Skip to content

Commit f697511

Browse files
authored
Merge pull request #20083 from aschackmull/java/prune-csrf-unprotected-request-type
Java: Prune PathGraph for CsrfUnprotectedRequestType.ql
2 parents ededa3c + 996de78 commit f697511

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,35 @@ private predicate sink(CallPathNode sinkMethodCall) {
237237
)
238238
}
239239

240+
private predicate fwdFlow(CallPathNode n) {
241+
source(n)
242+
or
243+
exists(CallPathNode mid | fwdFlow(mid) and CallGraph::edges(mid, n))
244+
}
245+
246+
private predicate revFlow(CallPathNode n) {
247+
fwdFlow(n) and
248+
(
249+
sink(n)
250+
or
251+
exists(CallPathNode mid | revFlow(mid) and CallGraph::edges(n, mid))
252+
)
253+
}
254+
255+
/**
256+
* Holds if `pred` has a successor node `succ` and this edge is in an
257+
* `unprotectedStateChange` path.
258+
*/
259+
predicate relevantEdge(CallPathNode pred, CallPathNode succ) {
260+
CallGraph::edges(pred, succ) and revFlow(pred) and revFlow(succ)
261+
}
262+
240263
/**
241264
* Holds if `sourceMethod` is an unprotected request handler that reaches a
242265
* `sinkMethodCall` that updates a database.
243266
*/
244267
private predicate unprotectedDatabaseUpdate(CallPathNode sourceMethod, CallPathNode sinkMethodCall) =
245-
doublyBoundedFastTC(CallGraph::edges/2, source/1, sink/1)(sourceMethod, sinkMethodCall)
268+
doublyBoundedFastTC(relevantEdge/2, source/1, sink/1)(sourceMethod, sinkMethodCall)
246269

247270
/**
248271
* Holds if `sourceMethod` is an unprotected request handler that appears to

java/ql/src/Security/CWE/CWE-352/CsrfUnprotectedRequestType.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java
1616
import semmle.code.java.security.CsrfUnprotectedRequestTypeQuery
1717

18-
query predicate edges(CallPathNode pred, CallPathNode succ) { CallGraph::edges(pred, succ) }
18+
query predicate edges(CallPathNode pred, CallPathNode succ) { relevantEdge(pred, succ) }
1919

2020
from CallPathNode source, CallPathNode sink
2121
where unprotectedStateChange(source, sink)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy