-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release-v1.0.15
- Loading branch information
Showing
12 changed files
with
245 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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,31 @@ | ||
"""Exports extract_route_params function""" | ||
|
||
from urllib.parse import quote, unquote | ||
from aikido_zen.helpers.try_parse_url_path import try_parse_url_path | ||
from aikido_zen.helpers.build_route_from_url import replace_url_segment_with_param | ||
|
||
|
||
def extract_route_params(url): | ||
"""Will try and build an array of user input based on the url""" | ||
results = [] | ||
try: | ||
path = try_parse_url_path(url) | ||
segments = path.split("/") | ||
for segment in segments: | ||
segment = unquote(segment) | ||
if segment.isalnum(): | ||
continue # Ignore alphanumerical parts of the url | ||
|
||
if segment is not quote(segment): | ||
results.append(segment) # This is not a standard piece of the URL | ||
elif replace_url_segment_with_param(segment) is not segment: | ||
results.append(segment) # Might be a secret, a hash, ... | ||
|
||
if len(results) > 0 or "." in unquote(path): | ||
# There are already phishy parts of the url OR | ||
# urldecoded path contains dots, which is uncommon and could point to path traversal. | ||
results.append(path[1:]) # Add path after slash as user input | ||
|
||
except Exception: | ||
pass | ||
return results |
This file contains 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,112 @@ | ||
import pytest | ||
from .extract_route_params import extract_route_params | ||
|
||
|
||
def test_with_urlencoded_urls(): | ||
url1 = "http://localhost:8080/app/shell/ls%20-la" | ||
assert extract_route_params(url1) == ["ls -la", "app/shell/ls%20-la"] | ||
|
||
url2 = "http://localhost:8080/app/shell/ls -la" | ||
assert extract_route_params(url2) == ["ls -la", "app/shell/ls -la"] | ||
|
||
|
||
def test_uses_keys(): | ||
url = "http://localhost:8080/app/shell/[email protected]/017shell/127.0.0.1/" | ||
assert extract_route_params(url) == [ | ||
"[email protected]", | ||
"127.0.0.1", | ||
"app/shell/[email protected]/017shell/127.0.0.1/", | ||
] | ||
|
||
|
||
def test_normal_urls(): | ||
assert extract_route_params("http://localhost:8080/a/b/abc2393027def/def") == [] | ||
|
||
|
||
def test_with_empty_route(): | ||
url1 = "http://localhost:8080" | ||
assert extract_route_params(url1) == [] | ||
|
||
url2 = "http://localhost:8080" | ||
assert extract_route_params(url2) == [] | ||
|
||
|
||
def test_special_characters(): | ||
url1 = "http://localhost:8080/app/shell/!@#$%^&*()" # Everything past hashtag is not url anymore | ||
assert extract_route_params(url1) == ["!@", "app/shell/!@"] | ||
|
||
url2 = "http://localhost:8080/app/shell/space test" | ||
assert extract_route_params(url2) == ["space test", "app/shell/space test"] | ||
|
||
url3 = "http://localhost:8080/app/shell/hello%20world" | ||
assert extract_route_params(url3) == ["hello world", "app/shell/hello%20world"] | ||
|
||
|
||
def test_numeric_segments(): | ||
# Alphanum is ignored: | ||
url1 = "http://localhost:8080/app/shell/12345" | ||
assert extract_route_params(url1) == [] | ||
|
||
url2 = "http://localhost:8080/app/shell/67890/abc" | ||
assert extract_route_params(url2) == [] | ||
|
||
|
||
def test_mixed_segments(): | ||
url1 = "http://localhost:8080/app/shell/abc123/!@#" | ||
assert extract_route_params(url1) == ["!@", "app/shell/abc123/!@"] | ||
|
||
url2 = "http://localhost:8080/app/shell/abc/123/!@#" | ||
assert extract_route_params(url2) == ["!@", "app/shell/abc/123/!@"] | ||
|
||
|
||
def test_encoded_and_unencoded(): | ||
url1 = "http://localhost:8080/app/shell/%E2%9C%93" | ||
assert extract_route_params(url1) == ["✓", "app/shell/%E2%9C%93"] | ||
|
||
url2 = "http://localhost:8080/app/shell/%E2%9C%93/normal" | ||
assert extract_route_params(url2) == ["✓", "app/shell/%E2%9C%93/normal"] | ||
|
||
|
||
def test_no_params(): | ||
url1 = "http://localhost:8080/app/shell/" | ||
assert extract_route_params(url1) == [] | ||
|
||
url2 = "http://localhost:8080/app/" | ||
assert extract_route_params(url2) == [] | ||
|
||
|
||
def test_edge_cases(): | ||
url1 = "http://localhost:8080/app/shell/.." | ||
assert extract_route_params(url1) == ["..", "app/shell/.."] | ||
|
||
url2 = "http://localhost:8080/app/shell/./" | ||
assert extract_route_params(url2) == ["app/shell/./"] | ||
|
||
|
||
def test_long_urls(): | ||
url1 = "http://localhost:8080/app./shell/" + "a" * 1000 | ||
assert extract_route_params(url1) == ["app.", "app./shell/" + "a" * 1000] | ||
|
||
url2 = "http://localhost:8080/app./shell/" + "b" * 1000 + "/c" * 1000 | ||
assert extract_route_params(url2) == [ | ||
"app.", | ||
"app./shell/" + "b" * 1000 + "/c" * 1000, | ||
] | ||
|
||
|
||
def test_query_parameters(): | ||
# Test query parameters are ignored: | ||
url1 = "http://localhost:8080/app/./shell/?param=value" | ||
assert extract_route_params(url1) == ["app/./shell/"] | ||
|
||
url2 = "http://localhost:8080/app/./shell/?key1=value1&key2=value2" | ||
assert extract_route_params(url2) == ["app/./shell/"] | ||
|
||
|
||
def test_fragment_identifiers(): | ||
# Fragments should be ignored: | ||
url1 = "http://localhost:8080/app/./shell/#section1" | ||
assert extract_route_params(url1) == ["app/./shell/"] | ||
|
||
url2 = "http://localhost:8080/app/shell/#/path/to/resource" | ||
assert extract_route_params(url2) == [] |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.