Skip to content

fix(tools): deny .npmrc in the workspace credential denylist - #2619

Merged
vastsa merged 1 commit into
vastsa:mainfrom
DeryFerd:fix/npmrc-workspace-denylist
Nov 26, 2026
Merged

vastsa merged 1 commit into
vastsa:mainfrom
DeryFerd:fix/npmrc-workspace-denylist

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 概要

The workspace security denylist is supposed to reject .npmrc files. docs/spec/03-runtime/15-workspace-ignore-rules.md section 3 lists .npmrc with 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 in crates/host-core/src/tools/ignore_rules.rs never included it, so Read returned the file, Write and Edit accepted it, and unscoped Grep and Glob listed it. Every one of those paths funnels through ignore_rules::is_sensitive_path, which is why one missing entry covered all of them.

A .npmrc usually holds a registry auth token. With this change the built-in tools treat it like .env and credentials.json: the file is denied by name, and the ripgrep fast path excludes it from the same constant, so the in-process walker and the rg walk return the same file set.

Requirement link / 需求关联

No tracking issue exists for this fix, so there is no Closes or Refs line to add. The requirement is the checked-in spec: docs/spec/03-runtime/15-workspace-ignore-rules.md section 3 already lists .npmrc as a denied credential file. This change makes the implementation match it.

What changed

  • crates/host-core/src/tools/ignore_rules.rs: added .npmrc to SENSITIVE_FILE_NAMES. configure_walker and rg_args both 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: extended denylist_matches_keys_env_and_credentials and rg_args_keep_only_denylist_when_scoped with .npmrc, for both the scoped and the unscoped argument sets.
  • crates/host-core/src/tools/mod.rs: added a .npmrc fixture to security_denylist_blocks_read_write_edit_and_hides_search_results, asserted that Read fails with WORKSPACE_PATH_DENIED, and asserted that an unscoped Grep and Glob leave the file out of their results.
  • docs/spec/06-delivery/e2e/tools-and-workspace.md: added .npmrc to 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 .env and credentials.json are already handled, and a .npmrc without a token is rare enough that a separate content probe would buy very little.

Validation

  • cargo fmt --check passes.
  • cargo test -p host-core --locked security_denylist passes (1 test).
  • cargo test -p host-core --locked ignore_rules passes (3 tests).
  • cargo clippy -p host-core --all-targets reports nothing in the changed files. The crate has five pre-existing warnings elsewhere.
  • node scripts/check-pr-base-main.mjs passes, and origin/main is an ancestor of the head.

Full cargo test -p host-core --locked on this machine reports 1340 passed and 21 failed. All 21 are in session_worktrees, data_relocation, db::project_path_tests, and rpc, and they fail with CRLF versus LF mismatches such as left: "base\r\n" against right: "base\n". The same failures reproduce on an unmodified main checkout, and none touch ignore_rules or the tool paths changed here.

E2E: E2E-234 (workspace security denylist and ignore layers) is NOT RUN in this environment. The machine has no node_modules or 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

  • The diff is three files: one constant, the unit tests that cover it, and the E2E scenario text. Production code changes by one array entry.
  • No behaviour change outside denylisted-path handling. .env.example, .env.sample, and .env.template stay readable, and .npmrc follows the same name-based rule as the other credential files.

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.
@DeryFerd
DeryFerd force-pushed the fix/npmrc-workspace-denylist branch from 30276a7 to 53eb96a Compare November 26, 2026 16:51

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .npmrc and .NPMRC with WORKSPACE_PATH_DENIED and preserve contents; .env.example stays 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants