Iframe Sandbox and Trusted Types Policy Builder

Embed third-party content with the least power it needs, and prepare your scripts for Trusted Types with a policy, a CSP header and a sink scan.

브라우저에서 실행됩니다. 파일은 기기 밖으로 나가지 않습니다. 확인하는 방법 보기

…

사용 방법

  1. 1
    Pick a preset

    Start from a preset that matches what you embed.

  2. 2
    Choose tokens

    Tick sandbox tokens and read each risk note.

  3. 3
    Delegate features

    Set the allow list for features the frame needs.

  4. 4
    Test the probe

    Reload the probe to see what the frame can do.

  5. 5
    Write policies

    Define Trusted Types policies, a default policy and reporting.

  6. 6
    Scan and copy

    Scan your code for sinks, then copy the tag, header and policy code.

이 도구 소개

Two browser features reduce the damage that untrusted HTML and scripts can do. The sandbox attribute on an iframe starts from zero, with no scripts, forms, pop-ups, downloads or same-origin access, and you add back only the capabilities the embedded content needs, one token at a time. The allow attribute delegates individual powerful features such as fullscreen, camera or payment to the frame. Trusted Types attack DOM-based cross-site scripting from the other side: once a page sends the CSP directive require-trusted-types-for 'script', strings can no longer be written into dangerous places such as innerHTML, eval or a script's src unless they pass through a named policy you wrote. Both features are powerful, but the details are easy to get wrong. One extra sandbox token can cancel the whole sandbox, and switching on Trusted Types without preparation breaks every unconverted sink. This builder gives you both with explanations and checks.

Sandbox and allow

Choose a preset (untrusted user HTML, third-party widget, video player embed or payment form) or tick tokens yourself. Each of the 14 tokens shows a low, medium or high risk label and what it unlocks. The risk panel explains dangerous combinations: allow-scripts with allow-same-origin on content from your own origin lets the frame remove its own sandbox; allow-top-navigation lets it redirect your visitors; allow-popups-to-escape-sandbox opens unsandboxed windows. The allow list covers 16 features with the frame's own origin, self only, any origin, listed origins or none. The finished iframe tag includes title for screen readers, size, referrerpolicy and lazy loading, and a matching CSP sandbox directive is shown for pages that are always framed.

Live probe

A small local test page loads inside an iframe with your tokens and reports whether scripts ran, which origin it has, whether storage and cookies are reachable and whether it can touch the parent page. It makes the effect of allow-same-origin visible at once.

Trusted Types policy

Define one or more named policies. createHTML can sanitise with DOMPurify, escape everything or refuse HTML; createScriptURL accepts only the origins or prefixes you list; createScript can refuse all strings. An optional default policy logs every sink you have not converted yet, which is how most teams migrate. The tool writes the CSP header, in report-only mode first if you like, with a report-uri, and the JavaScript that registers the policies.

Readiness scan

Paste front-end code or templates to list lines that use known sinks: innerHTML, outerHTML, insertAdjacentHTML, document.write, srcdoc, createContextualFragment, DOMParser, eval, new Function, string timers, script src, workers, importScripts and the framework escape hatches dangerouslySetInnerHTML, v-html and Angular innerHTML bindings. Counts by type and a checklist show the order of work.

Limits

The sink scan matches patterns line by line; it does not parse JavaScript or follow data flow, and minified bundles need runtime reports to find everything. Trusted Types are supported in Chromium-based browsers and newer releases of other engines; elsewhere the directive is ignored, so keep sanitising regardless. If this site's own policy blocks inline scripts, the probe will show scripts as blocked even when your tokens allow them.

풀이 예시

A travel site embeds a booking widget from https://widget.example.com. The starting tokens are allow-scripts, allow-forms and allow-popups. Adding allow-same-origin raises no alarm because the widget is on another origin, but ticking The framed page is on my own origin turns the warning red. The final tag has 3 tokens, title Booking widget, height 420 and loading lazy. For Trusted Types, one policy named app sanitises HTML with DOMPurify and allows scripts only from https://cdn.example.com/. The sample code scan finds 3 TrustedHTML, 2 TrustedScript and 1 TrustedScriptURL sinks, and the header starts as Content-Security-Policy-Report-Only with report-uri /csp-report.

한눈에 보기

자주 묻는 질문

What does an empty sandbox attribute do?

It applies every restriction: no scripts, no forms, no pop-ups, no downloads and a unique opaque origin. It is the safest way to display untrusted HTML.

Why is allow-scripts plus allow-same-origin dangerous?

If the framed content comes from your own origin, its scripts can reach the parent page and remove the sandbox attribute, so the restriction no longer exists.

What is the difference between sandbox and allow?

sandbox removes general capabilities such as scripts and forms. allow delegates specific powerful features such as camera, fullscreen or payment that are blocked in cross-origin frames by default.

Will Trusted Types break my site?

Enforcing them without preparation will block every unconverted sink. Start in report-only mode with a default policy that logs, fix the callers, then enforce.

Do I need DOMPurify?

Only if your policy must accept user-supplied HTML. Escaping or refusing HTML needs no library.

Is my code uploaded for the scan?

No. The scan runs in your browser and nothing is stored except a local draft.

완전 무료요금 없음, 가입 없음
파일은 비공개로 유지됩니다모든 작업이 브라우저 안에서 이루어집니다
내 언어로 쉽게여러 언어로 제공