Skip to content

Commit 5301f2e

Browse files
committed
Java: Diff-informed UnsafeDeserialization.ql
With this change, the slowest data-flow analysis in this query is made diff-informed with the same approach as for XSS.
1 parent 5c21424 commit 5301f2e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

java/ql/lib/semmle/code/java/security/UnsafeDeserializationQuery.qll

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,12 @@ predicate looksLikeResolveClassStep(DataFlow::Node fromNode, DataFlow::Node toNo
379379

380380
/** A sink representing an argument of a deserialization method */
381381
private class UnsafeTypeSink extends DataFlow::Node {
382+
MethodCall ma;
383+
384+
MethodCall getMethodCall() { result = ma }
385+
382386
UnsafeTypeSink() {
383-
exists(MethodCall ma, int i, Expr arg | i > 0 and ma.getArgument(i) = arg |
387+
exists(int i, Expr arg | i > 0 and ma.getArgument(i) = arg |
384388
(
385389
ma.getMethod() instanceof ObjectMapperReadMethod
386390
or
@@ -425,6 +429,25 @@ module UnsafeTypeConfig implements DataFlow::ConfigSig {
425429
predicate isAdditionalFlowStep(DataFlow::Node fromNode, DataFlow::Node toNode) {
426430
isUnsafeTypeAdditionalTaintStep(fromNode, toNode)
427431
}
432+
433+
predicate observeDiffInformedIncrementalMode() {
434+
// Since this configuration is for finding sinks to be used in a main
435+
// data-flow configuration, this configuration should only restrict the
436+
// sinks to be found if there are no main-configuration sources in the diff
437+
// range. That's because if there is such a source, we need to report query
438+
// results for it even with sinks outside the diff range.
439+
not UnsafeDeserializationFlow::hasSourceInDiffRange()
440+
}
441+
442+
// The query does not select the sources of this configuration
443+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
444+
445+
Location getASelectedSinkLocation(DataFlow::Node sink) {
446+
// Match by the surrounding method call since the sink of the overall
447+
// query will be contained in that (see the body of
448+
// `unsafeDeserialization/2`).
449+
result = sink.(UnsafeTypeSink).getMethodCall().getLocation()
450+
}
428451
}
429452

430453
/**

0 commit comments

Comments
 (0)