Skip to content

Commit 2d26405

Browse files
committed
JS: Treat browser message events as client-side sources
1 parent c1d03ac commit 2d26405

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ class PostMessageEventHandler extends Function {
207207
* An event parameter for a `postMessage` event handler, considered as an untrusted
208208
* source of data.
209209
*/
210-
private class PostMessageEventParameter extends RemoteFlowSource {
210+
private class PostMessageEventParameter extends ClientSideRemoteFlowSource {
211211
PostMessageEventParameter() {
212212
this = DataFlow::parameterNode(any(PostMessageEventHandler pmeh).getEventParameter())
213213
}
214214

215215
override string getSourceType() { result = "postMessage event" }
216+
217+
override ClientSideRemoteFlowKind getKind() { result.isMessageEvent() }
216218
}
217219

218220
/**

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import Cached
4040
* A type of remote flow source that is specific to the browser environment.
4141
*/
4242
class ClientSideRemoteFlowKind extends string {
43-
ClientSideRemoteFlowKind() { this = ["query", "fragment", "path", "url", "name"] }
43+
ClientSideRemoteFlowKind() {
44+
this = ["query", "fragment", "path", "url", "name", "message-event"]
45+
}
4446

4547
/**
4648
* Holds if this is the `query` kind, describing sources derived from the query parameters of the browser URL,
@@ -77,6 +79,12 @@ class ClientSideRemoteFlowKind extends string {
7779

7880
/** Holds if this is the `name` kind, describing sources derived from the window name, such as `window.name`. */
7981
predicate isWindowName() { this = "name" }
82+
83+
/**
84+
* Holds if this is the `message-event` kind, describing sources derived from cross-window message passing,
85+
* such as `event` in `window.onmessage = event => {...}`.
86+
*/
87+
predicate isMessageEvent() { this = "message-event" }
8088
}
8189

8290
/**

0 commit comments

Comments
 (0)