Skip to content

Commit

Permalink
Merge pull request #15905 from yoff/python/stdlib-start-modeling-usin…
Browse files Browse the repository at this point in the history
…g-mad

Python: Start modelling the standard library using MaD
  • Loading branch information
yoff authored Apr 24, 2024
2 parents ad8ec8c + 3b192b8 commit 2357a49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/ql/lib/semmle/python/frameworks/Stdlib.qll
Original file line number Diff line number Diff line change
Expand Up @@ -3121,8 +3121,13 @@ module StdlibPrivate {

override predicate propagatesFlow(string input, string output, boolean preservesValue) {
input in ["Argument[0]", "Argument[pattern:]"] and
output = "ReturnValue.Attribute[pattern]" and
preservesValue = true
(
output = "ReturnValue.Attribute[pattern]" and
preservesValue = true
or
output = "ReturnValue" and
preservesValue = false
)
}
}

Expand Down
44 changes: 44 additions & 0 deletions python/ql/lib/semmle/python/frameworks/Stdlib/StdLib.model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
extensions:
- addsTo:
pack: codeql/python-all
extensible: sourceModel
data: []

- addsTo:
pack: codeql/python-all
extensible: sinkModel
data: []

- addsTo:
pack: codeql/python-all
extensible: summaryModel
data:
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote
- ["urllib", "Member[parse].Member[quote]", "Argument[0,string:]", "ReturnValue", "taint"]
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus
- ["urllib", "Member[parse].Member[quote_plus]", "Argument[0,string:]", "ReturnValue", "taint"]
# See https://epydoc.sourceforge.net/stdlib/urllib-module.html
- ["urllib", "Member[parse].Member[splitquery]", "Argument[0,url:]", "ReturnValue.TupleElement[0,1]", "taint"]
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote
- ["urllib", "Member[parse].Member[unquote]", "Argument[0,string:]", "ReturnValue", "taint"]
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote_plus
- ["urllib", "Member[parse].Member[unquote_plus]", "Argument[0,string:]", "ReturnValue", "taint"]
# We could consider a more precise source than the first argument, namely tuple or dict content.
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
- ["urllib", "Member[parse].Member[urlencode]", "Argument[0,query:]", "ReturnValue", "taint"]
# See https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urljoin
- ["urllib", "Member[parse].Member[urljoin]", "Argument[0,base:,1,url:]", "ReturnValue", "taint"]
- addsTo:
pack: codeql/python-all
extensible: neutralModel
data: []

- addsTo:
pack: codeql/python-all
extensible: typeModel
data: []

- addsTo:
pack: codeql/python-all
extensible: typeVariableModel
data: []

0 comments on commit 2357a49

Please sign in to comment.