-
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.
- Loading branch information
Showing
41 changed files
with
728 additions
and
122 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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# Feature flag | ||
|
||
This feature is currently disabled by default. Enable it by setting the environment variable `AIKIDO_FEATURE_COLLECT_API_SCHEMA` to `true`. | ||
This feature is now on by default. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Contains package versions""" | ||
|
||
PKG_VERSION = "1.0.12" | ||
PKG_VERSION = "1.0.13" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
"""Exports extract_data_from_xml_body helper function""" | ||
|
||
import aikido_zen.context as ctx | ||
from aikido_zen.helpers.logging import logger | ||
|
||
|
||
def extract_data_from_xml_body(user_input, root_element): | ||
"""Extracts all attributes from the xml and adds them to context""" | ||
context = ctx.get_current_context() | ||
if not isinstance(context.body, str) or user_input != context.body: | ||
return | ||
try: | ||
context = ctx.get_current_context() | ||
if ( | ||
not context | ||
or not isinstance(context.body, str) | ||
or user_input != context.body | ||
): | ||
return | ||
|
||
extracted_xml_attrs = context.xml | ||
for el in root_element: | ||
for k, v in el.items(): | ||
if not extracted_xml_attrs.get(k): | ||
extracted_xml_attrs[k] = set() | ||
extracted_xml_attrs[k].add(v) | ||
context.set_as_current_context() | ||
extracted_xml_attrs = context.xml | ||
for el in root_element: | ||
for k, v in el.items(): | ||
if not extracted_xml_attrs.get(k): | ||
extracted_xml_attrs[k] = set() | ||
extracted_xml_attrs[k].add(v) | ||
context.set_as_current_context() | ||
except Exception as e: | ||
logger.debug("Exception occured when extracting XML: %s", e) |
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,10 @@ | ||
"""Exports get_argument""" | ||
|
||
|
||
def get_argument(args, kwargs, pos, name): | ||
"""Checks kwargs and args for your argument""" | ||
if name in kwargs: | ||
return kwargs.get(name) | ||
if args and len(args) > pos: | ||
return args[pos] | ||
return None |
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,62 @@ | ||
import pytest | ||
from .get_argument import get_argument | ||
|
||
|
||
def test_get_argument_with_only_kwargs(): | ||
"""Test when only kwargs are provided.""" | ||
result = get_argument((), {"arg1": "value1"}, 0, "arg1") | ||
assert result == "value1", f"Expected 'value1', got {result}" | ||
|
||
|
||
def test_get_argument_with_only_args(): | ||
"""Test when only args are provided.""" | ||
result = get_argument(("value2",), {}, 0, "arg1") | ||
assert result == "value2", f"Expected 'value2', got {result}" | ||
|
||
|
||
def test_get_argument_with_args_and_kwargs(): | ||
"""Test when both args and kwargs are provided, with priority to kwargs.""" | ||
result = get_argument(("value2",), {"arg1": "value1"}, 0, "arg1") | ||
assert result == "value1", f"Expected 'value1', got {result}" | ||
|
||
|
||
def test_get_argument_with_positional_index(): | ||
"""Test when args are provided and a specific position is requested.""" | ||
result = get_argument(("value2", "value3"), {}, 1, "arg1") | ||
assert result == "value3", f"Expected 'value3', got {result}" | ||
|
||
|
||
def test_get_argument_with_positional_index_out_of_bounds(): | ||
"""Test when the positional index is out of bounds.""" | ||
result = get_argument(("value2",), {}, 1, "arg1") | ||
assert result is None, f"Expected None, got {result}" | ||
|
||
|
||
def test_get_argument_with_none_in_kwargs(): | ||
"""Test when the argument in kwargs is None.""" | ||
result = get_argument((), {"arg1": None}, 0, "arg1") | ||
assert result is None, f"Expected None, got {result}" | ||
|
||
|
||
def test_get_argument_with_none_in_args(): | ||
"""Test when the argument in args is None.""" | ||
result = get_argument((None,), {}, 0, "arg1") | ||
assert result is None, f"Expected None, got {result}" | ||
|
||
|
||
def test_get_argument_with_empty_args_and_kwargs(): | ||
"""Test when both args and kwargs are empty.""" | ||
result = get_argument((), {}, 0, "arg1") | ||
assert result is None, f"Expected None, got {result}" | ||
|
||
|
||
def test_get_argument_with_multiple_kwargs(): | ||
"""Test when multiple kwargs are provided.""" | ||
result = get_argument((), {"arg1": "value1", "arg2": "value2"}, 0, "arg1") | ||
assert result == "value1", f"Expected 'value1', got {result}" | ||
|
||
|
||
def test_get_argument_with_positional_index_and_kwargs(): | ||
"""Test when both args and kwargs are provided, with positional index.""" | ||
result = get_argument(("value2", "value3"), {"arg1": "value1"}, 0, "arg1") | ||
assert result == "value1", f"Expected 'value1', got {result}" |
Oops, something went wrong.