1+ /**
2+ * Provides a taint-tracking configuration for reasoning about client-side
3+ * request forgery.
4+ *
5+ * Note, for performance reasons: only import this file if
6+ * the `Configuration` class is needed, otherwise
7+ * `RequestForgeryCustomizations` should be imported instead.
8+ */
9+
10+ import javascript
11+ import semmle.javascript.security.dataflow.UrlConcatenation
12+ import semmle.javascript.security.dataflow.RequestForgeryCustomizations:: RequestForgery
13+ import BrowserAPI
14+
15+ /**
16+ * A taint tracking configuration for client-side request forgery.
17+ * Server side is disabled since this is in the browser, but the extra models can be enabled for extra coverage
18+ */
19+ class Configuration extends TaintTracking:: Configuration {
20+ Configuration ( ) { this = "ClientSideRequestForgery" }
21+
22+ override predicate isSource ( DataFlow:: Node source ) {
23+ exists ( Source src |
24+ source = src and
25+ not src .isServerSide ( )
26+ ) or
27+ source instanceof OnMessageExternal or source instanceof OnConnectExternal
28+ }
29+
30+ override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
31+
32+ override predicate isSanitizer ( DataFlow:: Node node ) {
33+ super .isSanitizer ( node ) or
34+ node instanceof Sanitizer
35+ }
36+
37+ override predicate isSanitizerOut ( DataFlow:: Node node ) { sanitizingPrefixEdge ( node , _) }
38+
39+ override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
40+ isAdditionalRequestForgeryStep ( pred , succ )
41+ }
42+ }
43+
44+ class BrowserStep extends DataFlow:: SharedFlowStep {
45+ override predicate step ( DataFlow:: Node pred , DataFlow:: Node succ ) {
46+ ( exists ( DataFlow:: ParameterNode p |
47+ pred instanceof SendMessage and
48+ succ = p and
49+ p .getParameter ( ) instanceof AddListener
50+ ) )
51+ }
52+ }
53+
54+ class ReturnStep extends DataFlow:: SharedFlowStep {
55+ override predicate step ( DataFlow:: Node pred , DataFlow:: Node succ ) {
56+ ( exists ( DataFlow:: ParameterNode p |
57+ succ instanceof SendMessageReturnValue and
58+ pred = p .getAnInvocation ( ) .getArgument ( 0 ) and
59+ p .getParameter ( ) instanceof AddListenerReturn
60+ ) )
61+ }
62+ }
63+
64+ class AwaitStep extends DataFlow:: SharedFlowStep {
65+ override predicate step ( DataFlow:: Node pred , DataFlow:: Node succ ) {
66+ succ .asExpr ( ) instanceof AwaitExpr and pred .asExpr ( ) = succ .asExpr ( ) .( AwaitExpr ) .getOperand ( )
67+ }
68+ }
0 commit comments