Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@chopsui/trusted-types-policy

Package Overview
Dependencies
Maintainers
11
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chopsui/trusted-types-policy

Creates a secure TrustedTypes policy using DOMPurify as the sanitizer.

latest
npmnpm
Version
0.3.7
Version published
Weekly downloads
45
-25%
Maintainers
11
Weekly downloads
 
Created
Source

Trusted Types Policy

Purpose

This package contains a function that creates a trusted types policy for HTML and JavaScript UIs which are using React (or any other framework) to protect from insecure usage of dangerouslySetInnerHTML either by the devs or any package/library that the project is using. If TrustedTypes are not supported by the browser it will fall back to the polyfill, see support here.

Usage

  • Add this meta tag line to your main HTML/template file, or all of them if you have multiple in the <head> tag.

    <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">
    
  • Call this method in your entry point ts file (for React that will be index.tsx or index.ts)

    import createInnerHTMLSanitizingPolicy from '@chopsui/trusted-types-policy';
    
    createInnerHTMLSanitizingPolicy();
    

This should create a Trusted Types policy and any HTML string being insterted will be converted to a trusted type element.

FAQs

Package last updated on 01 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts