All Projects → w3c → Webappsec Trusted Types

w3c / Webappsec Trusted Types

Licence: other
A browser API to prevent DOM-Based Cross Site Scripting in modern web applications.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webappsec Trusted Types

Browser Sec Whitepaper
Cure53 Browser Security White Paper
Stars: ✭ 251 (-40.8%)
Mutual labels:  xss, dom
Javascript Steppitguide
JavaScript-StepPitGuide《JavaScript踩坑指南》- 说前端简单的什么的最变态了!
Stars: ✭ 30 (-92.92%)
Mutual labels:  w3c, dom
Dompurify
DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
Stars: ✭ 8,177 (+1828.54%)
Mutual labels:  xss, dom
smart-custom-element
Smart a lightweight web component library that provides capabilities for web components, such as data binding, using es6 native class inheritance. This library is focused for providing the developer the ability to write robust and native web components without the need of dependencies and an overhead of a framework.
Stars: ✭ 17 (-95.99%)
Mutual labels:  polyfill, dom
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (-83.73%)
Mutual labels:  dom, w3c
Arachni
Web Application Security Scanner Framework
Stars: ✭ 2,942 (+593.87%)
Mutual labels:  xss, dom
Dom4
Modern DOM functionalities for every browser
Stars: ✭ 903 (+112.97%)
Mutual labels:  polyfill, dom
parsed-html-rewriter
A DOM-based implementation of Cloudflare Worker's HTMLRewriter.
Stars: ✭ 34 (-91.98%)
Mutual labels:  polyfill, dom
sanitizer-polyfill
rewrite constructor arguments, call DOMPurify, profit
Stars: ✭ 46 (-89.15%)
Mutual labels:  polyfill, xss
Dom
Modern DOM API.
Stars: ✭ 88 (-79.25%)
Mutual labels:  dom, w3c
Wpt
Test suites for Web platform specs — including WHATWG, W3C, and others
Stars: ✭ 3,573 (+742.69%)
Mutual labels:  w3c, dom
Polyfill Library
NodeJS module to create polyfill bundles tailored to individual user-agents.
Stars: ✭ 404 (-4.72%)
Mutual labels:  polyfill
Eslint Plugin Testing Library
ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library
Stars: ✭ 384 (-9.43%)
Mutual labels:  dom
Xsser
From XSS to RCE 2.75 - Black Hat Europe Arsenal 2017 + Extras
Stars: ✭ 381 (-10.14%)
Mutual labels:  xss
Polyfill Ctype
This component provides a partial, native PHP implementation for the Ctype extension.
Stars: ✭ 3,774 (+790.09%)
Mutual labels:  polyfill
Hrjs
🔄 Tiny JavaScript plugin for highlighting and replacing text in the DOM
Stars: ✭ 420 (-0.94%)
Mutual labels:  dom
Wheels
以自己是否能造出轮子来衡量学习的效果
Stars: ✭ 406 (-4.25%)
Mutual labels:  dom
Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+847.64%)
Mutual labels:  dom
Fn Fx
A Functional API around JavaFX / OpenJFX.
Stars: ✭ 373 (-12.03%)
Mutual labels:  dom
Fakeindexeddb
A pure JS in-memory implementation of the IndexedDB API
Stars: ✭ 373 (-12.03%)
Mutual labels:  polyfill

Build Status npm bundle size Libraries.io dependency status for latest release GitHub issues npm BrowserStack Status

Trusted Types

First time here? This is a repository hosting the Trusted Types specification draft and the polyfill code. You might want to check out other resources about Trusted Types:

Polyfill

This repository contains a polyfill implementation that allows you to use the API in all web browsers. The compiled versions are stored in dist directory.

Browsers

The ES5 / ES6 builds can be loaded directly in the browsers. There are two variants of the browser polyfill - api_only (light) and full. The api_only variant defines the API, so you can create policies and types. Full version also enables the type enforcement in the DOM, based on the CSP policy it infers from the current document (see src/polyfill/full.js).

<!-- API only -->
<script src="https://w3c.github.io/webappsec-trusted-types/dist/es5/trustedtypes.api_only.build.js"></script>
<script>
     const p = trustedTypes.createPolicy('foo', ...)
     document.body.innerHTML = p.createHTML('foo'); // works
     document.body.innerHTML = 'foo'; // but this one works too (no enforcement).
</script>
<!-- Full -->
<script src="https://w3c.github.io/webappsec-trusted-types/dist/es5/trustedtypes.build.js" data-csp="trusted-types foo bar; require-trusted-types-for 'script'"></script>
<script>
    trustedTypes.createPolicy('foo', ...);
    trustedTypes.createPolicy('unknown', ...); // throws
    document.body.innerHTML = 'foo'; // throws
</script>

NodeJS

Polyfill is published as an npm package trusted-types:

$ npm install trusted-types

The polyfill supports both CommonJS and ES Modules.

const tt = require('trusted-types'); // or import {tt} from 'trusted-types'
tt.createPolicy(...);

Tinyfill

Due to the way the API is designed, it's possible to polyfill the most important API surface (trustedTypes.createPolicy function) with the following snippet:

if(typeof trustedTypes == 'undefined')trustedTypes={createPolicy:(n, rules) => rules};

It does not enable the enforcement, but allows the creation of policies that return string values instead of Trusted Types in non-supporting browsers. Since the injection sinks in those browsers accept strings, the values will be accepted unless the policy throws an error. This tinyfill code allows most applications to work in both Trusted-Type-enforcing and a legacy environment.

Building

To build the polyfill yourself (Java required):

$ git clone https://github.com/w3c/webappsec-trusted-types/
$ cd trusted-types
$ npm install
$ npm run build

Demo

To see the polyfill in action, visit the demo page.

Testing

It can be tested by running:

$ npm test

The polyfill can also be run against the web platform test suite, but that requires small patches to the suite - see tests/platform-tests/platform-tests-runner.sh.

Cross-browser testing provided by BrowserStack.

BrowserStack

Contributing

See CONTRIBUTING.

Questions?

Our wiki or the specification may already contain an answer to your question. If not, please contact us!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].