Skip to content

Commit

Permalink
Merge pull request ansible#4284 from ryanpetrello/more-event-sanitiza…
Browse files Browse the repository at this point in the history
…tion-tweaks

only sanitize project update events for the scm modules
  • Loading branch information
ryanpetrello authored May 1, 2020
2 parents 99c7f2f + bf65b40 commit cd21dd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
24 changes: 16 additions & 8 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3899,15 +3899,23 @@ def get_stdout(self, obj):
return UriCleaner.remove_sensitive(obj.stdout)

def get_event_data(self, obj):
try:
return json.loads(
UriCleaner.remove_sensitive(
json.dumps(obj.event_data)
# the project update playbook uses the git, hg, or svn modules
# to clone repositories, and those modules are prone to printing
# raw SCM URLs in their stdout (which *could* contain passwords)
# attempt to detect and filter HTTP basic auth passwords in the stdout
# of these types of events
if obj.event_data.get('task_action') in ('git', 'hg', 'svn'):
try:
return json.loads(
UriCleaner.remove_sensitive(
json.dumps(obj.event_data)
)
)
)
except Exception:
logger.exception("Failed to sanitize event_data")
return {}
except Exception:
logger.exception("Failed to sanitize event_data")
return {}
else:
return obj.event_data


class AdHocCommandEventSerializer(BaseSerializer):
Expand Down
8 changes: 5 additions & 3 deletions awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,12 @@ def event_handler(self, event_data):
# this is a _little_ expensive to filter
# with regex, but project updates don't have many events,
# so it *should* have a negligible performance impact
task = event_data.get('event_data', {}).get('task_action')
try:
event_data_json = json.dumps(event_data)
event_data_json = UriCleaner.remove_sensitive(event_data_json)
event_data = json.loads(event_data_json)
if task in ('git', 'hg', 'svn'):
event_data_json = json.dumps(event_data)
event_data_json = UriCleaner.remove_sensitive(event_data_json)
event_data = json.loads(event_data_json)
except json.JSONDecodeError:
pass

Expand Down

0 comments on commit cd21dd6

Please sign in to comment.