Repository navigation
fix: harden npmGlobalRoot against a nameless home, rewritten npmrc keys and untrimmed env values - #403
Merged
Conversation
…keys, untrimmed env values, and the wasted npm spawn (#399) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…c keys and untrimmed env values, and skip the needless npm spawn (#399) - A home the OS can't name (a UID with no passwd entry) asks npm instead of throwing out of resolveQmdEntry. - A quoted npmrc key asks npm: npm's ini unquotes keys. - Env values are read as npm's loadEnv reads them: only "" skipped, nothing trimmed, so a padded or whitespace prefix asks npm. - A worked-out root without qmd is the answer: npm root -g would give the same root, so it is no longer spawned. - The npm-agrees test drops the npm_config_* that npm test exports. Both copies (lib/qmd.ts, qmd-mcp.mjs) carry each change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e 3 needs it, and the padding rule in exactPath (#399) /simplify findings: both npmrc filters share one check, a key that isn't a plain word asks npm (quotes, escapes and ${} alike); an env prefix answers even when the OS home lookup throws; the untrimmed-value rule lives in exactPath with its reason; globalQmdEntry reads computed ?? askNpm(); the new tests use rmTemp and a shared entry path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reading (#399) /two-axis-review findings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rrow the npmrc key check (#399) /code-review findings: a worked-out root models the npm beside this Node, and the npm on PATH can differ, so a miss there still asks npm (item 4 declined, 2026-10-14). The npm-agrees test now compares roots whenever one is worked out. Auth keys with % ~ + are plain again; only a key npm's ini would rewrite asks npm. Headers name every hand-kept function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orm (#399) Second /code-review findings: a key holding ; or # sets the part before it, so it asks npm; tests pin brackets, a backslash and inner whitespace too; the docs list every form; askNpmForRoot reads stdout the same way in both copies; the npm-agrees test says it is a detector. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #399. Hardens
npmGlobalRoot(#382) inlib/qmd.tsand its hand-kept twin inqmd-mcp.mjs. Every change lands in both copies, and the tests run each case against both.A home the OS can't name no longer crashes the lookup. With HOME unset,
os.homedir()throws for a UID with no passwd entry. The home is now looked up only at rule 3, the first rule that reads~/.npmrc, and a throwing lookup asks npm. So an env prefix still answers without one.npmrc keys that npm's ini would rewrite ask npm. In npm 10.9.2's bundled ini 5.0.0, read 2026-10-14,
unsafe()trims a key and unquotes it, JSON-decoding a double-quoted one, and a;or#cuts it. So these keys ask npm:${…};;,#, brackets, a backslash or inner whitespace.Auth keys (
//host/path/:_authToken, with%,~or+) still count as plain. This applies to the user npmrc, the Node-prefix npmrc and the builtin npmrc.Env values are read as npm reads them.
@npmcli/config'sloadEnvskips only""and doesn't trim. So a whitespace-onlynpm_config_*value is set, not unset, and a padded prefix asks npm, becauseexactPathrejects padded values. The old code trimmed them, which was wrong too.The "npm agrees" test drops the
npm_config_*thatnpm testexports, so rule 1 no longer just echoes npm back. It now compares roots whenever one is worked out, not only when qmd sits under it, so it catches a CI leg where the two differ.Item 4 is declined (dated note on the issue).
globalQmdEntryis now exported, with injectable parameters for the tests, and still asks npm when qmd isn't under the worked-out root. That root models the npm beside this Node, and PATH's npm can differ: a self-upgraded npm on Windows, or mixed installs (inferred). Skipping the spawn would then fall back to the shellqmd, which fails on stock Windows. The cost is the pre-Harden npmGlobalRoot: a throwing homedir(), quoted npmrc keys, whitespace env values, and a wasted npm spawn #399 one, paid only on a miss.Left open:
upgrade-plan.tskeeps its ownnpm root -gspawn.homedir()inqmd-mcp.mjs'srunAsMcp,qmd-ignore.tsandsession-start.tspredates perf: find a global qmd without spawning npm root -g where npm's prefix is certain #382. Thesession-start.tscall is inside a try, and the other two are on paths where qmd itself needs a home.Type
fix— bug fixChecklist
type: descriptionformatmainand passes with it: ae36045 adds the red tests ahead of the fix, intests/qmd.test.ts, run against both copies.cd .claude/scripts && npm test): left to CI. Locally: typecheck, andtests/qmd.test.tspasses 70/70 with nothing skipped.exactPath's padding rule and the npmrc key check each have a red test and a mutation (below).Review. Each line names the commits the review ran on.
/simplifyran on ae36045 and 6d74ef9. Its findings are 34cb05a:exactPath;rmTempand a shared entry path in the tests.Skipped: one module for both copies, because the
.mjscan't import the.ts./two-axis-reviewagainst main ran on ae36045 to 34cb05a. Its findings are e66c548: theaskNpmForRootname, and the dated npm source reading./code-review highran on ae36045 to e66c548. Its findings are 19ba87b:Skipped:
upgrade-plan.ts's spawn./code-review highran on 19ba87b, the commit after the first review. Its findings are 9341a54:;and#keys;askNpmForRootreading stdout the same way in both copies;Skipped, each per the ruling above:
9341a54 has not had a review of its own. Its mutations are below.
Mutation: 22 mutations, 11 in each copy, each caught by
tests/qmd.test.ts:%,~,+);;and#don't count (covers 9341a54);userconfigdoesn't count;🤖 Generated with Claude Code