Skip to content

Commit 96275b8

Browse files
authored
Merge pull request #1 from AegisJSProject/release/1.0.0
Initial batch of code
2 parents d64637d + cfbfbf8 commit 96275b8

File tree

14 files changed

+2395
-356
lines changed

14 files changed

+2395
-356
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"no-prototype-builtins": 0
3232
},
3333
"globals": {
34-
"globalThis": "readonly"
34+
"globalThis": "readonly",
35+
"trustedTypes": "readonly"
3536
}
3637
}
3738

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules/
22
.github/
3+
test/
34
.editorconfig
45
.eslintignore
56
.eslintrc.json
@@ -14,6 +15,4 @@ importmap.yaml
1415
*.tgz
1516
*.log
1617
*.bak
17-
*.min.*
18-
*.map
1918
*.env

CHANGELOG.md

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
### Changed
10-
- Setup to transpile all `./*.js` to `./cjs/*.cjs` (except `*.config.js`)
11-
- Update `exports` and `main` accordingly
12-
13-
## [v1.1.1] - 2023-09-24
14-
15-
### Added
16-
- Add `unpkg` to `package.json`
17-
- Add badges in README
18-
19-
### Changed
20-
- Update `exports` to `package.json` to handle wider variety
21-
22-
### Fixed
23-
- Fix typo in `fix:js` script
24-
25-
### [v1.1.0] - 2023-07-03
26-
27-
### Changed
28-
- Update to node 20
29-
- Update npm publishing GH Action
30-
31-
## [v1.0.5] - 2023-07-02
32-
33-
### Added
34-
- Add `funding`
35-
36-
### Changed
37-
- Updated GitHub Actions workflows
38-
- Update versioning & lock-file scripts
39-
- Update `.npmignore` & `.gitignore`
40-
41-
## [v1.0.4] - 2023-06-08
42-
43-
### Added
44-
- Install `@shgysk8zer0/npm-utils`
45-
- Add `exports` to package config
46-
47-
### Removed
48-
- Uninstall `rollup`, `eslint`
49-
50-
### Changed
51-
- Use `getConfig()` from `@shgysk8zer0/js-utils/rollup` for rollup config
52-
53-
## [v1.0.3] - 2023-06-01
54-
55-
### Fixed
56-
- Revert to old Release Action, now with permissions & link to changelog
57-
58-
## [v1.0.2] - 2023-06-01
59-
60-
### Fixed
61-
- Fix `changelog-entry` to match `[$version]` instead of `$version`
62-
63-
## [v1.0.1] - 2023-05-31
64-
65-
### Fixed
66-
- Update GitHub Release workflow to use [Auto Release](https://github.com/marketplace/actions/auto-release)
67-
68-
## [v1.0.0] - 2023-05-31
9+
## [v1.0.0] - 2024-04-01
6910

7011
Initial Release

README.md

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
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

bundle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@aegisjsproject/trusted-types/trusted-types.js';
2+
import '@aegisjsproject/trusted-types/harden.js';

cjs/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)