Skip to content

Commit

Permalink
allow single-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 282ca98 commit dbb7999
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/source/usage/repositories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ 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:`& < > "`

----

Clone via SSH
Expand Down
11 changes: 8 additions & 3 deletions src/ansibleguy-webui/aw/api_endpoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def not_implemented(*args, **kwargs):
return JsonResponse({'error': 'Not yet implemented'}, status=404)


def validate_no_xss(value: str, field: str):
if is_set(value) and isinstance(value, str) and value != escape_html(value):
raise ValidationError(f"Found illegal characters in field '{field}'")
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
value = value.replace("'", '')

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

else:
validate_no_xss(value=attrs[field], field=field)

return attrs

Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/model/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Repository(BaseModel):

])
api_fields_write = form_fields
fields_shell_cmds = ['git_hook_pre', 'git_hook_post', 'git_override_initialize', 'git_override_update']

name = models.CharField(max_length=100, null=False, blank=False)
rtype = models.PositiveSmallIntegerField(choices=CHOICES_REPOSITORY)
Expand Down

0 comments on commit dbb7999

Please sign in to comment.