Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# CodeQL related
.codeql
.cache
*.testproj/
*.actual

# Test files / folders
test.ql
Expand Down
5 changes: 5 additions & 0 deletions .vimignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

codeql/
codeql-go/
.cache/

24 changes: 10 additions & 14 deletions python/github/LocalSources.qll
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,16 @@ module LocalSources {
class FileReadSource extends LocalSources::Range {
FileReadSource() {
// exists(StrConst literal | this = DataFlow::exprNode(literal))
(
exists(DataFlow::Node call |
(
// https://docs.python.org/3/library/functions.html#open
// var = open('abc.txt')
call = API::builtin("open").getACall().getAMethodCall("read")
or
// https://docs.python.org/3/library/os.html#os.read
call = API::moduleImport("os").getMember(["read"]).getACall()
) and
this = call
)
or
this instanceof FileSystemAccess::Range
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue was with this FileSystemAccess::Range as this also includes temp file access

exists(DataFlow::Node call |
(
// https://docs.python.org/3/library/functions.html#open
// var = open('abc.txt')
call = API::builtin("open").getACall().getAMethodCall("read")
or
// https://docs.python.org/3/library/os.html#os.read
call = API::moduleImport("os").getMember(["read"]).getACall()
) and
this = call
) and
this.getScope().inSource()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
| app.py:20:8:20:26 | ControlFlowNode for Attribute() |
| app.py:22:6:22:11 | ControlFlowNode for Attribute |
| app.py:23:6:23:15 | ControlFlowNode for Attribute |
| app.py:26:5:26:23 | ControlFlowNode for open() |
| app.py:27:6:27:13 | ControlFlowNode for Attribute() |
| app.py:29:6:29:24 | ControlFlowNode for open() |
| app.py:30:10:30:17 | ControlFlowNode for Attribute() |
| app.py:32:6:32:40 | ControlFlowNode for Attribute() |
| app.py:33:7:33:23 | ControlFlowNode for Attribute() |
8 changes: 8 additions & 0 deletions tests/python-tests/libraries/localsources/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@

f2 = os.open("/etc/passwd", os.O_RDONLY)
i10 = os.read(f2, 1024)


# False Positives

import tempfile

t1 = tempfile.gettempdir()
t2 = tempfile.mkdtemp()