Repository navigation
feat(code-injection): report dynamic imports and runpy reached by input - #250
Merged
Merged
Conversation
Part of #240: sys.path and getattr are left for a next step.
…d unchanged eval/exec Part of #240.
A check of the shape of a module or file name (isidentifier(), isalnum(), re.fullmatch) limits its characters, not the code it names. For the dynamic import and runpy sinks it leaves a hotspot; only membership in a constant allowlist or equality with a constant proves them. Part of #240.
Sink.merged rebuilt the sink without selects, so another plugin declaring the same import sink brought back shape checks as proofs. The merged sink selects when either declaration does, in either order. Part of #240.
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.
Part 1 of #240.
sys.pathandgetattr(...)()are left for a next step.Summary
New sinks:
importlib.import_module,__import__,importlib.__import__,runpy.run_moduleandrunpy.run_pathareCODEsinks.name,mod_name,path_name). The package of a relative name, the globals and the run name are data.__import__was not resolved at all:BUILTIN_NAMESdropped every name starting with_. It now resolves topython.builtins.__import__.How findings are reported:
Untrusted module importorUntrusted script execution; the rule id stayscode-injection."app.plugins." + name, f-string) gives a hotspot. Reading it needsir.ssaandabstract.module_strings, as inssrf, so the manifest and therequiresassertion intests/test_detectors.pychange accordingly.eval.Verification
tests/test_dynamic_import_sinks.py, new: 20 tests, 13 of which fail on main. They also cover negative cases (constant name, allowlist, data arguments only) and pin thatevalstill reports environment and command-line input.test_packagingmetadata issue.ruff checkandmypyclean.