forked from yandex/gixy
-
-
Notifications
You must be signed in to change notification settings - Fork 26
A plugin to check for proxy_pass usage resulting in decoding and normalization #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63534ae
A plugin to check for proxy_pass usage resulting in decoding and norm…
MegaManSec d93bbe8
Add proxy_pass_path_fp.conf
MegaManSec 63ee620
Change class name
MegaManSec f4d481f
Find the dist file in the correct location
MegaManSec 5443164
Use proxy_pass_normalized as class name as it's included in the report
MegaManSec 0678c01
Add URL to mkdocs
MegaManSec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import re | ||
| import gixy | ||
| from gixy.plugins.plugin import Plugin | ||
|
|
||
| class proxy_pass_normalized(Plugin): | ||
| r""" | ||
| This plugin detects if there is any path component (slash or more) | ||
| after the host in a proxy_pass directive. | ||
| Example flagged directives: | ||
| proxy_pass http://backend/; | ||
| proxy_pass http://backend/foo/bar; | ||
| """ | ||
|
|
||
| summary = 'Detect path after host in proxy_pass (potential URL decoding issue)' | ||
| severity = gixy.severity.LOW | ||
| description = ("A slash immediately after the host in proxy_pass leads to the path being decoded and normalized before proxying downstream, leading to unexpected behavior related to encoded slashes.") | ||
| help_url = 'https://joshua.hu/proxy-pass-nginx-decoding-normalizing-url-path-dangerous#nginx-proxy_pass' | ||
| directives = ['proxy_pass'] | ||
|
|
||
| def __init__(self, config): | ||
| super(proxy_pass_normalized, self).__init__(config) | ||
| self.parse_uri_re = re.compile(r'(?P<scheme>[^?#/)]+://)?(?P<host>[^?#/)]+)(?P<path>/.*)?') | ||
|
|
||
| def audit(self, directive): | ||
| proxy_pass_arg = directive.args[0] | ||
| if not proxy_pass_arg: | ||
| return | ||
|
|
||
| parsed = self.parse_uri_re.match(proxy_pass_arg) | ||
|
|
||
| if not parsed: | ||
| return | ||
|
|
||
| if not parsed.group('path'): | ||
| return | ||
|
|
||
| self.add_issue( | ||
| severity=self.severity, | ||
| directive=[directive, directive.parent], | ||
| reason=( | ||
| "Found a slash (and possibly more) after the hostname in proxy_pass. " | ||
| "This can lead to path decoding issues." | ||
| ) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,5 @@ coverage>=4.3 | |
| flake8>=3.2 | ||
| tox>=2.7.0 | ||
| pytest-xdist | ||
| setuptools | ||
| twine | ||
3 changes: 3 additions & 0 deletions
3
tests/plugins/simply/proxy_pass_normalized/proxy_pass_path.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| location / { | ||
MegaManSec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| proxy_pass http://server/; | ||
| } | ||
3 changes: 3 additions & 0 deletions
3
tests/plugins/simply/proxy_pass_normalized/proxy_pass_path_fp.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| location / { | ||
| proxy_pass http://downstream; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.