Skip to content

Commit

Permalink
[alias_traversal] Minor improvements + respects path in the alias dir…
Browse files Browse the repository at this point in the history
…ective:

  - alias /foo/bar/ -> HIGH severity
  - alias /foo/bar -> MEDIUM severity
  • Loading branch information
buglloc committed Nov 10, 2017
1 parent 2a922f3 commit ea7d771
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions gixy/directives/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ def __init__(self, name, args):
@property
def variables(self):
return [Variable(name='document_root', value=self.path, provider=self)]


class AliasDirective(Directive):
nginx_name = 'alias'

def __init__(self, name, args):
super(AliasDirective, self).__init__(name, args)
self.path = args[0]
9 changes: 7 additions & 2 deletions gixy/plugins/alias_traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ class alias_traversal(Plugin):
"""
summary = 'Path traversal via misconfigured alias.'
severity = gixy.severity.HIGH
description = 'TODO'
description = 'Using alias in a prefixed location that doesn\'t ends with directory separator could lead to path ' \
'traversal vulnerability. '
help_url = 'https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md'
directives = ['alias']

def audit(self, directive):
for location in directive.parents:
if location.name != 'location':
continue

if not location.modifier or location.modifier == '^~':
# We need non-strict prefixed locations
if not location.path.endswith('/'):
self.add_issue(directive=[directive, location])
self.add_issue(
severity=gixy.severity.HIGH if directive.path.endswith('/') else gixy.severity.MEDIUM,
directive=[directive, location]
)
break
2 changes: 1 addition & 1 deletion tests/plugins/simply/alias_traversal/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"severity": "HIGH"
"severity": ["MEDIUM", "HIGH"]
}
3 changes: 3 additions & 0 deletions tests/plugins/simply/alias_traversal/not_slashed_alias.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location /files {
alias /home;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location /files/ {
alias /home;
}
3 changes: 3 additions & 0 deletions tests/plugins/simply/alias_traversal/slashed_alias.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location /files {
alias /home/;
}
3 changes: 3 additions & 0 deletions tests/plugins/simply/alias_traversal/slashed_alias_fp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location /files/ {
alias /home/;
}

0 comments on commit ea7d771

Please sign in to comment.