Repository navigation
fix(tools): deny .npmrc in the workspace credential denylist - #2619
Conversation
Spec 15 section 3 lists `.npmrc` among the credential files the workspace security denylist must always deny, but the host-core name list only covered `.env`, `credentials.json`, and the key suffixes. Read, Write, Edit, Grep, and Glob all share this list, so the file was still reachable through every built-in tool path. Add `.npmrc` to the exact-name list, cover the name predicate and the rg argument path with regression tests, extend the workspace denylist tool test with a `.npmrc` fixture, and add the file to the E2E-234 scenario so the documented behaviour matches the unit-covered behaviour.
30276a7 to
53eb96a
Compare
There was a problem hiding this comment.
AIUO CodePilot · Preliminary review
Diff-only preliminary review: adding `.npmrc` to `SENSITIVE_FILE_NAMES` (and covering it in unit/E2E text) is consistent with the claimed spec alignment and the deny-by-name rule used for `.env`/`credentials.json`. The added host-core test assertions for Read/Grep/Glob appear coherent with the change. No evidenced defect found in the diff. Verification limits: no execution, build, test run, ripgrep equivalence check, or repository/spec inspection was performed; claims in the PR body (test counts, E2E NOT RUN, spec wording) are unverified.
No evidenced findings in the supplied diff.
Head: 53eb96a
Base: c2042ae
CI: no-statuses; mergeable: true.
Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.
vastsa
left a comment
There was a problem hiding this comment.
Independently verified against head 53eb96a and main c2042ae.
The defect is real: executing the baseline production filename/path predicates permits .npmrc; the candidate denies it. The existing workspace spec requires this credential protection. Adding the shared denylist entry reaches Read/Write/Edit, the walker, and rg without unrelated production changes.
Validation performed locally in an isolated candidate worktree:
- cargo build -p host-core --locked: PASS.
- cargo test -p host-core --locked security_denylist: 1 PASS; ignore_rules: 3 PASS.
- cargo fmt --all -- --check and git diff --check: PASS.
- cargo clippy -p host-core --all-targets --locked: success with two warnings in unchanged review.rs/transcripts.rs.
- Real compiled Host over stdio RPC with isolated data/workspace/session: Read/Write/Edit reject
.npmrcand.NPMRCwith WORKSPACE_PATH_DENIED and preserve contents;.env.examplestays readable; scoped/unscoped Grep and Glob omit credentials and retain notes.txt. Repeated with system rg enabled and with PI_DESKTOP_DISABLE_RG=1: PASS both.
Head contains current main. GitHub merge candidate and tested head have identical tree 74dfca280d768cfc10aea9eb567f4568796b4355. No hosted CI checks are reported; this is not a claim of green CI. Full crate suite and Electron journey were not run; the affected Host filesystem/RPC boundary was exercised directly. No contributor source changes were necessary.
Summary / 概要
The workspace security denylist is supposed to reject
.npmrcfiles.docs/spec/03-runtime/15-workspace-ignore-rules.mdsection 3 lists.npmrcwith the credential files that tools must never read, write, edit, or surface in a search, and the plugin SDK and devkit already refuse it. The host-core name list incrates/host-core/src/tools/ignore_rules.rsnever included it, soReadreturned the file,WriteandEditaccepted it, and unscopedGrepandGloblisted it. Every one of those paths funnels throughignore_rules::is_sensitive_path, which is why one missing entry covered all of them.A
.npmrcusually holds a registry auth token. With this change the built-in tools treat it like.envandcredentials.json: the file is denied by name, and the ripgrep fast path excludes it from the same constant, so the in-process walker and thergwalk return the same file set.Requirement link / 需求关联
No tracking issue exists for this fix, so there is no
ClosesorRefsline to add. The requirement is the checked-in spec:docs/spec/03-runtime/15-workspace-ignore-rules.mdsection 3 already lists.npmrcas a denied credential file. This change makes the implementation match it.What changed
crates/host-core/src/tools/ignore_rules.rs: added.npmrctoSENSITIVE_FILE_NAMES.configure_walkerandrg_argsboth derive from that list, so the walker and the ripgrep fast path stay aligned without extra wiring.crates/host-core/src/tools/ignore_rules.rs: extendeddenylist_matches_keys_env_and_credentialsandrg_args_keep_only_denylist_when_scopedwith.npmrc, for both the scoped and the unscoped argument sets.crates/host-core/src/tools/mod.rs: added a.npmrcfixture tosecurity_denylist_blocks_read_write_edit_and_hides_search_results, asserted thatReadfails withWORKSPACE_PATH_DENIED, and asserted that an unscopedGrepandGlobleave the file out of their results.docs/spec/06-delivery/e2e/tools-and-workspace.md: added.npmrcto the E2E-234 preconditions and to the expected absence list.Denial is by file name, which is stricter than the spec's "with tokens (best-effort)" wording. That matches how
.envandcredentials.jsonare already handled, and a.npmrcwithout a token is rare enough that a separate content probe would buy very little.Validation
cargo fmt --checkpasses.cargo test -p host-core --locked security_denylistpasses (1 test).cargo test -p host-core --locked ignore_rulespasses (3 tests).cargo clippy -p host-core --all-targetsreports nothing in the changed files. The crate has five pre-existing warnings elsewhere.node scripts/check-pr-base-main.mjspasses, andorigin/mainis an ancestor of the head.Full
cargo test -p host-core --lockedon this machine reports 1340 passed and 21 failed. All 21 are insession_worktrees,data_relocation,db::project_path_tests, andrpc, and they fail with CRLF versus LF mismatches such asleft: "base\r\n"againstright: "base\n". The same failures reproduce on an unmodifiedmaincheckout, and none touchignore_rulesor the tool paths changed here.E2E: E2E-234 (workspace security denylist and ignore layers) is
NOT RUNin this environment. The machine has nonode_modulesor Electron install. E2E-234's own status line records the Electron journey as deferred by the no-local-E2E policy while the Rust tool behaviour is unit-covered, so the unit tests above are the alternative evidence. The remaining risk is the unverified Electron journey, not the denylist logic itself.Notes
.env.example,.env.sample, and.env.templatestay readable, and.npmrcfollows the same name-based rule as the other credential files.