Skip to content
Draft
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
3 changes: 2 additions & 1 deletion python/ql/src/Security/CWE-022/TarSlip.ql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import python
import semmle.python.security.Paths
import semmle.python.dataflow.TaintTracking
import semmle.python.security.strings.Basic
private import semmle.python.ApiGraphs::API as API

/** A TaintKind to represent open tarfile objects. That is, the result of calling `tarfile.open(...)` */
class OpenTarFile extends TaintKind {
Expand All @@ -35,7 +36,7 @@ class OpenTarFile extends TaintKind {
/** The source of open tarfile objects. That is, any call to `tarfile.open(...)` */
class TarfileOpen extends TaintSource {
TarfileOpen() {
Value::named("tarfile.open").getACall() = this and
API::moduleImport("tarfile").getMember("open").getACall().getNode() = this and
/*
* If argument refers to a string object, then it's a hardcoded path and
* this tarfile is safe.
Expand Down
5 changes: 4 additions & 1 deletion python/ql/src/Statements/ModificationOfLocals.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
*/

import python
private import semmle.python.ApiGraphs::API as API

predicate originIsLocals(ControlFlowNode n) { n.pointsTo(_, _, Value::named("locals").getACall()) }
predicate originIsLocals(ControlFlowNode n) {
n.pointsTo(_, _, API::moduleImport("locals").getACall().getNode())
}

predicate modification_of_locals(ControlFlowNode f) {
originIsLocals(f.(SubscriptNode).getObject()) and
Expand Down
7 changes: 4 additions & 3 deletions python/ql/src/Statements/SideEffectInAssert.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import python
private import semmle.python.ApiGraphs::API as API

predicate func_with_side_effects(Expr e) {
exists(string name | name = e.(Attribute).getName() or name = e.(Name).getId() |
Expand All @@ -22,11 +23,11 @@ predicate func_with_side_effects(Expr e) {
}

predicate call_with_side_effect(Call e) {
e.getAFlowNode() = Value::named("subprocess.call").getACall()
e.getAFlowNode() = API::moduleImport("subprocess").getMember("call").getACall().getNode()
or
e.getAFlowNode() = Value::named("subprocess.check_call").getACall()
e.getAFlowNode() = API::moduleImport("subprocess").getMember("check_call").getACall().getNode()
or
e.getAFlowNode() = Value::named("subprocess.check_output").getACall()
e.getAFlowNode() = API::moduleImport("subprocess").getMember("check_output").getACall().getNode()
}

predicate probable_side_effect(Expr e) {
Expand Down