-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Python: Allow models-as-data sanitizers and convert 1 existing sanitizer #21234
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables models-as-data (MaD) sanitizers for Python security queries and converts the Flask path-injection sanitizer from CodeQL to a MaD model. The key change is fixing the barrierNode implementation to use asSink() instead of asSource(), which correctly identifies where data flows into sanitizing functions.
Changes:
- Fixed
barrierNodeimplementation in ApiGraphModels.qll to useasSink()for proper barrier node identification - Converted Flask
send_from_directoryfilename sanitizer from CodeQL class to MaD YAML model - Added
SanitizerFromModelclasses across 8 security query customization files to support MaD-defined sanitizers - Added
CredentialSanitizerclass in HardcodedCredentials.ql to support credential-specific MaD sanitizers
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModels.qll | Fixed barrierNode to use asSink() instead of asSource() for correct identification of nodes where data flows into barriers |
| python/ql/lib/semmle/python/frameworks/Flask.qll | Removed FlaskSendFromDirectoryCallFilenameSanitizer class (converted to MaD) |
| python/ql/lib/semmle/python/frameworks/Flask.model.yml | Added MaD barrier model for Flask send_from_directory filename argument |
| python/ql/lib/semmle/python/security/dataflow/UrlRedirectCustomizations.qll | Clarified comment that SanitizerFromModel sanitizes all flow states |
| python/ql/lib/semmle/python/security/dataflow/UnsafeDeserializationCustomizations.qll | Added SanitizerFromModel class for unsafe-deserialization kind |
| python/ql/lib/semmle/python/security/dataflow/SqlInjectionCustomizations.qll | Added SanitizerFromModel class for sql-injection kind |
| python/ql/lib/semmle/python/security/dataflow/ReflectedXSSCustomizations.qll | Added SanitizerFromModel class for html-injection and js-injection kinds |
| python/ql/lib/semmle/python/security/dataflow/PathInjectionCustomizations.qll | Added SanitizerFromModel class for path-injection kind |
| python/ql/lib/semmle/python/security/dataflow/LogInjectionCustomizations.qll | Added SanitizerFromModel class for log-injection kind |
| python/ql/lib/semmle/python/security/dataflow/CommandInjectionCustomizations.qll | Added SanitizerFromModel class for command-injection kind |
| python/ql/lib/semmle/python/security/dataflow/CodeInjectionCustomizations.qll | Added SanitizerFromModel class for code-injection kind |
| python/ql/src/Security/CWE-798/HardcodedCredentials.ql | Added CredentialSanitizer class to support MaD barriers for credential sinks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I confirmed that without this sanitizer a test fails.
fbf9d1d to
7232568
Compare
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| query: Security/CWE-089/SqlInjection.ql | ||
| postprocess: utils/test/PrettyPrintModels.ql |
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Note the commit "Fix implementation of barrierNode for barrier models" was needed to make the commit "Convert Flask path-injection sanitizer to MaD" work. I am not certain that it is the correct approach, so please review this carefully.
Also carefully review the MaD that I wrote, as I have no experience with MaD for dynamic languages.
There are two other sanitizers which seemed convertible, but only sanitize certain flow-states. We could in future extend the url-redirection
kindstring to make it possible to specify this. This would have a much greater benefit if the use of flow states for URL redirection is first implemented for all languages.