Skip to content

Commit

Permalink
workaround to allow double-quotes in hook-commands (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Sep 14, 2024
1 parent dbb7999 commit 8ea1d59
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/source/usage/repositories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ If you want to run multiple ones - they need to be comma-separated.

These hooks will not be processed if you override the actual create/update command.

**Note**: For security reasons (XSS) these characters are not allowed: :code:`& < > "`
**Note**: For security reasons (XSS) these characters are currently not allowed: :code:`< >`

----

Expand Down
3 changes: 2 additions & 1 deletion src/ansibleguy-webui/aw/api_endpoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def not_implemented(*args, **kwargs):
def validate_no_xss(value: str, field: str, shell_cmd: bool = False):
if is_set(value) and isinstance(value, str):
if shell_cmd:
# allow single-quotes
# ignore characters shell-commands may need
value = value.replace("'", '')
value = value.replace('&', '')

if value != escape_html(value):
raise ValidationError(f"Found illegal characters in field '{field}'")
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/api_endpoints/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def validate(self, attrs: dict):
for field in Repository.api_fields_write:
if field in attrs:
if field in Repository.fields_shell_cmds:
attrs[field] = attrs[field].replace('"', "''")
validate_no_xss(value=attrs[field], field=field, shell_cmd=True)

else:
Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/execute/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def _repo_process(self, cmd: str, env: dict):
def _run_repo_config_cmds(self, cmds: str, env: dict):
if is_set(cmds):
for cmd in cmds.split(','):
cmd = cmd.replace("''", '"')
self._repo_process(cmd=cmd, env=env)

def _git_origin_with_credentials(self) -> str:
Expand Down

0 comments on commit 8ea1d59

Please sign in to comment.