Skip to content

Commit 1a52f17

Browse files
committed
Python: Add StringConstCompare BarrierGuard
1 parent a82936c commit 1a52f17

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,26 @@ class BarrierGuard extends GuardNode {
355355
}
356356
}
357357

358+
/** Provides commonly used BarrierGuards */
359+
module BarrierGuard {
360+
/** A validation of unknown node by comparing with a constant string value. */
361+
class StringConstCompare extends BarrierGuard, CompareNode {
362+
ControlFlowNode checked_node;
363+
364+
StringConstCompare() {
365+
exists(StrConst str_const |
366+
this.operands(str_const.getAFlowNode(), any(Eq eq), checked_node)
367+
or
368+
this.operands(checked_node, any(Eq eq), str_const.getAFlowNode())
369+
)
370+
}
371+
372+
override predicate checks(ControlFlowNode node, boolean branch) {
373+
node = checked_node and branch = true
374+
}
375+
}
376+
}
377+
358378
/**
359379
* Algebraic datatype for tracking data content associated with values.
360380
* Content can be collection elements or object attributes.

python/ql/test/experimental/dataflow/tainttracking/defaultSanitizer/TestTaint.expected renamed to python/ql/test/experimental/dataflow/tainttracking/commonSanitizer/TestTaint.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| test_string_eq.py:16 | fail | const_eq_clears_taint | ts |
1+
| test_string_eq.py:16 | ok | const_eq_clears_taint | ts |
22
| test_string_eq.py:18 | ok | const_eq_clears_taint | ts |
33
| test_string_eq.py:20 | ok | const_eq_clears_taint | ts |
44
| test_string_eq.py:27 | fail | const_eq_clears_taint2 | ts |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import experimental.dataflow.tainttracking.TestTaintLib
2+
3+
class CustomSanitizerOverrides extends TestTaintTrackingConfiguration {
4+
override predicate isSanitizerGuard(DataFlow::BarrierGuard guard) {
5+
guard instanceof DataFlow::BarrierGuard::StringConstCompare
6+
}
7+
}

python/ql/test/experimental/dataflow/tainttracking/defaultSanitizer/test_string_eq.py renamed to python/ql/test/experimental/dataflow/tainttracking/commonSanitizer/test_string_eq.py

File renamed without changes.

python/ql/test/experimental/dataflow/tainttracking/defaultSanitizer/TestTaint.ql

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)