Sandbox website tiles by default; opt into same-origin per widget
A website tile now runs in an opaque origin (allow-scripts, popups, forms). Its new "Trusted site" setting adds allow-same-origin for sites that need their own cookies and storage, and a trusted tile pointing at the origin the app runs on (its own, or the hub's) shows a notice instead of the frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013GAeg4Jo6xjZzjwy9QDWMQ
This commit is contained in:
@@ -459,6 +459,23 @@ export function embedUrl(widget: WidgetDef): string {
|
||||
return /^https?:\/\//i.test(url) ? url : ""
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether *url* is on *origin*: the one a trusted embed must not load.
|
||||
*
|
||||
* `allow-same-origin` lets a page keep its own origin, which for another site
|
||||
* is only what visiting it would do. For a page on the origin this app runs on
|
||||
* — its own, or the hub's when it is served through one — it means scripts
|
||||
* that can reach into the app and read its session. An address that does not
|
||||
* parse counts as one.
|
||||
*/
|
||||
export function onOrigin(url: string, origin: string): boolean {
|
||||
try {
|
||||
return new URL(url).origin === origin
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Somebody else's page, drawn in the tile.
|
||||
*
|
||||
@@ -466,21 +483,31 @@ export function embedUrl(widget: WidgetDef): string {
|
||||
* — with no binding of its own, so nothing has to be modelled as a message
|
||||
* first. A site that refuses to be framed (`X-Frame-Options`) shows its own
|
||||
* refusal inside the tile; that is between the browser and the site.
|
||||
*
|
||||
* By default the page runs in an opaque origin, with no cookies or storage of
|
||||
* its own. **Trusted** keeps it in its own origin, which most interactive
|
||||
* sites need to start (the demo's weather map renders an unstyled list
|
||||
* without it), and is refused for this app's own origin.
|
||||
*/
|
||||
function EmbedWidget({ widget }: WidgetProps) {
|
||||
const url = embedUrl(widget)
|
||||
const trusted = config(widget).trusted === true
|
||||
if (!url) return <p className="text-muted-foreground">Give it an address.</p>
|
||||
if (trusted && onOrigin(url, window.location.origin)) {
|
||||
return (
|
||||
<p className="text-muted-foreground" data-testid="embed-refused">
|
||||
This app's own address cannot be a trusted site.
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<iframe
|
||||
// A changed sandbox applies from the next navigation only, so a toggle
|
||||
// reloads the frame rather than leaving the old one running.
|
||||
key={trusted ? "trusted" : "sandboxed"}
|
||||
src={url}
|
||||
title={widget.title || url}
|
||||
// `allow-same-origin` keeps the page in its own origin, with the
|
||||
// cookies and storage most sites will not start without: the demo's
|
||||
// weather map renders an unstyled list without it. That is safe only
|
||||
// while the page *is* another origin. One served from this app's own
|
||||
// origin would run as the app, scripts and all, and could read the
|
||||
// session.
|
||||
sandbox="allow-scripts allow-popups allow-forms allow-same-origin"
|
||||
sandbox={`allow-scripts allow-popups allow-forms${trusted ? " allow-same-origin" : ""}`}
|
||||
referrerPolicy="no-referrer"
|
||||
loading="lazy"
|
||||
className="h-full w-full rounded-md border-0"
|
||||
|
||||
Reference in New Issue
Block a user