Repository navigation
fix(dist-tag): support npm's web-based 2FA flow - #11998
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2026-05-14T09:04:00.133ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughAdds npm web-based 2FA support to ChangesWeb-based OTP support for dist-tag commands
Sequence DiagramsequenceDiagram
participant CLI
participant DistTagCmd as dist-tag command
participant WithOtp as withOtpHandling
participant RegistryOp as setDistTag/deleteDistTag
participant Npm as npm Registry
participant Browser as Browser web-auth
CLI->>DistTagCmd: invoke add/rm (opts, cliOtp)
DistTagCmd->>DistTagCmd: compute authType (web|legacy) and otp
DistTagCmd->>WithOtp: run operation with OTP context
WithOtp->>RegistryOp: call with authType and otp
RegistryOp->>Npm: PUT/DELETE with npm-auth-type and optional npm-otp
alt Npm responds 401 with authUrl/doneUrl or OTP challenge
Npm-->>RegistryOp: 401 + auth info
RegistryOp-->>WithOtp: throw SyntheticOtpError
WithOtp->>Browser: open authUrl and poll doneUrl
Browser-->>WithOtp: auth completed (done)
WithOtp->>RegistryOp: retry operation with obtained OTP
else success
Npm-->>RegistryOp: 2xx
RegistryOp-->>CLI: success
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Integrated-Benchmark Report (Linux)Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.1604119650399998,
"stddev": 0.180379683247681,
"median": 2.10819464054,
"user": 2.6379070199999997,
"system": 3.3754229199999997,
"min": 2.00903836254,
"max": 2.56435988054,
"times": [
2.16419551354,
2.0203801065399998,
2.13338925154,
2.02846215654,
2.00903836254,
2.08646148254,
2.39483290254,
2.56435988054,
2.07307219554,
2.12992779854
]
},
{
"command": "pacquet@main",
"mean": 2.04344071554,
"stddev": 0.039419805168550384,
"median": 2.0301689760399997,
"user": 2.6375878200000002,
"system": 3.3451206200000003,
"min": 2.00371086554,
"max": 2.10762061954,
"times": [
2.1064190315399998,
2.06737519254,
2.03290548654,
2.10762061954,
2.01689451054,
2.05607034254,
2.02743246554,
2.00665245654,
2.00371086554,
2.00932618454
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6568242944800001,
"stddev": 0.038787133011907324,
"median": 0.64677296888,
"user": 0.35218984,
"system": 1.3202504199999998,
"min": 0.6220996963800001,
"max": 0.76295299738,
"times": [
0.76295299738,
0.64589342738,
0.65357327838,
0.65895845338,
0.64310892538,
0.64765251038,
0.63863605438,
0.6220996963800001,
0.63856991038,
0.65679769138
]
},
{
"command": "pacquet@main",
"mean": 0.6652962310799999,
"stddev": 0.039483556692675094,
"median": 0.64486317538,
"user": 0.34071473999999996,
"system": 1.32085232,
"min": 0.63834576038,
"max": 0.74866362138,
"times": [
0.74866362138,
0.65065335638,
0.6406892333800001,
0.64202240838,
0.63834576038,
0.64660683138,
0.63935494238,
0.64311951938,
0.68150197938,
0.72200465838
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.2545386497599997,
"stddev": 0.0271237980603259,
"median": 2.25507923336,
"user": 3.7110421199999997,
"system": 3.0544915799999997,
"min": 2.20938126286,
"max": 2.29927830886,
"times": [
2.25625867286,
2.2756155758600003,
2.2825764418600003,
2.2289776308600002,
2.26126298386,
2.29927830886,
2.20938126286,
2.25389979386,
2.22986231286,
2.24827351386
]
},
{
"command": "pacquet@main",
"mean": 2.2783925786599997,
"stddev": 0.027680334678612122,
"median": 2.2823882168600003,
"user": 3.71959242,
"system": 3.06144538,
"min": 2.22230417386,
"max": 2.30958238986,
"times": [
2.24295934086,
2.30958238986,
2.3071384798600003,
2.27345562486,
2.27728702386,
2.22230417386,
2.28805356786,
2.28748940986,
2.30038815786,
2.27526761786
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.4078776357400002,
"stddev": 0.01889691285468865,
"median": 1.40345171774,
"user": 1.64338944,
"system": 1.7257114000000002,
"min": 1.3858516247400001,
"max": 1.4504265817400002,
"times": [
1.39583013874,
1.39712392574,
1.4221330037400002,
1.4028434627400002,
1.4078913157400001,
1.40405997274,
1.3920001647400002,
1.4206161667400001,
1.4504265817400002,
1.3858516247400001
]
},
{
"command": "pacquet@main",
"mean": 1.42569461614,
"stddev": 0.06450344552352857,
"median": 1.40885760924,
"user": 1.63541424,
"system": 1.7491349,
"min": 1.3733597617400002,
"max": 1.60276663274,
"times": [
1.4000375397400002,
1.4207474247400003,
1.4229069467400002,
1.3733597617400002,
1.60276663274,
1.4012505247400002,
1.4308237917400002,
1.38733832074,
1.4092356917400002,
1.40847952674
]
}
]
} |
|
| Branch | pr/11998 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 2,254.54 ms(-4.96%)Baseline: 2,372.19 ms | 2,846.63 ms (79.20%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,407.88 ms(-5.85%)Baseline: 1,495.42 ms | 1,794.51 ms (78.45%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 2,160.41 ms(+4.47%)Baseline: 2,068.00 ms | 2,481.60 ms (87.06%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 656.82 ms(-3.46%)Baseline: 680.35 ms | 816.43 ms (80.45%) |
Review Summary by QodoSupport npm's web-based 2FA flow for dist-tag operations WalkthroughsDescription• Support npm's web-based 2FA flow for dist-tag add/rm commands • Send npm-auth-type: web header and handle web auth challenges • Extract deleteDistTag function with OTP handling wrapper • Fix Accept header to only apply to GET/HEAD requests Diagramflowchart LR
A["dist-tag add/rm CLI"] -->|no --otp| B["Send npm-auth-type: web"]
A -->|with --otp| C["Send npm-auth-type: legacy + npm-otp"]
B -->|401 with authUrl| D["SyntheticOtpError"]
C -->|401 with authUrl| D
D -->|withOtpHandling| E["Open browser auth"]
E -->|Poll doneUrl| F["Get 64-char token"]
F -->|Retry with npm-otp| G["Success"]
H["Accept header cleanup"] -->|GET/HEAD only| I["Avoid 400 on writes"]
File Changes1. network/fetch/src/fetchFromRegistry.ts
|
Without `--otp`, `pnpm dist-tag add` (and `rm`) failed against npmjs.org with `[ERR_PNPM_UNAUTHORIZED] You must be logged in to set dist-tag … "You must provide a one-time pass. Upgrade your client to npm@latest in order to use 2FA."` — the browser never opened. The fallback "upgrade your client" message is what npmjs.org returns when the client doesn't announce `npm-auth-type: web`; without that header the server skips the web challenge and tells the user to install a newer npm. `--otp=<6-digit code>` already worked because the OTP went out in `npm-otp` directly. Send `npm-auth-type: web` on dist-tag writes when no `--otp` is given, surface 401 responses carrying `authUrl`/`doneUrl` (or the legacy "one-time pass" text) as `SyntheticOtpError`, and wrap the call in the existing `withOtpHandling` helper (already used by `pnpm publish`), which opens the browser, polls the done URL, and retries with the resulting token as `npm-otp` while keeping `npm-auth-type: web` in place. Drive-by cleanup in `@pnpm/network.fetch`: the abbreviated-metadata `Accept` header is no longer attached to non-GET requests, matching `npm-registry-fetch`'s behavior.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@registry-access/client/src/setDistTag.ts`:
- Around line 15-21: The code documents authType defaulting to 'web' but only
sends the npm-auth-type header when callers explicitly pass authType; update the
header construction in setDistTag (where headers are built for the request) to
treat undefined authType as 'web' and always send npm-auth-type:
<authTypeValue>, using the authType parameter (defaulting to 'web') so callers
relying on the exported default trigger the web OTP flow; ensure the same change
is applied to the other header-construction site mentioned (lines ~30-33).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: db58d3fd-ce81-4c91-9285-c04e35e868d9
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
.changeset/fix-dist-tag-web-otp.mdnetwork/fetch/src/fetchFromRegistry.tsnetwork/fetch/test/fetchFromRegistry.test.tsregistry-access/client/package.jsonregistry-access/client/src/setDistTag.tsregistry-access/client/tsconfig.jsonregistry-access/commands/package.jsonregistry-access/commands/src/distTag.tsregistry-access/commands/test/setDistTag.tsregistry-access/commands/tsconfig.json
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Follow Standard Style with trailing commas, preferring functions over classes, and declaring functions after they are used (relying on hoisting)
Use a single options object instead of multiple parameters when a function needs more than two or three arguments
Follow Import Order: Standard libraries first, then external dependencies (alphabetically), then relative imports
Write self-documenting code where function names, parameters, and types explain what a function does without requiring prose comments
Do not write comments that restate what the code already says; refactor via renaming, splitting helpers, or restructuring instead
Do not repeat documentation at call sites that already exists in JSDoc on the callee; update JSDoc once for all call sites to benefit
Use JSDoc only for a function's contract (preconditions, postconditions, edge cases, why the function exists), not for re-narrating the body
Do not record past implementation shape, refactor history, or 'the previous code did X' framing in code; use git log and git blame instead
Write comments only when: the reason for code is non-obvious (hidden invariant, workaround for known bug, deliberate exception), or the right name doesn't fit (temporary technical constraint)
Files:
network/fetch/test/fetchFromRegistry.test.tsregistry-access/commands/test/setDistTag.tsregistry-access/client/src/setDistTag.tsnetwork/fetch/src/fetchFromRegistry.tsregistry-access/commands/src/distTag.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use util.types.isNativeError() instead of instanceof Error for error type checking in Jest tests
Files:
network/fetch/test/fetchFromRegistry.test.ts
🧠 Learnings (3)
📚 Learning: 2026-05-26T21:01:06.666Z
Learnt from: zkochan
Repo: pnpm/pnpm PR: 11966
File: .changeset/require-tarball-integrity.md:6-6
Timestamp: 2026-05-26T21:01:06.666Z
Learning: In pnpm lockfile-related release notes/docs (especially changeset markdown), preserve URL hostnames exactly as they appear in pnpm-lock.yaml tarball resolution entries—keep hosts like `codeload.github.com`, `bitbucket.org`, and `gitlab.com` in lowercase. Do not “correct” them to title-case/preserve brand capitalization (e.g., LanguageTool rules like `GITHUB` capitalization) because these are literal URL fragments, not platform brand names.
Applied to files:
.changeset/fix-dist-tag-web-otp.md
📚 Learning: 2026-05-14T09:04:00.133Z
Learnt from: zkochan
Repo: pnpm/pnpm PR: 11622
File: resolving/npm-resolver/test/publishedBy.test.ts:350-354
Timestamp: 2026-05-14T09:04:00.133Z
Learning: In the pnpm/pnpm repository, ESLint is the authoritative style linter. Do not raise review findings for missing trailing commas in multiline function calls (e.g., `fs.writeFileSync(...)`) when this repo’s ESLint configuration does not report them and lint passes. Prefer deferring to the ESLint results for this specific trailing-comma rule rather than enforcing it manually in code review.
Applied to files:
network/fetch/test/fetchFromRegistry.test.tsregistry-access/commands/test/setDistTag.tsregistry-access/client/src/setDistTag.tsnetwork/fetch/src/fetchFromRegistry.tsregistry-access/commands/src/distTag.ts
📚 Learning: 2026-05-05T23:03:04.286Z
Learnt from: zkochan
Repo: pnpm/pnpm PR: 11479
File: __utils__/scripts/package.json:6-9
Timestamp: 2026-05-05T23:03:04.286Z
Learning: The pattern cross-env NODE_OPTIONS="$NODE_OPTIONS ..." in package.json scripts is an established convention in the pnpm/pnpm repository and is used across many packages (e.g., fs/hard-link-dir, worker, __utils__/scripts). Do not flag this as a cross-platform issue in individual files; if a change is needed, apply it as a repo-wide change in a separate PR. Scope this guidance to all package.json files in the repo; use the minimatch pattern '**/package.json' to identify relevant files and review changes at the repository level rather than per-file.
Applied to files:
registry-access/client/package.jsonregistry-access/commands/package.json
🔇 Additional comments (7)
.changeset/fix-dist-tag-web-otp.md (1)
1-11: LGTM!registry-access/client/package.json (1)
36-36: LGTM!registry-access/client/tsconfig.json (1)
17-20: LGTM!registry-access/commands/package.json (1)
41-42: LGTM!Also applies to: 47-47, 52-54, 57-57
registry-access/commands/tsconfig.json (1)
27-29: LGTM!Also applies to: 39-41
network/fetch/src/fetchFromRegistry.ts (1)
68-73: LGTM!Also applies to: 128-147
network/fetch/test/fetchFromRegistry.test.ts (1)
314-358: LGTM!
…TP context
Two review fixes:
- `setDistTag` documented `authType` as defaulting to `'web'` but only
sent the `npm-auth-type` header when the field was explicitly passed.
Always send the header, defaulting to `'web'`.
- `OTP_CONTEXT` used a module-level `createFetchFromRegistry({})`, so
the `withOtpHandling` doneUrl poll ignored the command's proxy / TLS
/ `configByUri` config. Build the OTP context per call from the
command's `opts` instead.
Also rename `toOtpOrUnauthorizedError` → `parseAuthError` and drop the
spurious `async` (the body string is already awaited at the call site).
Summary
pnpm dist-tag add(andrm) without--otpfails against npmjs.org with:The browser never opens — pnpm just surfaces the legacy 401 as
UNAUTHORIZEDand exits.pn dist-tag add … --otp=<6-digit code>already works; the gap is the interactive path that npm CLI handles via web 2FA. The "Upgrade your client" hint in the 401 body is the registry's polite way of saying "you didn't sendnpm-auth-type: web, so I'm falling back to the legacy challenge."What changed
@pnpm/registry-access.client#setDistTag: now sendsnpm-auth-type: web(matching npm CLI'sauth-typedefault) when no--otpis given, andnpm-auth-type: legacy+npm-otpwhen--otpis given. On 401, the body is parsed: a JSON shape withauthUrl/doneUrl, or a body matching/one-time pass/i, is converted to aSyntheticOtpError; anything else still throwsUNAUTHORIZED.@pnpm/registry-access.commands#distTag: wraps bothaddandrmin the existing@pnpm/network.web-auth#withOtpHandling(the same helper that backspnpm publish's web 2FA), so the EOTP-shaped error opens the browser, polls the done URL, and retries with the 64-char token asnpm-otp(withnpm-auth-type: webstill present, so the session is recognized).distTag.tswas extracted intodeleteDistTagand gets the same headers + OTP handling.@pnpm/network.fetchcleanup: the abbreviated-metadataAcceptheader (application/vnd.npm.install-v1+json; q=1.0, …) is only emitted on GET/HEAD now; sending it on writes is non-standard (npm-registry-fetch never does so) and was a distraction during debugging.Test plan
@pnpm/registry-access.commands).registry-access/commands/test/setDistTag.ts:npm-auth-type: webon the initial request when no OTPnpm-auth-type: weband addsnpm-otp(caught a real bug in an earlier iteration of the patch)--otpswitches toauthType: legacy{authUrl, doneUrl}body →SyntheticOtpError(body)SyntheticOtpError(undefined)UNAUTHORIZEDPnpmError@pnpm/network.fetchlock the Accept-header behavior (sent on GET, omitted on PUT).--otpthe browser opens, web auth completes, and the dist-tag is set.Notes / follow-ups
unpublish,owner add/rm,deprecate/undeprecate(inregistry-access/commands) have the same shape (inlinenpm-otpheader, nowithOtpHandling) and presumably break the same way for non---otpusers. Out of scope here but worth a follow-up.@pnpm/registry-access.clientasminorbecauseSetDistTagOptionsgained anauthTypefield; the rest ispatch.Draft because I'd like a sanity check on putting OTP plumbing at the command-handler layer (vs. inside
setDistTagitself). I went that way to keep@pnpm/registry-access.clientUI-free, mirroring howpublishWithOtpHandlinglives in@pnpm/releasing.commandsrather than inlibnpmpublish.Written by an agent (Claude Code, claude-opus-4-7).
Summary by CodeRabbit
pnpm dist-tag addandpnpm dist-tag rmnow surface registry OTP challenges in the browser flow; legacy--otp=<code>still works.