Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/components/WorkspaceOperationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ function HtmlPreviewFrame({
if (fitRafRef.current != null) cancelAnimationFrame(fitRafRef.current);
}, []);

// Keep untrusted agent HTML in an opaque origin: combining scripts and same-origin
// would let it access the application's storage and authenticated browser state.
return (
<div className="workspace-op-html-fit" ref={containerRef}>
<iframe
ref={frameRef}
sandbox="allow-same-origin allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-pointer-lock allow-top-navigation-by-user-activation"
sandbox="allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-pointer-lock allow-top-navigation-by-user-activation"
src={src}
srcDoc={src ? undefined : renderContent}
title={title}
Expand Down
16 changes: 16 additions & 0 deletions frontend/tests/htmlPreviewSandboxContract.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';

const workspacePanel = readFileSync(
new URL('../src/components/WorkspaceOperationPanel.tsx', import.meta.url),
'utf8',
);

test('HTML preview keeps agent-generated scripts in an opaque-origin sandbox', () => {
const sandboxMatch = workspacePanel.match(/sandbox="([^"]+)"/);

assert.ok(sandboxMatch, 'HTML preview iframe must declare a sandbox');
assert.match(sandboxMatch[1], /\ballow-scripts\b/);
assert.doesNotMatch(sandboxMatch[1], /\ballow-same-origin\b/);
});