No Login Data Private Local Save

Trusted Types API Demo - Online Prevent XSS

6
0
0
0

Trusted Types API Demo

Online XSS Prevention Sandbox & Security Playground

Detecting...
"> Mouse Events
Controls which HTML elements & attributes survive sanitization
HTML / Payload Input Potentially Unsafe
Unsafe (Raw innerHTML)
Vulnerable
Safe (Trusted Types)
Sanitized
Generated Trusted Types Code Copy & Use
// Your Trusted Types implementation code will appear here...
// Select a payload and policy level, then click "Generate" or type in the editor
0
Dangerous constructs detected
0
Elements / Attributes sanitized
100%
Safe output confidence
Frequently Asked Questions

Trusted Types is a browser security API designed to eliminate DOM-based Cross-Site Scripting (XSS) attacks. It enforces that only trusted, sanitized data can be assigned to dangerous DOM sinks like innerHTML, outerHTML, document.write, and eval.

Instead of accepting arbitrary strings, these sinks require special typed objects — TrustedHTML, TrustedScript, or TrustedScriptURL — that can only be created through explicitly defined policies. This makes it impossible for attacker-controlled strings to reach execution contexts.

Trusted Types prevents XSS by enforcing a type-based security boundary:

  1. Default deny: All DOM sinks reject plain strings by default when Trusted Types are enforced via CSP.
  2. Policy enforcement: Developers must create explicit policies that validate or sanitize data before it reaches a sink.
  3. Audit trail: Each policy call is recorded, making it easy to audit where trusted values are created.
  4. Compile-time safety: TypeScript definitions help catch violations at development time.

For example, element.innerHTML = untrustedString will throw a TypeError when Trusted Types are enforced, forcing developers to use policy.createHTML(sanitizedString) instead.

As of 2024-2025, Trusted Types is supported in:

  • Google Chrome 83+ (full support)
  • Microsoft Edge 83+ (full support, Chromium-based)
  • Opera 69+ (Chromium-based)
  • Samsung Internet 14+
  • Firefox — Partial support in development (tracked in Bug 1709390)
  • Safari — Not yet supported (as of early 2025)

You can use feature detection: if (window.trustedTypes) { /* supported */ }. For unsupported browsers, consider using a polyfill or fallback sanitization library like DOMPurify.

Add one of these directives to your Content-Security-Policy HTTP header:

# Basic enforcement
Content-Security-Policy: require-trusted-types-for 'script';

# With a named policy
Content-Security-Policy: require-trusted-types-for 'script'; trusted-types myPolicy;

The require-trusted-types-for 'script' directive enables enforcement. The optional trusted-types directive restricts which policy names are allowed, adding an extra layer of security.

  • TrustedHTML — For HTML content assigned to innerHTML, outerHTML, insertAdjacentHTML, etc. Created via policy.createHTML().
  • TrustedScript — For script content passed to eval(), Function(), setTimeout() with string arguments, etc. Created via policy.createScript().
  • TrustedScriptURL — For URLs passed to script loading sinks like <script src>, import(), Web Workers, etc. Created via policy.createScriptURL().

Each type corresponds to a specific injection sink category, ensuring precise control over what data reaches each dangerous API.

Yes, but it requires coordination. Many popular libraries have already adopted Trusted Types compatibility:

  • DOMPurify — Returns TrustedHTML when Trusted Types are available
  • Angular — Built-in Trusted Types support since v11
  • React — Trusted Types compatible; uses text content by default for JSX
  • Lit (LitElement) — Full Trusted Types support
  • jQuery — Version 3.5+ added Trusted Types compatibility

For libraries that don't support Trusted Types, you can create a default policy as a fallback, but this should be used sparingly as it can weaken security.

No. Trusted Types is a defense-in-depth mechanism, not a replacement for proper input validation and output encoding. It acts as a safety net at the DOM level:

  • Input validation ensures data conforms to expected formats before processing
  • Output encoding ensures data is safely rendered in the correct context (HTML, JS, CSS, URL)
  • Trusted Types ensures that even if validation/encoding fails, dangerous sinks cannot accept untrusted strings

All three layers should be used together for comprehensive XSS protection.

  • Overly permissive default policies — A default policy that passes through unsanitized strings defeats the purpose
  • Forgetting about all sinks — Remember document.write, eval, setTimeout with strings, srcdoc on iframes, etc.
  • Third-party code — Ads, analytics, and widgets may break if they use forbidden sinks
  • Dynamic code generation — Template engines that compile to string-based innerHTML need updating
  • Reporting gaps — Use report-uri or report-to alongside enforcement to catch violations without breaking users

Start with Report-Only mode to identify violations before enforcing Trusted Types in production.

New

Semantic Versioning Validator - Online Check Semver Syntax

Validate and compare semantic version strings. Check if a version satisfies a range (e.g., ^1.2.3). Visual breakdown of major.minor.patch. Local only.

New

GeoJSON Validator - Online Check Geometry & Properties

