postMessage sends data to whatever origin the target window has, with "*"

tx0/ts:post-message-any-originrecommendedwarningsecurity, cwe-345

What it finds

target.postMessage(data, "*") delivers the data to whatever page the target window shows at that moment. If the window was navigated elsewhere, or opened by an attacker, a foreign origin receives it. Naming the expected origin makes the browser drop the message otherwise.

Reported are calls of a method postMessage whose second argument is the literal "*"; for workers and message ports the second argument is a list of transferables, never a string.

From the rule's source, post_message_any_origin.rs.

Example from the rule's tests
export function send(frame: Window, worker: Worker, data: unknown) {  frame.postMessage(data, "*");tx0 reports: lets any origin receive this message  frame.postMessage(data, "https://app.example.org");  worker.postMessage(data, []);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:post-message-any-origin" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:post-message-any-origin] reason="..."

tx0 explain tx0/ts:post-message-any-origin shows the same in the terminal. Found a false positive? Report it.