Skip to content

Commit ee0140e

Browse files
committed
share code between unsafe-shell and unsafe-html queries
1 parent 23908f9 commit ee0140e

File tree

3 files changed

+4
-26
lines changed

3 files changed

+4
-26
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeHtmlConstruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module UnsafeHtmlConstruction {
3636
}
3737

3838
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
39-
classFieldStep(pred, succ)
39+
DataFlow::localFieldStep(pred, succ)
4040
}
4141
}
4242
}

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeHtmlConstructionCustomizations.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,6 @@ module UnsafeHtmlConstruction {
166166
override string describe() { result = "Markdown rendering" }
167167
}
168168

169-
/**
170-
* A taint step from the write of a field in a constructor to a read of the same field in an instance method.
171-
*/
172-
predicate classFieldStep(DataFlow::Node pred, DataFlow::Node succ) {
173-
// flow-step from a property written in the constructor to a use in an instance method.
174-
// "simulates" client usage of a class, and regains some flow-steps lost by `requireMatchedReturn` below.
175-
exists(DataFlow::ClassNode clazz, string prop |
176-
DataFlow::thisNode(clazz.getConstructor().getFunction()).getAPropertyWrite(prop).getRhs() =
177-
pred and
178-
DataFlow::thisNode(clazz.getAnInstanceMethod().getFunction()).getAPropertyRead(prop) = succ
179-
)
180-
}
181-
182169
/**
183170
* Holds if there is a path without unmatched return steps from `source` to `sink`.
184171
*/

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstruction.qll

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import javascript
1414
*/
1515
module UnsafeShellCommandConstruction {
1616
import UnsafeShellCommandConstructionCustomizations::UnsafeShellCommandConstruction
17+
import UnsafeHtmlConstructionCustomizations
1718

1819
/**
1920
* A taint-tracking configuration for reasoning about shell command constructed from library input vulnerabilities.
@@ -35,21 +36,11 @@ module UnsafeShellCommandConstruction {
3536
// override to require that there is a path without unmatched return steps
3637
override predicate hasFlowPath(DataFlow::SourcePathNode source, DataFlow::SinkPathNode sink) {
3738
super.hasFlowPath(source, sink) and
38-
exists(DataFlow::MidPathNode mid |
39-
source.getASuccessor*() = mid and
40-
sink = mid.getASuccessor() and
41-
mid.getPathSummary().hasReturn() = false
42-
)
39+
UnsafeHtmlConstruction::requireMatchedReturn(source, sink)
4340
}
4441

4542
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
46-
// flow-step from a property written in the constructor to a use in an instance method.
47-
// "simulates" client usage of a class, and regains some flow-steps lost by `hasFlowPath` above.
48-
exists(DataFlow::ClassNode clz, string name |
49-
pred =
50-
DataFlow::thisNode(clz.getConstructor().getFunction()).getAPropertyWrite(name).getRhs() and
51-
succ = DataFlow::thisNode(clz.getInstanceMethod(_).getFunction()).getAPropertyRead(name)
52-
)
43+
DataFlow::localFieldStep(pred, succ)
5344
}
5445
}
5546
}

0 commit comments

Comments
 (0)