1- # npm-template
1+ # @ aegisjsproject/trusted-types
22
3- A template repo for npm packages
3+ A polyfill for the [ Trusted Types API ] ( https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API )
44
5- [ ![ CodeQL] ( https://github.com/shgysk8zer0/node-http /actions/workflows/codeql-analysis.yml/badge.svg )] ( https://github.com/shgysk8zer0/npm-template /actions/workflows/codeql-analysis.yml )
6- ![ Node CI] ( https://github.com/shgysk8zer0/node-http /workflows/Node%20CI/badge.svg )
7- ![ Lint Code Base] ( https://github.com/shgysk8zer0/node-http /workflows/Lint%20Code%20Base/badge.svg )
5+ [ ![ CodeQL] ( https://github.com/AegisJSProject/trusted-types /actions/workflows/codeql-analysis.yml/badge.svg )] ( https://github.com/AegisJSProject/trusted-types /actions/workflows/codeql-analysis.yml )
6+ ![ Node CI] ( https://github.com/AegisJSProject/trusted-types /workflows/Node%20CI/badge.svg )
7+ ![ Lint Code Base] ( https://github.com/AegisJSProject/trusted-types /workflows/Lint%20Code%20Base/badge.svg )
88
9- [ ![ GitHub license] ( https://img.shields.io/github/license/shgysk8zer0/node-http .svg )] ( https://github.com/shgysk8zer0/node-http /blob/master/LICENSE )
10- [ ![ GitHub last commit] ( https://img.shields.io/github/last-commit/shgysk8zer0/node-http .svg )] ( https://github.com/shgysk8zer0/node-http /commits/master )
11- [ ![ GitHub release] ( https://img.shields.io/github/release/shgysk8zer0/node-http ?logo=github )] ( https://github.com/shgysk8zer0/node-http /releases )
9+ [ ![ GitHub license] ( https://img.shields.io/github/license/AegisJSProject/trusted-types .svg )] ( https://github.com/AegisJSProject/trusted-types /blob/master/LICENSE )
10+ [ ![ GitHub last commit] ( https://img.shields.io/github/last-commit/AegisJSProject/trusted-types .svg )] ( https://github.com/AegisJSProject/trusted-types /commits/master )
11+ [ ![ GitHub release] ( https://img.shields.io/github/release/AegisJSProject/trusted-types ?logo=github )] ( https://github.com/AegisJSProject/trusted-types /releases )
1212[ ![ GitHub Sponsors] ( https://img.shields.io/github/sponsors/shgysk8zer0?logo=github )] ( https://github.com/sponsors/shgysk8zer0 )
1313
14- [ ![ npm] ( https://img.shields.io/npm/v/@shgysk8zer0/npm-template )] ( https://www.npmjs.com/package/@shgysk8zer0/npm-template )
15- ![ node-current] ( https://img.shields.io/node/v/@shgysk8zer0/npm-template )
16- ![ npm bundle size gzipped] ( https://img.shields.io/bundlephobia/minzip/@shgysk8zer0/npm-template )
17- [ ![ npm] ( https://img.shields.io/npm/dw/@shgysk8zer0/npm-template ?logo=npm )] ( https://www.npmjs.com/package/@shgysk8zer0/npm-template )
14+ [ ![ npm] ( https://img.shields.io/npm/v/@aegisjsproject/trusted-types )] ( https://www.npmjs.com/package/@aegisjsproject/trusted-types )
15+ ![ node-current] ( https://img.shields.io/node/v/@aegisjsproject/trusted-types )
16+ ![ npm bundle size gzipped] ( https://img.shields.io/bundlephobia/minzip/@aegisjsproject/trusted-types )
17+ [ ![ npm] ( https://img.shields.io/npm/dw/@aegisjsproject/trusted-types ?logo=npm )] ( https://www.npmjs.com/package/@aegisjsproject/trusted-types )
1818
19- [ ![ GitHub followers] ( https://img.shields.io/github/followers/shgysk8zer0 .svg?style=social )] ( https://github.com/shgysk8zer0 )
20- ![ GitHub forks] ( https://img.shields.io/github/forks/shgysk8zer0/node-http .svg?style=social )
21- ![ GitHub stars] ( https://img.shields.io/github/stars/shgysk8zer0/node-http .svg?style=social )
19+ [ ![ GitHub followers] ( https://img.shields.io/github/followers/AegisJSProject .svg?style=social )] ( https://github.com/AegisJSProoject )
20+ ![ GitHub forks] ( https://img.shields.io/github/forks/AegisJSProject/trusted-types .svg?style=social )
21+ ![ GitHub stars] ( https://img.shields.io/github/stars/AegisJSProject/trusted-types .svg?style=social )
2222[ ![ Twitter Follow] ( https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social )] ( https://twitter.com/shgysk8zer0 )
2323
2424[ ![ Donate using Liberapay] ( https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay )] ( https://liberapay.com/shgysk8zer0/donate " Donate using Liberapay ")
@@ -27,3 +27,47 @@ A template repo for npm packages
2727- [ Code of Conduct] ( ./.github/CODE_OF_CONDUCT.md )
2828- [ Contributing] ( ./.github/CONTRIBUTING.md )
2929<!-- - [Security Policy](./.github/SECURITY.md) -->
30+
31+ ## [ Concepts and Usage] ( https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API#concepts_and_usage )
32+
33+ Client-side, or DOM-based, XSS attacks happen when data controlled by a user
34+ (such as that input into a form field) reaches a function that can execute that
35+ data. These functions are known as injection sinks. DOM-based XSS attacks happen
36+ when a user is able to write arbitrary JavaScript code and have it executed by one
37+ of these functions.
38+
39+ The Trusted Types API locks down risky injection sinks, requiring you to process
40+ the data before passing it to one of these functions. If you use a string, then
41+ the browser will throw a TypeError and prevent the use of the function.
42+
43+ Trusted Types works alongside [ Content-Security Policy] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP )
44+ with the [ ` trusted-types ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types )
45+ and [ ` require-trusted-types-for ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-trusted-types-for )
46+ directives.
47+
48+ ### [ Injection Sinks] ( https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API#injection_sinks )
49+
50+ The Trusted Types API locks down injection sinks that can act as a vector for DOM-XSS
51+ attacks. An injection sink is any Web API function that should only be called
52+ with trusted, validated or sanitized input. Examples of injection sinks include:
53+
54+ - Functions that insert HTML into the document such as Element.innerHTML, Element.outerHTML, or Document.write.
55+ - Functions that create a new same-origin Document with caller-controlled markup such as DOMParser.parseFromString.
56+ - Functions that execute code such as Global_Objects/eval.
57+ - Setters for Element attributes that accept a URL of code to load or execute.
58+
59+ Trusted Types will force you to process the data before passing it to any
60+ injection sink rather than use a string. This ensures that the data is trustworthy.
61+
62+ > [ !IMPORTANT]
63+ > Since the document cannot directly access HTTP headers, this polyfill requires
64+ > either ` <meta http-equiv="Content-Security-Policy"> ` or a ` data-trusted-policies `
65+ > attribute to be set on ` <html> ` .
66+
67+ The Trusted Types API gives web developers a way to lock down the insecure parts
68+ of the DOM API to prevent client-side Cross-site scripting (XSS) attacks.
69+
70+ ## Included Scripts/Modules
71+ - ** ` trusted-types ` ** : Polyfills the ` globalThis.trustedTypes ` object
72+ - ** ` harden ` ** : Overwrites "injection sink" property & attribute setters
73+ - ** ` bundle ` ** : Loads polyfill and conditionally "harden"s
0 commit comments