Skip to content

Commit ea4243e

Browse files
committed
remove npm cli for legacy tokens
1 parent daa6ce2 commit ea4243e

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ For Bun, the permission model is currently discussed [here](https://github.com/o
285285

286286
#### Hardened JavaScript
287287

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
289289

290290
> 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.
291291
@@ -339,26 +339,24 @@ npm profile enable-2fa auth-and-writes
339339
340340
### 8. Create Tokens with Limited Access
341341

342+
> [!IMPORTANT]
343+
>
344+
> Prefer _trusted publishing_ over tokens if possible! See [the "trusted publishing" section below](#trusted-publishing) for more details.
345+
342346
https://docs.npmjs.com/about-access-tokens#about-granular-access-tokens
343347

344-
> 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.
345349
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)).
352351

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
362360

363361
### 9. Generate Provenance Statements
364362

@@ -392,13 +390,14 @@ To publish without evoking the `npm publish` command, we can do one of the follo
392390
393391
#### Trusted Publishing
394392

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]
396394
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.
400398

401399
Related tools:
400+
402401
- https://github.com/antfu/open-packages-on-npm (CLI to setup Trusted Publisher for monorepo packages)
403402
- https://github.com/sxzz/userscripts/blob/main/src/npm-trusted-publisher.md (Userscript to fill the form for Trusted Publisher on npmjs.com)
404403

@@ -533,6 +532,7 @@ https://securityscorecards.dev and https://github.com/ossf/scorecard
533532
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,...
534533

535534
Run the checks:
535+
536536
1. automatically on code you own using the [GitHub Action](https://github.com/marketplace/actions/ossf-scorecard-action)
537537
2. manually on your (or somebody else’s) project via the [Command Line](https://github.com/ossf/scorecard#scorecard-command-line-interface)
538538

@@ -565,21 +565,39 @@ In the JavaScript ecosystem, the OpenJS Foundation (https://openjsf.org) was fou
565565
- Ecosystem Funds: https://funds.ecosyste.ms
566566

567567
[^1]: https://www.aikido.dev/blog/npm-debug-and-chalk-packages-compromised
568+
568569
[^2]: https://socket.dev/blog/nx-packages-compromised
570+
569571
[^3]: https://socket.dev/blog/ongoing-supply-chain-attack-targets-crowdstrike-npm-packages
572+
570573
[^4]: https://www.reversinglabs.com/blog/malicious-npm-patch-delivers-reverse-shell
574+
571575
[^5]: https://socket.dev/blog/north-korean-apt-lazarus-targets-developers-with-malicious-npm-package
576+
572577
[^6]: https://socket.dev/blog/npm-registry-spam-john-wick
578+
573579
[^7]: https://github.com/duckdb/duckdb-node/security/advisories/GHSA-w62p-hx95-gf2c
580+
574581
[^8]: https://en.wikipedia.org/wiki/Npm_left-pad_incident
582+
575583
[^9]: https://socket.dev/blog/when-everything-becomes-too-much
584+
576585
[^10]: https://nodejs.org/en/learn/typescript/run-natively
586+
577587
[^11]: https://libraries.io/npm
588+
578589
[^12]: https://www.theregister.com/2016/03/29/npmgate_followup
590+
579591
[^13]: https://github.com/dominictarr/event-stream/issues/116
592+
580593
[^14]: https://en.wikipedia.org/wiki/XZ_Utils_backdoor
594+
581595
[^15]: https://openssf.org/blog/2024/04/15/open-source-security-openssf-and-openjs-foundations-issue-alert-for-social-engineering-takeovers-of-open-source-projects/
596+
582597
[^16]: https://xkcd.com/2347
583-
[^17]: https://github.blog/security/supply-chain-security/our-plan-for-a-more-secure-npm-supply-chain
598+
599+
[^17]: https://docs.npmjs.com/trusted-publishers#prefer-trusted-publishing-over-tokens
600+
584601
[^18]: https://stackoverflow.com/questions/54124033/deleting-package-lock-json-to-resolve-conflicts-quickly
602+
585603
[^19]: https://pnpm.io/git#merge-conflicts

0 commit comments

Comments
 (0)