Strip the opener from every link a Gadget UI opens - #113
Open
RenKoya1 wants to merge 1 commit into
Open
Conversation
The Gadget iframe carries allow-popups-to-escape-sandbox, so a link it
opens lands in an unsandboxed context; the injected click handler exists
to make sure that context has no opener. It only matched
`a[href][target]` with `target === "_blank"`, and two shapes slip past:
- a link with no target attribute of its own, in a document carrying
`<base target="_blank">`. CSP's base-uri restricts a base element's
href, not its target, so Gadget code can set the default target for
every link on the page, and `a.target` stays "".
- an SVG anchor, whose `.target` is an SVGAnimatedString, so
`.toLowerCase()` throws and the handler never reaches the rel write.
Match any anchor instead of deciding which ones open a new context.
rel=noopener is inert on a same-context navigation, so over-applying it
costs nothing, and neither shape can slip through.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Gadget iframe is
sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox", so a link it opens lands in a context that is no longer sandboxed. The capture-phase click handler inINJECTED_CODE_PREFIXis what makes sure that context has noopener.It matched
a[href][target]and then requiredanchor.target.toLowerCase() === "_blank". Two shapes reach a new context without satisfying that:targetattribute, in a document carrying<base target="_blank">. CSP'sbase-urirestricts a base element's href, not its target, so Gadget code can set the default target for every link on the page. The anchor's owntargetattribute stays absent, so it does not match the selector anda.targetis"".SVGAElement.targetis anSVGAnimatedString, so.toLowerCase()throws and the handler never reaches therelwrite.The fix stops trying to decide which links open a new context and matches any anchor.
rel=noopeneris inert on a same-context navigation, so over-applying it costs nothing, while under-applying it is the failure that matters here. Dropping the.targetread removes the SVG hazard as a side effect.Verification
The handler ships as a string injected into the sandboxed frame, so it is not reachable from the jsdom suite — there is no unit test to add against the shipped code. I ran the two selectors against a jsdom document to confirm the behaviour rather than infer it:
pnpm exec tsc --noEmitclean,workshop-frontendsuite 118/118, oxlint reports nothing new.