Repository navigation
fix(config): allow tokenHelper to be set in the global auth.ini - #12833
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds trusted ChangesTokenHelper authentication flow
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Config as NpmrcAuth
participant Headers as AuthHeaders
participant Registry as Registry request
participant Helper as TokenHelperRunner
Config->>Headers: build headers with trusted tokenHelper
Registry->>Headers: request credentials for registry URL
Headers->>Helper: execute helper lazily
Helper-->>Headers: token output or failure
Headers-->>Registry: Authorization header or no credential
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
PR Summary by QodoFix tokenHelper validation to trust global pnpm auth.ini
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an auth configuration regression in @pnpm/config.reader where a tokenHelper written by pnpm config set into the global pnpm auth.ini was incorrectly rejected as “project-level” configuration. It does so by validating tokenHelper against the merged trusted config sources rather than only ~/.npmrc, while keeping the project/workspace .npmrc guard in place.
Changes:
- Validate
tokenHelperpresence/value againstnpmrcResult.trustedConfig(includes globalauth.ini) instead ofnpmrcResult.userConfig. - Add tests covering: (1)
tokenHelperin globalauth.iniis accepted, and (2)tokenHelperin project.npmrcis still rejected. - Add a changeset for patch releases of
@pnpm/config.readerandpnpm.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pnpm11/config/reader/src/index.ts | Switch tokenHelper trust validation to use trustedConfig so global auth.ini is accepted while project config remains blocked. |
| pnpm11/config/reader/test/index.ts | Add coverage for the global auth.ini acceptance path and the project .npmrc rejection path. |
| .changeset/allow-tokenhelper-in-global-auth-ini.md | Document the fix and ship patch bumps for the affected packages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1. Pacquet tokenHelper laziness diverges
|
|
Code review by qodo was updated up to the latest commit 7710272 ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan |
|
Code review by qodo was updated up to the latest commit 7710272 |
|
Code review by qodo was updated up to the latest commit b6ab691 ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan |
1 similar comment
|
Code review by qodo was updated up to the latest commit b6ab691 ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan |
|
Code review by qodo was updated up to the latest commit b6ab691 |
The guard that blocks tokenHelper in a project .npmrc validated the value against ~/.npmrc only. A tokenHelper written to the global pnpm auth.ini, where `pnpm config set` stores it, was treated as project configuration and rejected on every command, and could not be removed with `pnpm config delete`. Validate against the trusted config, which includes the global auth.ini but still excludes workspace and project .npmrc files.
The comment said the env layer skips `//host/:tokenHelper` to avoid tripping the project-config guard, which validated against ~/.npmrc. That guard now validates against the trusted config, which already includes the env-scoped layer, so admitting the key here would instead pass the guard and let an env var run an arbitrary command. Describe that as the actual reason to drop it.
b6ab691 to
2d46611
Compare
Confidence Score: 5/5Safe to merge — the change is a single-source swap on the TypeScript side with well-reasoned trust semantics, fully mirrored in the Rust port, and tests cover global accept, project reject, reserved-character reject, and env-drop paths on both stacks. The trust-boundary logic is correct and matches across both stacks. The OnceLock-per-key pattern avoids holding the shared mutex across slow subprocess invocations, ChildGuard prevents process leaks, and pipe-draining threads prevent deadlocks. No logic defects were identified. No files require special attention. Reviews (6): Last reviewed commit: "fix(pacquet): kill an orphaned tokenHelp..." | Re-trigger Greptile |
|
Code review by qodo was updated up to the latest commit 2d46611 |
PR Code Suggestions ✨Latest suggestions up to 722a623 Warning
Previous suggestionsSuggestions up to commit 44a1473
Suggestions up to commit 833f27e
Suggestions up to commit 83a1156
Suggestions
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The comment described the trust rule as "user-level config" while the guard now validates against trustedConfig. Reword it to name the trusted, non-repo sources it actually checks (~/.npmrc and the global auth.ini) and to note that trustedConfig merges exactly those and excludes the repo sources. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Port pnpm's tokenHelper feature to pacquet, the counterpart of this PR's TypeScript-side guard fix. A tokenHelper configured in ~/.npmrc or the global auth.ini names a command pacquet runs to obtain a registry token; a tokenHelper in a workspace or project .npmrc, or supplied through a URL-scoped environment variable, is refused so a checked-in config cannot run an arbitrary command. Config layer: parse //host/:tokenHelper (scoped and default too) from trusted .npmrc/auth.ini sources only; validate reserved characters; and reject a project-contributed helper by comparing the full merge against the trusted-only merge (the analog of pnpm's trustedConfig), surfacing the same ERR_PNPM_TOKEN_HELPER_IN_PROJECT_CONFIG / _UNSUPPORTED_CHARACTER codes. Network layer: AuthHeaders carries the un-executed command per registry and runs it lazily on lookup, memoized so it runs at most once and never for a command that makes no matching request. Baked headers keep their eager, lock-free hot path. A header is emitted only on success; a failing helper logs and sends no credential, so pacquet never forwards a wrong, partial, or stale token. Because AuthHeaders::for_url is infallible, a helper failure surfaces as a loud error plus an unauthenticated request rather than pnpm's hard whole-command abort. Closes the tokenHelper items in pnpm/plans/TEST_PORTING.md. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit 833f27e |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pnpm/crates/network/src/token_helper.rs (1)
120-122: 🩺 Stability & Availability | 🔵 TrivialCaller in
auth.rsholds a mutex acrossrun_token_helper_command.The relevant context shows
auth.rslocksresolved_token_helpersbefore callingexecute_token_helperand holds it for the full 60-second timeout window. This serializes all concurrent auth lookups behind a single helper execution. The previous indefinite-hang concern was addressed by the timeout, but consider releasing the lock during helper execution (and handling potential thundering herd) if contention becomes an issue in practice.🤖 Prompt for 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. In `@pnpm/crates/network/src/token_helper.rs` around lines 120 - 122, Update the auth flow around execute_token_helper so the resolved_token_helpers mutex guard is not held while run_token_helper_command performs the potentially 60-second helper execution. Clone or otherwise extract the required helper configuration while locked, release the guard before execution, and preserve safe coordination for concurrent lookups if needed to avoid duplicate helper runs.
🤖 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 `@pnpm/crates/network/src/token_helper.rs`:
- Around line 139-143: Configure the child process builder in the token helper
spawn chain with kill-on-drop enabled before calling spawn, preserving the
existing stdin, stdout, and stderr configuration. This ensures the spawned
process is terminated if the Child is dropped before polling begins.
---
Nitpick comments:
In `@pnpm/crates/network/src/token_helper.rs`:
- Around line 120-122: Update the auth flow around execute_token_helper so the
resolved_token_helpers mutex guard is not held while run_token_helper_command
performs the potentially 60-second helper execution. Clone or otherwise extract
the required helper configuration while locked, release the guard before
execution, and preserve safe coordination for concurrent lookups if needed to
avoid duplicate helper runs.
🪄 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: 7919834a-e4c7-484e-b56b-3b2deb35f819
📒 Files selected for processing (7)
.changeset/pacquet-token-helper.md.changeset/token-helper-timeout.mdpnpm/crates/config/src/npmrc_auth.rspnpm/crates/network/src/token_helper.rspnpm/crates/network/src/token_helper/tests.rspnpm11/network/auth-header/src/getAuthHeadersFromConfig.tspnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- pnpm/crates/network/src/token_helper/tests.rs
- .changeset/pacquet-token-helper.md
- pnpm/crates/config/src/npmrc_auth.rs
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: Greptile Review
- GitHub Check: Analyze (javascript)
⚠️ CI failures not shown inline (5)
GitHub Actions: Pacquet Code Coverage / Code Coverage: fix(config): allow tokenHelper to be set in the global auth.ini
Conclusion: failure
##[group]Run bail() {
�[36;1mbail() {�[0m
�[36;1m printf '::error::install-action: %s\n' "$*"�[0m
GitHub Actions: Pacquet Code Coverage / Code Coverage: fix(config): allow tokenHelper to be set in the global auth.ini
Conclusion: failure
serde_core v1.0.228
Compiling memchr v2.8.0
Compiling serde v1.0.228
Compiling version_check v0.9.5
Compiling portable-atomic v1.13.1
Compiling bitflags v2.11.1
Compiling equivalent v1.0.2
Compiling syn v2.0.117
Compiling critical-section v1.2.0
Compiling itoa v1.0.18
Compiling foldhash v0.2.0
Compiling getrandom v0.2.17
Compiling once_cell v1.21.4
Compiling hashbrown v0.17.0
Compiling typenum v1.20.0
Compiling simd-adler32 v0.3.9
Compiling rand_core v0.6.4
Compiling zmij v1.0.21
Compiling shlex v1.3.0
Compiling jobserver v0.1.34
Compiling find-msvc-tools v0.1.9
Compiling adler2 v2.0.1
Compiling miniz_oxide v0.8.9
Compiling cc v1.2.60
Compiling rustix v1.1.4
Compiling indexmap v2.14.0
Compiling subtle v2.6.1
Compiling linux-raw-sys v0.12.1
Compiling generic-array v0.14.7
Compiling smallvec v1.15.1
Compiling serde_json v1.0.150
Compiling log v0.4.29
Compiling unicode-width v0.2.2
Compiling rand_core v0.10.1
Compiling getrandom v0.4.3
Compiling is_ci v1.2.0
Compiling is-terminal v0.4.17
Compiling owo-colors v4.3.0
Compiling supports-color v2.1.0
Compiling supports-color v3.0.2
Compiling object v0.37.3
Compiling gimli v0.32.3
Compiling pin-project-lite v0.2.17
Compiling rustc-demangle v0.1.27
Compiling unicode-width v0.1.14
Compiling unicode-linebreak v0.1.5
Compiling terminal_size v0.4.4
Compiling textwrap v0.16.2
Compiling supports-hyperlinks v3.2.0
Compiling supports-unicode v3.0.0
Compiling const-oid v0.9.6
Compiling unicode-segmentation v1.13.2
Compiling addr2line v0.25.1
Compiling unicode-xid v0.2.6
Compiling convert_case v0.10.0
Compiling tracing-core v0.1.36
Compiling serde_derive v1.0.228
Compiling zeroize_derive v1.4.3
Compiling miette-derive v7.6.0
Compiling derive_more-impl v2.1.1
Compiling zeroize v1.8.2
Compilin...
GitHub Actions: Pacquet Code Coverage / 1_Code Coverage.txt: fix(config): allow tokenHelper to be set in the global auth.ini
Conclusion: failure
##[group]Run bail() {
�[36;1mbail() {�[0m
�[36;1m printf '::error::install-action: %s\n' "$*"�[0m
GitHub Actions: Pacquet Code Coverage / Code Coverage: fix(config): allow tokenHelper to be set in the global auth.ini
Conclusion: failure
##[group]Run bail() {
�[36;1mbail() {�[0m
�[36;1m printf '::error::install-action: %s\n' "$*"�[0m
GitHub Actions: Pacquet Code Coverage / Code Coverage: fix(config): allow tokenHelper to be set in the global auth.ini
Conclusion: failure
##[group]Run bail() {
�[36;1mbail() {�[0m
�[36;1m printf '::error::install-action: %s\n' "$*"�[0m
🧰 Additional context used
📓 Path-based instructions (6)
.changeset/**/*.{md,mdx}
📄 CodeRabbit inference engine (AGENTS.md)
.changeset/**/*.{md,mdx}: For published TypeScript package changes, create a concise changeset in.changesetdescribing the user-facing change and affected packages.
Always explicitly includepnpmin a changeset with the appropriate patch, minor, or major bump when the CLI version should change.
Files:
.changeset/token-helper-timeout.md
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: For TypeScript changes, install dependencies and compile withpnpm installandpnpm run compile; compile specific packages withpnpm --filter <package_name> run compile.
Run tests for a specific TypeScript project, file, or test case rather than running all repository tests.
Run all TypeScript linting checks withpnpm run lint.
Use Standard Style with trailing commas for TypeScript code.
Prefer functions over classes in TypeScript.
Declare functions after they are used, relying on hoisting.
Limit functions to two or three arguments; use a single options object when more parameters are needed.
Order imports as standard libraries, alphabetized external dependencies, then relative imports.
ThrowPnpmErrorfrom@pnpm/errorfor user-reachable errors; use plainErrorfor programmer, type-guard, and unreachable-branch errors.
Never swallow errors; catch only the specific expected error code, throw on impossible states, and include contextual information such as offending paths in error messages.
Use verb names for functions, specific names for types and fields, existing terminology, and established file-naming conventions.
Prefer plain string operations for string parsing; use the existingobject/property-pathparser-combinator pattern when structured parsing with backtracking is required.
Route configurable values through@pnpm/configand command options rather than hardcoding them; command handlers should return data and let the CLI print it.
Prefer asynchronous filesystem APIs andasync/await; usePromise.allorPromise.anyfor independent work and hoist invariant work out of loops.
Files:
pnpm11/network/auth-header/src/getAuthHeadersFromConfig.tspnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
**/*.{ts,tsx,rs}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,rs}: Avoid comments that restate code, repeat callee documentation, describe past implementation history, or narrate the function body.
Write comments only for non-obvious rationale, hidden invariants, workarounds, deliberate exceptions, or temporary technical constraints; prefer renaming or restructuring first.
Files:
pnpm11/network/auth-header/src/getAuthHeadersFromConfig.tspnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.tspnpm/crates/network/src/token_helper.rs
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
When checking whether a caught error is an Error in Jest tests, use
util.types.isNativeError()instead ofinstanceof Error.
Files:
pnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
pnpm/**/*.rs
📄 CodeRabbit inference engine (pnpm/AGENTS.md)
pnpm/**/*.rs: Keep pacquet and the TypeScript pnpm CLI behaviorally identical, including commands, flags, defaults, errors, file formats, logs, layouts, and hooks.
When changing pacquet behavior, update the corresponding TypeScript pnpm workspace in the same PR, or document why the change cannot yet be matched.
Match observable behavior rather than mirroring the TypeScript implementation's structure.
Keep reporterpnpm:<channel>emissions identical between implementations, including call site, payload, and ordering.
Prefer real fixtures such astempfile::TempDir, the mocked registry, or integration tests; use dependency injection only for unreachable filesystem, time, process-global-state, or external-service branches.
Represent TypeScript branded strings with Rust newtype wrappers rather than plainStringor&str.
For branded strings that upstream always validates, construct them only through validatingTryFrom<String>and/orFromStr; do not expose an infallible arbitrary-string constructor.
For upstream brands that are never runtime-validated, expose infallibleFrom<String>and, when useful,From<&str>conversions.
When upstream sometimes bypasses validation, provide an explicitfrom_str_unchecked-style escape hatch while retaining the validating constructor.
Use serde#[serde(try_from = "String")]for validated deserialization and#[serde(into = "String")]for serialization of branded types crossing file-format boundaries.
Usederive_more::Fromandderive_more::Intofor mechanical branded-string conversions; write manual implementations only for validation or normalization logic.
Model TypeScript string-literal unions as Rust enums, not newtype wrappers.
Model TypeScript template-literal string types as branded Rust newtypes using the applicable validation and serde rules.
Use owned or borrowed parameters to minimize copies, widening parameters to types such as&Pathover&PathBufand&strover&Stringwhen possible.
Prefer `Ar...
Files:
pnpm/crates/network/src/token_helper.rs
pnpm/**/src/**/*.rs
📄 CodeRabbit inference engine (pnpm/AGENTS.md)
Keep tests alongside the code they exercise using standard Cargo layout; use crate
tests/directories for integration tests.
Files:
pnpm/crates/network/src/token_helper.rs
🧠 Learnings (7)
📚 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/token-helper-timeout.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:
pnpm11/network/auth-header/src/getAuthHeadersFromConfig.tspnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
📚 Learning: 2026-06-05T13:47:26.046Z
Learnt from: vsumner
Repo: pnpm/pnpm PR: 12190
File: installing/deps-installer/src/install/index.ts:2337-2343
Timestamp: 2026-06-05T13:47:26.046Z
Learning: In the pnpm/pnpm codebase, `PnpmError` automatically prefixes `err.code` with `ERR_PNPM_` when you pass a code that does not already start with `ERR_PNPM_` (it normalizes `this.code` via `code.startsWith('ERR_PNPM_') ? code : `ERR_PNPM_${code}``). Therefore, during code review you should NOT flag `new PnpmError(...)` call sites for passing a bare error code (e.g., `new PnpmError('FROZEN_STORE_INCOMPATIBLE_WITH_PNPR', ...)`); the resulting `err.code` will still be `ERR_PNPM_FROZEN_STORE_INCOMPATIBLE_WITH_PNPR`.
Applied to files:
pnpm11/network/auth-header/src/getAuthHeadersFromConfig.tspnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
📚 Learning: 2026-06-05T13:47:05.929Z
Learnt from: vsumner
Repo: pnpm/pnpm PR: 12190
File: installing/deps-installer/test/install/frozenStore.ts:2-17
Timestamp: 2026-06-05T13:47:05.929Z
Learning: In the pnpm/pnpm repository, the shared Jest preset keeps `injectGlobals` at its default (`true`), so `test` and `expect` are available as Jest globals. Therefore, reviewers should not flag (or treat as TypeScript/compilation errors) missing `import { test, expect } from 'jest/globals'` when a test file uses `test`/`expect` without importing them. Importing from `jest/globals` may still be used for consistency with sibling files, but it is not required for execution in this repo unless a Jest preset is explicitly configured with `injectGlobals: false`.
Applied to files:
pnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts
📚 Learning: 2026-06-06T18:58:37.156Z
Learnt from: zkochan
Repo: pnpm/pnpm PR: 12243
File: pacquet/crates/package-manager/src/install_package_by_snapshot.rs:319-322
Timestamp: 2026-06-06T18:58:37.156Z
Learning: When reviewing Rust code, do not assume `matches!(expr, Pattern(_))` will move out of `expr` if `Pattern(_)` contains no by-value bindings. `matches!` desugars to a `match` that auto-borrows the scrutinee for discrimination, so even if `expr` is a non-`Copy` value behind a shared reference (e.g., `&T`), the macro should not move-out of the borrowed data purely due to `matches!`. Treat `matches!(&expr, Pattern(_))` as a readability/clarity improvement, not a correctness requirement. Only flag potential move-out-of-borrow risks when the pattern includes by-value bindings that would require moving the matched value.
Applied to files:
pnpm/crates/network/src/token_helper.rs
📚 Learning: 2026-06-12T20:41:57.558Z
Learnt from: zkochan
Repo: pnpm/pnpm PR: 12364
File: pacquet/crates/package-manager/src/install/tests.rs:5717-5717
Timestamp: 2026-06-12T20:41:57.558Z
Learning: In the pnpm/pnpm Rust workspace (toolchain Rust 1.95.0), keep using `std::time::Duration::from_mins(...)` and `std::time::Duration::from_hours(...)` as-is. Do not flag these as invalid or suggest replacing them with `Duration::from_secs(...)`, because Clippy’s `clippy::duration_suboptimal_units` lint is denied by `-D warnings` in CI, and changing to seconds may trigger CI failures.
Applied to files:
pnpm/crates/network/src/token_helper.rs
📚 Learning: 2026-06-29T10:07:32.128Z
Learnt from: KSXGitHub
Repo: pnpm/pnpm PR: 12719
File: pacquet/crates/cli/tests/update.rs:56-56
Timestamp: 2026-06-29T10:07:32.128Z
Learning: When reviewing Rust code, do not flag `format!`, `write!`, or `writeln!` calls as having “missing format arguments” if the format string is a raw string literal (e.g., `r#"...{name}..."#`, `br#"...{spec}..."#`) that uses Rust’s captured-format-argument syntax (`{name}`, `{spec}`, etc.). Raw string literals still support captured-format placeholders, so the code is valid as long as those captured names correspond to in-scope variables and compiles.
Applied to files:
pnpm/crates/network/src/token_helper.rs
🪛 ast-grep (0.44.1)
pnpm11/network/auth-header/src/getAuthHeadersFromConfig.ts
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { spawnSync } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
🔇 Additional comments (4)
.changeset/token-helper-timeout.md (1)
1-7: LGTM!pnpm11/network/auth-header/src/getAuthHeadersFromConfig.ts (1)
77-92: LGTM!pnpm11/network/auth-header/test/getAuthHeadersFromConfig.test.ts (1)
6-6: LGTM!Also applies to: 88-93
pnpm/crates/network/src/token_helper.rs (1)
11-25: LGTM!Also applies to: 45-55, 58-79, 88-114, 175-184, 206-216
resolve_entry held the shared resolved-token-helpers Mutex for the entire duration of the helper subprocess, so a slow (up to the 60s timeout) or hung helper for one registry blocked every other registry's auth lookup that hit a tokenHelper entry. Key each cache slot by a per-key OnceLock instead: the shared Mutex is now held only briefly to fetch-or-insert the slot, and the subprocess runs while the Mutex is free. OnceLock still serializes concurrent first-lookups of the same key, so a helper runs at most once. A regression test asserts a second registry's lookup completes while a slow helper is still running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit 44a1473 |
…anic run_token_helper_command spawned the child and then created reader threads before the wait loop; a panic in between (a failed thread::spawn) would drop the Child without killing it, leaving an orphaned process. std has no `kill_on_drop`, so wrap the child in a ChildGuard that kills it on drop until it is disarmed once the process has been reaped (killing a reaped pid could hit a recycled process). This also subsumes the explicit kill on the timeout path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit 722a623 |
What
Allow a
tokenHelperconfigured in the global pnpmauth.inito be used, instead of rejecting it as project-level configuration.Closes #12759.
Why
The guard that blocks
tokenHelperfrom a project.npmrc(so a checked-in.npmrccan't run an arbitrary command) validated the helper againstuserConfig, which only contains~/.npmrc. Butpnpm config setwrites atokenHelperto the globalauth.ini, which flows intotrustedConfig, notuserConfig. As a result a legitimately configuredtokenHelperwas rejected on every command withERR_PNPM_TOKEN_HELPER_IN_PROJECT_CONFIG, andpnpm config deletefailed as well. The guard's own comment already says the helper may come from "~/.npmrcor global auth.ini".How
Validate against
trustedConfiginstead ofuserConfig.trustedConfigmerges the trusted sources (including~/.npmrcand the globalauth.ini) but excludes workspace and project.npmrcfiles, so the global helper is accepted while a project-level one is still rejected.Tests in
config/readercover both paths: atokenHelperin the globalauth.iniis honored, and atokenHelperin a project.npmrcstill throwsERR_PNPM_TOKEN_HELPER_IN_PROJECT_CONFIG.Pacquet parity
Pacquet had no
tokenHelpersupport at all, so this PR also ports the whole feature to the Rust stack (matching the cardinal rule that user-visible changes land in both stacks):pnpm/crates/config): parse//host/:tokenHelper(scoped and default forms too) from trusted.npmrc/auth.inisources only; reject a project/workspace helper via the same full-vs-trusted comparison used on the TypeScript side; and reject reserved characters — surfacing the sameERR_PNPM_TOKEN_HELPER_IN_PROJECT_CONFIG/ERR_PNPM_TOKEN_HELPER_UNSUPPORTED_CHARACTERcodes.pnpm/crates/network):AuthHeaderscarries the un-executed command per registry and runs it lazily on lookup, memoized (runs at most once, and never for a command that makes no matching request). Baked headers keep their eager, lock-free hot path; a header is emitted only on success, so a failing helper sends no credential.AuthHeaders::for_urlis infallible and there is no single network seam, a helper failure surfaces as a loud error plus an unauthenticated request rather than pnpm's hard whole-command abort.tokenHelperwhen it builds the auth-header lookup (so a helper for a registry never contacted still runs); pacquet runs each helper lazily on the first request to that registry (per-registry, memoized, and never on a command that makes no matching request). Both bound execution at 60s.Covered by new Rust unit + integration tests (parse, trust guard, reserved-char, env-drop, lazy execution / memoization, and an end-to-end
/bin/echorun).Pacquet port added by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
tokenHelperfrom the user’s global pnpmauth.iniis now trusted, while project/workspace.npmrctokenHelpervalues remain blocked.tokenHelperexecution is lazy and registry-scoped, rejects unsupported inputs, and now has a 60-second timeout.tokenHelpersupport for retrieving registry tokens on demand.