You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-22Lines changed: 40 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -285,7 +285,7 @@ For Bun, the permission model is currently discussed [here](https://github.com/o
285
285
286
286
#### Hardened JavaScript
287
287
288
-
Companies like MetaMask and Moddable uses https://www.npmjs.com/package/ses and https://github.com/LavaMoat/LavaMoat to enable runtime protections like prevent modifying JavaScript's primordials (Object, String, Number, Array, ...), and limit access to the platform API (window, document, XHR, etc) per-package. These mechanism are also suggested as TC39 proposals like https://github.com/tc39/proposal-compartments
288
+
Companies like MetaMask and Moddable uses https://www.npmjs.com/package/ses and https://github.com/LavaMoat/LavaMoat to enable runtime protections like prevent modifying JavaScript's primordials (Object, String, Number, Array, ...), and limit access to the platform API (window, document, XHR, etc) per-package. These mechanism are also suggested as TC39 proposals like https://github.com/tc39/proposal-compartments
289
289
290
290
> Watch [The Attacker is Inside: Javascript Supplychain Security and LavaMoat (~20mins, Nov 2022)](https://youtu.be/Z5Bz0DYga1k) to get a quick high level overview of how this works.
> An access token is a common way to authenticate to `npm` when using the API or the `npm` CLI.
348
+
> At the end of 2025, NPM announced the [sunset of Legacy Tokens](https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/) to improve security. [Granular Access Tokens](https://docs.npmjs.com/about-access-tokens#about-granular-access-tokens) will be the default going forward.
345
349
346
-
```sh
347
-
npm token create # for a read and publish token
348
-
npm token create --read-only # for a read-only token
349
-
npm token create --cidr=[list] # for a CIDR-restricted read and publish token
350
-
npm token create --read-only --cidr=[list] # for a CIDR-restricted read-only token
351
-
```
350
+
Currently, granular access tokens can only be created on the website: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website (support for creating granular access tokens via npm token CLI command will be added [in the future](https://github.com/orgs/community/discussions/179562)).
352
351
353
-
> [!IMPORTANT]
354
-
> Granular Access Tokens should be used instead of Legacy Tokens. Legacy tokens cannot be scoped and don't automatically expire. They're considered dangerous to use.
355
-
>
356
-
> - Restrict token to specific packages, scopes, and organizations
357
-
> - Set a token expiration date (e.g., annually)
358
-
> - Limit token access based on IP address ranges (CIDR notation)
359
-
> - Select between read-only or read and write access
360
-
> - Don't use the same token for multiple purposes
361
-
> - Descriptive token names
352
+
Here are some best practices when creating tokens:
353
+
354
+
- Descriptive token names
355
+
- Restrict token to specific packages, scopes, and organizations
356
+
- Set a token expiration date (e.g., annually)
357
+
- Limit token access based on IP address ranges (CIDR notation)
358
+
- Select between read-only or read and write access
359
+
- Don't use the same token for multiple purposes
362
360
363
361
### 9. Generate Provenance Statements
364
362
@@ -392,13 +390,14 @@ To publish without evoking the `npm publish` command, we can do one of the follo
392
390
393
391
#### Trusted Publishing
394
392
395
-
When using OpenID Connect (OIDC) auth, one can publish packages _without_ npm tokens, and get _automatic_ provenance. This is called **trusted publishing** and read the GitHub announcement here: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/ and https://docs.npmjs.com/trusted-publishers
393
+
> Use _trusted publishing_ over tokens whenever possible[^17]
396
394
397
-
> [!IMPORTANT]
398
-
>
399
-
> It is recommended to use trusted publishing instead of tokens[^17].
395
+
When using OpenID Connect (OIDC) auth, one can publish packages _without_ npm tokens, and get _automatic_ provenance. This is called **trusted publishing** and read the GitHub announcement here: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/
396
+
397
+
See https://docs.npmjs.com/trusted-publishers for instructions on how to configure trusted publishing.
400
398
401
399
Related tools:
400
+
402
401
-https://github.com/antfu/open-packages-on-npm (CLI to setup Trusted Publisher for monorepo packages)
403
402
-https://github.com/sxzz/userscripts/blob/main/src/npm-trusted-publisher.md (Userscript to fill the form for Trusted Publisher on npmjs.com)
404
403
@@ -533,6 +532,7 @@ https://securityscorecards.dev and https://github.com/ossf/scorecard
533
532
Free and open source automated tool that assesses a number of important heuristics ("checks") associated with software security and assigns each check a score of 0-10. Several risks mentioned in this repository are included as part of the checks: Pinned Dependencies, Token Permissions, Packaging, Signed Releases,...
534
533
535
534
Run the checks:
535
+
536
536
1. automatically on code you own using the [GitHub Action](https://github.com/marketplace/actions/ossf-scorecard-action)
537
537
2. manually on your (or somebody else’s) project via the [Command Line](https://github.com/ossf/scorecard#scorecard-command-line-interface)
538
538
@@ -565,21 +565,39 @@ In the JavaScript ecosystem, the OpenJS Foundation (https://openjsf.org) was fou
0 commit comments