Skip to content

Refuse script messages that aren't from the main frame - #263

Draft
olivaresf wants to merge 1 commit into
mainfrom
drop-subframe-script-messages
Draft

olivaresf wants to merge 1 commit into
mainfrom
drop-subframe-script-messages

Conversation

@olivaresf

Copy link
Copy Markdown
Member

No description provided.

Both the bridge and turbo message handlers construct this one class, and
it forwarded every WKScriptMessage to its delegate without ever asking
which frame sent it. Any subframe a page embeds - a third-party ad, an
OAuth widget, a video player - could post to
window.webkit.messageHandlers.bridge or .turbo and be obeyed with the
main document's authority: proposing a visit, supplying the HTML that
becomes the document, or driving any registered bridge component.

The forMainFrameOnly: true flag on the injected user scripts does not
close this. It scopes where the injected JavaScript runs, not which
frames may post to a handler, and messageHandlers is present in every
frame regardless - a subframe can skip the wrapper and call postMessage
with a hand-built body.

WKScriptMessage carries frameInfo, which WebKit populates and the page
cannot forge, so read isMainFrame from the platform instead of trusting
anything the page supplies. The refused origin is logged so an app that
was relying on a subframe message can see why it stopped arriving.
@olivaresf

Copy link
Copy Markdown
Member Author

Implementation-only diff: dbc4fc0..54b3e6eSource/ScriptMessageHandler.swift, 1 file changed, 6 insertions(+), 0 deletions. Tests land in a separate commit on top of this range; this range is the implementation read.

Context receipt — acceptance clause built to: "every legitimate bridge component still works; a foreign-origin subframe gets no bridge at all, with a log line saying why." Platform contract of record: WKScriptMessage.frameInfoWKFrameInfo.isMainFrame / .securityOrigin (all non-optional, verified against the iOS 26.4 SDK WebKit headers rather than cited from memory).

Baseline: existing suite green on this range — 368 tests passed via xcodebuild test -scheme HotwireNative -destination "name=iPhone 17 Pro", the repo's own CI invocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant