Enhance sandbox component to accept sandbox prop - #69617
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks, @Imran92! The https://github.com/Automattic/videopress/issues/1217 link leads to 404 packages. Please don't use private links or dead links for other repositories as references. |
|
Thanks @Mamaduka , I've removed the links |
|
I see there are many |
|
We could allow passing additional |
The const sandbox = clsx( 'allow-scripts', 'allow-same-origin', 'allow-presentation', {
'allow-popups': allowPopups,
} );But handling such a string list inside the component is a bit unwieldy. We'd have to parse it, fork the behavior completely on presence of Just defining a new There is the downside that @mirka mentions: there are currently 14 |
jsnajdr
left a comment
There was a problem hiding this comment.
I think that API-design-wise the allowPopups prop is OK, although not ideal. I'm approving to signal that the entire PR is OK. But let's continue discussing if there are disagreements.
|
The I would prefer improving general support for Let's rebase, resolve conflicts and pipe tokens through |
Adds an allowPopups prop to the SandBox component so that content inside the sandboxed iframe (e.g. embeds with links) can open new browsing contexts. The token is off by default and is applied to both the isolated and same-origin sandbox variants. Co-authored-by: Konstantin Obenland <obenland@gmx.de>
The sandbox attribute is a space-separated token list, just like className, so clsx expresses the conditional allow-popups token more clearly than template-string concatenation. Suggested by @jsnajdr in the PR review. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks @Mamaduka! Clumsily rebased onto trunk, resolved the conflicts, and the sandbox attribute is now built with clsx in both sandbox variants. |
What?
Adds an optional
allowPopupsprop to theSandBoxcomponent, letting consumers opt intoallow-popupsin the iframe'ssandboxattribute.Why?
The iframe in the
SandBoxcomponent does not includeallow-popupsin itssandboxvalue. Because of this, links inside sandboxed content don't take users anywhere when clicked — the navigation is blocked.Our actual goal is to use this in the Jetpack repo to fix the VideoPress blocks. Jetpack consumes the
@wordpress/componentsnpm library, so this needs to be released on npm before we can move on with the next part of the fix.How?
Since this PR was opened,
SandBoxwas significantly refactored (#77212) and is now split into two internal variants, dispatched via theallowSameOriginprop:IsolatedSandBox(default) —sandbox="allow-scripts allow-presentation".allow-same-originwas deliberately dropped for user-controlled content (e.g. the HTML block) as a security hardening.SameOriginSandBox(allowSameOrigin) —sandbox="allow-scripts allow-same-origin allow-presentation", for server-fetched oEmbed previews.Neither variant includes
allow-popups. Rather than expose a rawsandboxstring override — which would let a caller passallow-same-originback into the isolated, user-controlled variant and quietly undo that hardening — this PR adds a targeted, opt-inallowPopups?: booleanprop (@default false). When set,allow-popupsis appended to whichever variant's defaultsandboxattribute. This keeps with trunk's boolean-flag design (alongsideallowSameOrigin) and preserves the existing security guarantees.Testing Instructions
SandBoxdoesn't break (default behavior is unchanged whenallowPopupsis not passed).SandBoxwithallowPopupsand confirm the iframe'ssandboxattribute includesallow-popups, and that a link inside the sandboxed content can open.Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A