Skip to content

Commit d1d9df7

Browse files
felickzCopilot
andcommitted
Address review: restrict @HostListener handler to window/document message targets
Drop the plain 'message' event name from the @HostListener matcher. The postMessage 'message' event is dispatched on window and does not bubble, so an element-level @HostListener('message') does not receive cross-window messages. Keeping only 'window:message' and 'document:message' makes the model more precise and matches the accompanying comment and change note. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9bffcf8 commit d1d9df7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • javascript/ql/lib/semmle/javascript/security/dataflow

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ class PostMessageEventHandler extends Function {
197197
)
198198
or
199199
// Angular's `@HostListener('window:message', ['$event'])` decorator registers
200-
// a method as a `message` event handler on the global `window`/`document`
200+
// a method as a `message` event handler on the global `window` or `document`
201201
// target. The decorated method receives the `MessageEvent` as its first
202202
// parameter, so it is equivalent to `window.addEventListener('message', ...)`.
203203
exists(MethodDefinition method, DataFlow::CallNode decorator |
204204
decorator = DataFlow::moduleMember("@angular/core", "HostListener").getACall() and
205205
decorator = method.getADecorator().getExpression().flow() and
206-
decorator.getArgument(0).mayHaveStringValue(["window:message", "document:message", "message"]) and
206+
decorator.getArgument(0).mayHaveStringValue(["window:message", "document:message"]) and
207207
method.getBody() = this and
208208
paramIndex = 0
209209
)

0 commit comments

Comments
 (0)