-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Docs: add path query example to data flow docs #20622
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2930e79
Fix mistakes in Go data flow examples in docs
owen-mc 1004635
Add path query example to python data flow docs
owen-mc 3c80690
Fix link syntax
owen-mc 944e116
Add path query example to other lang data flow docs
owen-mc 2e0915e
Add missing links to "Creating path queries"
owen-mc c8c1c6e
Address review comments
owen-mc 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 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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -354,11 +354,50 @@ This data flow configuration tracks data flow from environment variables to open | |||||
| select fileOpen, "This call to 'os.open' uses data from $@.", | ||||||
| environment, "call to 'os.getenv'" | ||||||
|
|
||||||
| Path Query Example | ||||||
| ~~~~~~~~~~~~~~~~~~ | ||||||
|
|
||||||
| Here is the first example above, converted into a path query: | ||||||
|
|
||||||
| .. code-block:: ql | ||||||
|
|
||||||
| /** | ||||||
| * @kind path-problem | ||||||
| * @problem.severity warning | ||||||
| * @id file-system-access-from-remote-input | ||||||
| */ | ||||||
|
|
||||||
| import python | ||||||
| import semmle.python.dataflow.new.DataFlow | ||||||
| import semmle.python.dataflow.new.TaintTracking | ||||||
| import semmle.python.dataflow.new.RemoteFlowSources | ||||||
| import semmle.python.Concepts | ||||||
|
|
||||||
| module RemoteToFileConfiguration implements DataFlow::ConfigSig { | ||||||
| predicate isSource(DataFlow::Node source) { | ||||||
| source instanceof RemoteFlowSource | ||||||
| } | ||||||
|
|
||||||
| predicate isSink(DataFlow::Node sink) { | ||||||
| sink = any(FileSystemAccess fa).getAPathArgument() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| module RemoteToFileFlow = TaintTracking::Global<RemoteToFileConfiguration>; | ||||||
|
|
||||||
| import RemoteToFileFlow::PathGraph | ||||||
|
|
||||||
| from RemoteToFileFlow::PathNode input, RemoteToFileFlow::PathNode fileAccess | ||||||
| where RemoteToFileFlow::flowPath(input, fileAccess) | ||||||
| select fileAccess.getNode(), input, fileAccess, "This file access uses data from $@.", | ||||||
| input, "user-controllable input." | ||||||
|
|
||||||
| For more information, see ":doc:`Creating path queries <creating-path-queries>`". | ||||||
|
|
||||||
| Further reading | ||||||
| --------------- | ||||||
|
|
||||||
| - `Exploring data flow with path queries <https://docs.github.com/en/code-security/codeql-for-vs-code/getting-started-with-codeql-for-vs-code/exploring-data-flow-with-path-queries>`__ in the GitHub documentation. | ||||||
| - `Creating path queries <https://codeql.github.com/docs/writing-codeql-queries/creating-path-queries/>`__ in the GitHub documentation. | ||||||
|
||||||
| - `Creating path queries <https://codeql.github.com/docs/writing-codeql-queries/creating-path-queries/>`__ in the GitHub documentation. | |
| - `Creating path queries <https://codeql.github.com/docs/writing-codeql-queries/creating-path-queries/>`__. |
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.
It would be good to be more explicit here, maybe:
Alternatively, you could give the two queries above a heading.