Paste a GeoJSON object and validate its structure. Catch missing coordinates, wrong types, and feature errors. Local.

New

.htaccess Validator - Online Check Syntax

Paste your .htaccess rules and check for common syntax errors or misconfigurations. No server required; static analysis.

New

Web App Manifest Validator - Online Check PWA Manifest

Paste your manifest.json and instantly validate it against the W3C spec. Catch errors and warnings. Client‑side.

New

JSON-LD Validator - Online Structured Data Syntax Checker

Paste JSON-LD and validate basic syntax and required properties for Article, Product, etc. Local only. Instant feedback.

New

Launch Handler API Demo - Online Control App Launch Behavior

Configure how your PWA launches: focus existing or create new. Test with the launch_handler manifest field.

New

Semantic Versioning Validator - Check Semver Syntax

Validate if a version string follows SemVer 2.0.0. Also sort and compare versions. Developer tool.

New

Protocol Handler Registration - Online Register URL Scheme

Learn how to register your PWA to handle custom URL protocols. See the manifest entry and test.

New

CORS Proxy Emulator - Online Test Cross‑Origin Requests

Bypass CORS for testing by routing requests through a local service worker proxy. Debug APIs without server changes. Experimental.

New

NPM Version Badge Generator - Online Shields Style

Pick a package name and generate a custom version or download badge as a static image or Markdown link. For readme files.

New

SQL Injection Simulator - Online Educational Sandbox

Test SQL injection inputs on a mock database and see the resulting query. Learn how to prevent SQLi. No real data.

New

Get Installed Related Apps Demo - Online PWA Detection

Check if your related native or PWA app is installed. See the API in action and copy the code.

New

Swagger/OpenAPI YAML Previewer - Online Render & Test

Paste your Swagger/OpenAPI YAML and see a rendered API documentation preview with expandable endpoints. All local rendering.

New

PWA Manifest Generator - Online Create app.webmanifest

Fill in your PWA details to generate a valid manifest.json file. Include icons, theme color, display mode.

New

YAML to JSON Converter - Online Config Translator

Translate YAML configuration files into JSON format instantly. Validate syntax during conversion. Perfect for DevOps and configuration management. Secure client-side operation.

New

ZX Spectrum Basic Emulator - Online Retro Code Playground

Write and run simple Sinclair BASIC programs in a browser-based ZX Spectrum emulator. Load demo programs and experience 80s computing. Educational fun.

New

XML to JSON Converter - Online Parse XML to Object

Parse XML strings into compact JSON representation. Handles attributes and text nodes intelligently. Quick and private, ideal for API response translation.

New

Random RSA/EC Key Pair Demo - Online Cryptographic Visualization

Generate a dummy RSA or EC public/private key pair for educational visualization. Shows key structure and ASN.1 dump. Not for production use.

New

PBKDF2 Key Derivation Demo - Online Password‑Based Key

Derive a strong cryptographic key from a password using PBKDF2 with SHA‑256. Adjust iterations and salt. Educational and test tool.

New

Markdown Diff Viewer - Online Compare & Highlight Markdown

Paste two Markdown texts and see a side‑by‑side diff with rendered preview. Perfect for editing and collaboration.

New

PWA Icon Resizer & Manifest - Online Generate Sizes

Upload a 512x512 logo and get resized icons for every PWA requirement. Download a zip and the corresponding manifest.json snippet.

New

Git Semver Tag Generator - Online Create Release Tags

Generate a series of semantic version tags with optional prefixes. Copy for your release script. Consistent tagging.

New

Paper Fold Simulator - Online Virtual Origami Practice

Fold a virtual square paper step by step with crease lines and visual previews. Practice origami basics without wasting real paper. All canvas‑based.

New

GraphQL Schema to Markdown Docs - Online Generator

Paste a GraphQL SDL schema and get auto‑generated Markdown documentation. Perfect for API docs. All local.

New

Markdown Slide Deck - Online Presentation Builder

Write slides in Markdown and instantly preview a web‑based presentation. Export as HTML. Pure frontend.

New

Brick Breaker - Online Classic Breakout Arcade

Smash bricks with a ball and paddle. Multiple rows of colored bricks, power‑ups, and score tracking. All built with HTML5 Canvas.

New

Regex Injection / ReDoS Tester - Online Safe Pattern Test

Test a regular expression against malicious inputs to detect catastrophic backtracking and ReDoS vulnerabilities. Educational.

New

image‑rendering CSS Demo - Online Crisp or Smooth

Toggle image‑rendering: auto, pixelated, crisp‑edges on a scaled image. Essential for pixel art display.

New

Dark Mode Toggle Demo - Online Respect System Preference

Implement a dark/light theme toggle that respects prefers‑color‑scheme. Copy the complete JavaScript and CSS.

New

Clipboard Image Paste Demo - Online Ctrl+V to Preview

Press Ctrl+V to paste an image from your clipboard into the page. See dimensions and download. Simple utility.