Security: Arbitrary Code Execution via exec() on File Content#12334
Closed
barttran2k wants to merge 1 commit intoaio-libs:masterfrom
Closed
Security: Arbitrary Code Execution via exec() on File Content#12334barttran2k wants to merge 1 commit intoaio-libs:masterfrom
barttran2k wants to merge 1 commit intoaio-libs:masterfrom
Conversation
The `calc_headers` function reads, compiles, and executes the content of `aiohttp/hdrs.py` using `exec(code, globs)`. If an attacker can modify `hdrs.py` (e.g., through a supply chain attack or compromised repository), arbitrary code would be executed when this tool script is run. The tool is used to generate C source files that get compiled into the library. Affected files: gen.py Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
Merging this PR will improve performance by ×3.1
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_get_request_with_251308_compressed_chunked_payload[isal.isal_zlib-pyloop] |
62.4 ms | 20.3 ms | ×3.1 |
| ⚡ | test_get_request_with_251308_compressed_chunked_payload[zlib-pyloop] |
426.7 ms | 353.1 ms | +20.83% |
| ⚡ | test_get_request_with_251308_compressed_chunked_payload[zlib_ng.zlib_ng-pyloop] |
205.8 ms | 168.3 ms | +22.28% |
Comparing barttran2k:contribai/fix/security/arbitrary-code-execution-via-exec-on-fil (9d50881) with master (fc67cfd)
Footnotes
-
4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Member
|
Duplicate of #12331 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
calc_headersfunction reads, compiles, and executes the content ofaiohttp/hdrs.pyusingexec(code, globs). If an attacker can modifyhdrs.py(e.g., through a supply chain attack or compromised repository), arbitrary code would be executed when this tool script is run. The tool is used to generate C source files that get compiled into the library.Severity:
mediumFile:
tools/gen.pySolution
Instead of using
exec(), parsehdrs.pywith theastmodule to safely extract the header constants:import ast; tree = ast.parse(hdrs_file.read_text()); # extract string assignments from the AST.Changes
tools/gen.py(modified)Testing