-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: block dangerous file extension uploads in payload API #3302
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
Open
deacon-mp
wants to merge
10
commits into
master
Choose a base branch
from
fix/payload-rce-code-injection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+70
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f13ea26
fix(security): block server-side executable file types in payload upload
deacon-mp 7a1e64d
test(security): add regression tests for payload extension blocking
deacon-mp 77eb911
fix: address Copilot review feedback on payload extension blocking
deacon-mp a42f616
Address Copilot review: use subset assertion for blocked extensions t…
deacon-mp 913d038
Removed unused _BLOCKED_EXTENSIONS reference
jlklos ae9cdfb
Merge branch 'master' into fix/payload-rce-code-injection
jlklos 94d059a
Strip trailing periods
jlklos cd24ec5
Parametrize extension validation test
jlklos bb77631
Rerun tests
jlklos 37e4fe3
Fix formatting of docstring in test_payload_extension_blocking
jlklos 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """ | ||
| Security regression tests for payload upload extension blocking (CWE-94 fix). | ||
|
|
||
| Verifies that _validate_payload_extension() correctly rejects server-side | ||
| executable file types (.py, .pyc, .pyo, .so, .dll). | ||
| """ | ||
| import pytest | ||
| from aiohttp import web | ||
|
|
||
| from app.api.v2.handlers.payload_api import _validate_payload_extension | ||
|
|
||
|
|
||
| class TestPayloadExtensionBlocking: | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "filename", | ||
| [ | ||
| "malicious.py", | ||
| "malicious.pyc", | ||
| "malicious.pyo", | ||
| "exploit.so", | ||
| "evil.dll", | ||
| "malicious.PY", | ||
| "malicious.Py", | ||
| # Files with a safe-looking extension followed by a blocked one | ||
| "legit.txt.py", | ||
| ], | ||
| ) | ||
| def test_blocked_filenames_rejected(self, filename): | ||
| with pytest.raises(web.HTTPBadRequest): | ||
| _validate_payload_extension(filename) | ||
|
|
||
| def test_exe_allowed(self): | ||
| """Agent binaries (.exe) must still be uploadable.""" | ||
| _validate_payload_extension('sandcat.exe') # should not raise | ||
|
|
||
| def test_elf_allowed(self): | ||
| _validate_payload_extension('sandcat-linux') # no extension — should not raise | ||
|
|
||
| def test_zip_allowed(self): | ||
| _validate_payload_extension('payloads.zip') | ||
|
|
||
| def test_go_allowed(self): | ||
| _validate_payload_extension('manx.go') | ||
|
|
||
| def test_blocked_extensions_set(self): | ||
| """Verify the constant is a frozenset and contains at least the known dangerous types.""" | ||
| from app.api.v2.handlers.payload_api import _BLOCKED_EXTENSIONS as _BLK | ||
| assert isinstance(_BLK, frozenset), "_BLOCKED_EXTENSIONS must be a frozenset" | ||
| expected_minimum = frozenset({'.py', '.pyc', '.pyo', '.so', '.dll'}) | ||
| assert _BLK.issuperset(expected_minimum), ( | ||
| f"_BLOCKED_EXTENSIONS missing required extensions: {expected_minimum - _BLK}" | ||
| ) |
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.