Repository navigation
feat: analyse module bodies and class bodies as functions - #114
Merged
Merged
Conversation
The module's statements outside its definitions are lowered as a function named <module>, and a top-level class's statements outside its methods as Cls.<body>, both carrying the span of what they stand for so their names resolve in the right scope. Their calls are call sites, their values carry taint and an advisory entry point called at import time is reachable. Inside the module body, the variables the module assigns are the body's locals: x = input(); os.system(x) connects in SSA and a module-level for loop has a target, while functions, classes and imports stay globals for the call graph and the symbol resolution. Wildcard imports lower to nothing. Coverage counts the bodies; the cache format is bumped. Regression snapshots re-recorded: 13 missing-timeout, 2 ssrf, 1 command-injection and 1 reachable-vulnerability at module level, and one stale syntax-error entry main no longer produced. Closes #113
…preter full-stack-fastapi-template's deps.py uses 'except A, B:' (PEP 758), which only Python 3.14 parses; the snapshot keeps its syntax-error note and the coverage the CI observes.
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.
Closes #113.
What
analyzable_functionsnow yields the module body as a synthetic function<module>and each top-level class's body asCls.<body>, in source order, before the definitions they contain. They carry the module's / class's span, soscope_forresolves their names in the right scope (the module scope is now registered by its span).forloops andx = input(); os.system(x)were unsupported or disconnected when every name was a global. Functions, classes and imports stay globals, which is what the call graph and the symbol resolution key on; other functions still read module variables throughGlobal. Wildcard imports lower to nothing._enclosingignores the synthetic bodies so a module-level lambda is not "nested" in<module>.<module>/<body>;CACHE_FORMAT4 → 5 so cached modules gain their module-level findings.Tests
tests/test_module_level.py(9): synthetic functions and their order, empty module, module-levelos.system(input())reported in<module>, an advisory entry point called at module level and in a class body reachable, a top-level def called from the body foundthroughit, module variables as locals (taint connects,forsupported), functions still read module variables as globals. One ceiling documented: a lambda bound to a module-level name and called through that name is not resolved.Expectations that counted or listed functions were updated (
<module>appears; coverage +1 per module with statements); twolower()test helpers skip the body function. 926 passed; ruff and mypy clean.Regression snapshots
Re-recorded and reviewed: every new entry is in
<module>— 13missing-timeout, 2ssrf(Vulnerable_fastapi exploit script: response JSON into a URL), 1command-injection(httpiedocs/contributors/fetch.py:sys.argvthroughmaintocheck_output), 1reachable-vulnerability(pygoatlab_code/test.py: module-levelyaml.load). One removal: asyntax-errorondeps.pythatmainalready no longer produced (stale snapshot). Coverage function counts rose accordingly.Downstream
The two
xfail(strict=True)Django integrations in the enterprise repo (#17) will start passing and need their marks removed with the pin bump.