-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Python: Add support for threat models #17203
Merged
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5ec8e5d
Python: Setup support for threat-models
RasmusWL 766dcc4
ThreatModels: Expose `knownThreatModel`
RasmusWL 617ab27
Python: Add test showing default active threat-models
RasmusWL 8f7dec0
Python: Remove 'response' from default threat-models
RasmusWL 528f08f
Python: Make queries use ActiveThreatModelSource
RasmusWL b9239d7
Python: Add basic support for environment/commandargs threat-models
RasmusWL 56c85ff
Python: Fixup threat-models for `os.environ.get()`
RasmusWL e1801f3
Python: Proper threat-model handling for argparse
RasmusWL 66f389a
Python: Model stdin thread-model
RasmusWL d245db5
Python: Model `file` threat-model
RasmusWL 7483075
Python: Fixup modeling of `os.open`
RasmusWL 8d8cd05
Python: Add basic support for `database` threat-model
RasmusWL a0b24d6
Python: Add e2e threat-model test
RasmusWL 0ccb5b1
Python: Add change-note
RasmusWL 7d3793e
Docs: Update threat-model list to include Python
RasmusWL 333367c
Python: Add threat-modeling of `raw_input`
RasmusWL cbebf7b
Python: Additional threatModelSource annotations
RasmusWL 5ff7b65
Python: Add links to threat-model docs
RasmusWL e35c2b2
Docs: Include 'Threat models' for Python
RasmusWL e11bfc2
Docs: Fix link
RasmusWL 4a21a85
Merge branch 'main' into threat-models
RasmusWL 535db98
Python: Minor simplification of `ActiveThreatModelSource`
RasmusWL 431a1af
Merge branch 'main' into threat-models
RasmusWL 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
There are no files selected for viewing
This file contains 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 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 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,4 @@ | ||
--- | ||
category: feature | ||
--- | ||
* Added support for custom threat-models, which can be used in most of our taint-tracking queries, see our [documentation](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#extending-codeql-coverage-with-threat-models) for more details. |
This file contains 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,8 @@ | ||
extensions: | ||
- addsTo: | ||
pack: codeql/threat-models | ||
extensible: threatModelConfiguration | ||
data: | ||
# Since responses are enabled by default in the shared threat-models configuration, | ||
# we need to disable it here to keep existing behavior for the python analysis. | ||
- ["response", false, -2147483647] |
This file contains 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 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 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 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 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,29 @@ | ||
extensions: | ||
- addsTo: | ||
pack: codeql/python-all | ||
extensible: sourceModel | ||
data: | ||
- ['os', 'Member[getenv].ReturnValue', 'environment'] | ||
- ['os', 'Member[getenvb].ReturnValue', 'environment'] | ||
- ['os', 'Member[environ]', 'environment'] | ||
- ['os', 'Member[environb]', 'environment'] | ||
- ['posix', 'Member[environ]', 'environment'] | ||
|
||
- ['sys', 'Member[argv]', 'commandargs'] | ||
- ['sys', 'Member[orig_argv]', 'commandargs'] | ||
|
||
- ['sys', 'Member[stdin]', 'stdin'] | ||
- ['builtins', 'Member[input].ReturnValue', 'stdin'] | ||
- ['builtins', 'Member[raw_input].ReturnValue', 'stdin'] # python 2 only | ||
|
||
|
||
# if no argument is given, the default is to use sys.argv[1:] | ||
- ['argparse.ArgumentParser', 'Member[parse_args,parse_known_args].WithArity[0].ReturnValue', 'commandargs'] | ||
|
||
- ['os', 'Member[read].ReturnValue', 'file'] | ||
- addsTo: | ||
pack: codeql/python-all | ||
extensible: summaryModel | ||
data: | ||
- ['argparse.ArgumentParser', 'Member[parse_args,parse_known_args]', 'Argument[0,args:]', 'ReturnValue', 'taint'] | ||
# note: taint of attribute lookups is handled in QL |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.
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.
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.
Might I suggest the name
FlowSource
for this class? It seems consistent with C++ and Swift at least, and it works nicely withRemoteFlowSource
being a special case of it.Then we could rename
ActiveThreatModelSource
toThreatModelFlowSource
to be consistent with other languages. I do agree that the "active" prefix makes sense, but given that this will be the new go-to thing to use inisSource()
predicates it seems that we really do want consistency for that class name.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.
I've persuaded
@michaelnebel
to be in favor ofActiveThreatModelSource
, so I've just filed a PR to make the existing languages use that as well 👍 #17424FlowSource
Regarding renaming to
FlowSource
, I've tried to do that here: RasmusWL@dec5daaI'm slightly hesitant to accept it, I can't quite put my finger on it, but I think it's because it's so generic that name could be used to capture the set of sources for any data-flow/taint-tracking configuration, no matter the logic, whereas
ThreatModelSource
seem to convey a more specific meaning to me.I realize that your suggestion probably fits pretty well with current naming in C#/Java/Go with
SourceNode
and C++/Swift withFlowSource
🤔 Maybe I'll see if anyone comes with a convincing argument during next round of review, otherwise it looks like I should just disagree-and-commit.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.
Whatever we do we ought to treat the naming of the two classes as a single decision; not something where we try to make a decision for each class in isolation.
The proposed rename to
FlowSource
made sense when the other class would be calledThreatModelFlowSource
; but it doesn't work so so nicely withActiveThreatModelSource
. I'd prefer the combinationThreatModelSource/ActiveThreatModelSource
overFlowSource/ActiveThreatModelSource
.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.
Alright, I'm feeling strongly in favor of
ActiveThreatModelSource
, so it seems like I won't add theFlowSource
commit 👍