-
Notifications
You must be signed in to change notification settings - Fork 279
Context preview Future developments
This document outlines planned improvements and open design questions for the Context Preview feature.
All <script> tags are stripped from fetched HTML documents before rendering in the preview panels. Scripts inserted
via innerHTML are inert by HTML spec, so even prior to stripping they never executed — the removal simply reduces DOM
bloat and makes the no-execution policy explicit.
The question was raised whether scripts hosted on files.sandbox.translated.com (Translated's own infrastructure) could
be treated as safe and retained in the preview HTML, since they power JS-driven layouts (accordions, tab panels,
lazy-loaded content) that would otherwise remain in their initial/hidden state.
External scripts must not be retained in the rendered HTML — even when originating from Translated-owned domains — for the following reasons:
- Unverified execution context. Customer-uploaded files may contain arbitrary JavaScript. The fact that a script is hosted on a Translated domain does not guarantee its contents have been audited or sandboxed. A customer could upload an HTML file referencing scripts that make external network calls, exfiltrate data, or interact with browser APIs in unexpected ways.
-
CSP bypass risk. If the Content-Security-Policy of the preview page allows
files.sandbox.translated.comas a script source, any script hosted there — including those uploaded by customers — would execute with full CSP approval. This effectively turns a trusted origin into an attacker-controlled execution surface. - Domain trust is not content trust. Allowlisting a domain in CSP means trusting every resource served from that domain. Since the sandbox hosts user-uploaded content, domain-level trust does not imply content-level trust.
The only scenario in which script execution could be safely re-enabled is by generating a dedicated HTML response with a restrictive CSP that completely isolates the preview's execution environment:
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline' https://files.sandbox.translated.com; img-src https://files.sandbox.translated.com data:; font-src https://files.sandbox.translated.com; script-src 'none'Key properties of this approach:
-
script-src 'none'— No scripts execute at all, regardless of origin. This is the maximum-isolation baseline. -
Selective relaxation — If specific trusted scripts are identified and audited,
script-srccould be narrowed to a hash-based or nonce-based allowlist rather than a domain allowlist. -
Separate document context — The preview would need to be served as a full HTML document (e.g., via an iframe with
sandboxattributes) rather than injected into the main page's DOM, so the CSP applies independently. -
sandboxiframe attributes — Combine CSP with<iframe sandbox="allow-same-origin">(withoutallow-scripts) for defense-in-depth. Thesandboxattribute provides a browser-enforced execution boundary even if CSP is misconfigured.
| Risk | Description | Mitigation |
|---|---|---|
| XSS via inline event handlers |
onclick, onerror, etc. attributes in customer HTML can execute JS even without <script> tags |
Strip inline event handler attributes during parsing, or rely on CSP script-src 'none' to block them |
| Data exfiltration | Scripts could send document content to external endpoints |
connect-src 'none' in CSP; sandbox without allow-scripts
|
| DOM manipulation | Executed JS could interfere with segment tagging and highlighting | Isolation via iframe/shadow DOM boundary |
| Resource loading side-effects | CSS/fonts/images could leak referrer or timing information |
referrerpolicy="no-referrer" on the iframe |
| Performance | Executing customer JS could block the main thread or cause infinite loops | Isolated iframe prevents main-thread blocking; consider allow-scripts only with a timeout/kill mechanism |
Maintain the current no-script policy. If JS-driven layouts cause significant usability issues (many hidden nodes),
explore the isolated-iframe approach with sandbox + strict CSP as a follow-up initiative rather than relaxing script
execution in the existing Shadow DOM panels.