Skip to content

Commit 1253553

Browse files
committed
JS: Add browser source kinds
1 parent 68dfa5c commit 1253553

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/ModelsAsData.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ private class RemoteFlowSourceFromMaD extends RemoteFlowSource {
3535
override string getSourceType() { result = "Remote flow" }
3636
}
3737

38+
private class ClientSideRemoteFlowSourceFromMaD extends ClientSideRemoteFlowSource {
39+
private ClientSideRemoteFlowKind kind;
40+
41+
ClientSideRemoteFlowSourceFromMaD() { ModelOutput::sourceNode(this, kind) }
42+
43+
override ClientSideRemoteFlowKind getKind() { result = kind }
44+
45+
override string getSourceType() {
46+
result = "Source node (" + this.getThreatModel() + ") [from data-extension]"
47+
}
48+
}
49+
3850
/**
3951
* A threat-model flow source originating from a data extension.
4052
*/

javascript/ql/lib/semmle/javascript/security/dataflow/RemoteFlowSources.qll

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,47 @@ import Cached
4343

4444
/**
4545
* A type of remote flow source that is specific to the browser environment.
46+
*
47+
* The underlying string also corresponds to a source kind.
4648
*/
4749
class ClientSideRemoteFlowKind extends string {
4850
ClientSideRemoteFlowKind() {
49-
this = ["query", "fragment", "path", "url", "name", "message-event"]
51+
this =
52+
[
53+
"browser", "browser-url-query", "browser-url-fragment", "browser-url-path", "browser-url",
54+
"browser-window-name", "browser-message-event"
55+
]
5056
}
5157

5258
/**
53-
* Holds if this is the `query` kind, describing sources derived from the query parameters of the browser URL,
59+
* Holds if this is the `browser` kind, indicating a remote source in a browser context, that does not fit into one
60+
* of the more specific kinds.
61+
*/
62+
predicate isGenericBrowserSourceKind() { this = "browser" }
63+
64+
/**
65+
* Holds if this is the `browser-url-query` kind, describing sources derived from the query parameters of the browser URL,
5466
* such as `location.search`.
5567
*/
56-
predicate isQuery() { this = "query" }
68+
predicate isQuery() { this = "browser-url-query" }
5769

5870
/**
59-
* Holds if this is the `frgament` kind, describing sources derived from the fragment part of the browser URL,
71+
* Holds if this is the `browser-url-fragment` kind, describing sources derived from the fragment part of the browser URL,
6072
* such as `location.hash`.
6173
*/
62-
predicate isFragment() { this = "fragment" }
74+
predicate isFragment() { this = "browser-url-fragment" }
6375

6476
/**
65-
* Holds if this is the `path` kind, describing sources derived from the pathname of the browser URL,
77+
* Holds if this is the `browser-url-path` kind, describing sources derived from the pathname of the browser URL,
6678
* such as `location.pathname`.
6779
*/
68-
predicate isPath() { this = "path" }
80+
predicate isPath() { this = "browser-url-path" }
6981

7082
/**
71-
* Holds if this is the `url` kind, describing sources derived from the browser URL,
83+
* Holds if this is the `browser-url` kind, describing sources derived from the browser URL,
7284
* where the untrusted part of the URL is prefixed by trusted data, such as the scheme and hostname.
7385
*/
74-
predicate isUrl() { this = "url" }
86+
predicate isUrl() { this = "browser-url" }
7587

7688
/** Holds if this is the `query` or `fragment` kind. */
7789
predicate isQueryOrFragment() { this.isQuery() or this.isFragment() }
@@ -83,13 +95,13 @@ class ClientSideRemoteFlowKind extends string {
8395
predicate isPathOrUrl() { this.isPath() or this.isUrl() }
8496

8597
/** Holds if this is the `name` kind, describing sources derived from the window name, such as `window.name`. */
86-
predicate isWindowName() { this = "name" }
98+
predicate isWindowName() { this = "browser-window-name" }
8799

88100
/**
89-
* Holds if this is the `message-event` kind, describing sources derived from cross-window message passing,
101+
* Holds if this is the `browser-message-event` kind, describing sources derived from cross-window message passing,
90102
* such as `event` in `window.onmessage = event => {...}`.
91103
*/
92-
predicate isMessageEvent() { this = "message-event" }
104+
predicate isMessageEvent() { this = "browser-message-event" }
93105
}
94106

95107
/**

0 commit comments

Comments
 (0)