Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

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

DeryFerd53eb96abb1c1
diff --git a/crates/host-core/src/tools/ignore_rules.rs b/crates/host-core/src/tools/ignore_rules.rs
index 09b549c7b..cdb651265 100644
--- a/crates/host-core/src/tools/ignore_rules.rs
+++ b/crates/host-core/src/tools/ignore_rules.rs
@@ -20,7 +20,8 @@ use std::path::{Path, PathBuf};
pub const WORKSPACE_IGNORE_FILE: &str = ".pi-desktopignore";
/// Exact file names on the security denylist (spec 15 §3).
-const SENSITIVE_FILE_NAMES: &[&str] = &["id_rsa", "id_ed25519", "credentials.json", ".env"];
+const SENSITIVE_FILE_NAMES: &[&str] =
+ &["id_rsa", "id_ed25519", "credentials.json", ".env", ".npmrc"];
/// File-name suffixes on the security denylist (spec 15 §3).
const SENSITIVE_SUFFIXES: &[&str] = &[".pem", ".key", ".p12", ".pfx"];
@@ -226,6 +227,7 @@ mod tests {
"bundle.p12",
"cert.pfx",
"credentials.json",
+ ".npmrc",
] {
assert!(is_sensitive_file_name(name), "{name} must be denied");
}
@@ -254,9 +256,11 @@ mod tests {
fn rg_args_keep_only_denylist_when_scoped() {
let scoped = rg_args(Path::new("/nonexistent"), true);
assert!(scoped.contains(&"!*.pem".to_string()));
+ assert!(scoped.contains(&"!.npmrc".to_string()));
assert!(!scoped.contains(&"!node_modules".to_string()));
let unscoped = rg_args(Path::new("/nonexistent"), false);
assert!(unscoped.contains(&"!node_modules".to_string()));
assert!(unscoped.contains(&"!*.log".to_string()));
+ assert!(unscoped.contains(&"!.npmrc".to_string()));
}
}
diff --git a/crates/host-core/src/tools/mod.rs b/crates/host-core/src/tools/mod.rs
index 954743e72..a29485d9e 100644
--- a/crates/host-core/src/tools/mod.rs
+++ b/crates/host-core/src/tools/mod.rs
@@ -4428,6 +4428,7 @@ mod tests {
std::fs::write(dir.path().join(".env"), "SECRET_TOKEN=needle\n").unwrap();
std::fs::write(dir.path().join(".env.example"), "SECRET_TOKEN=needle\n").unwrap();
std::fs::write(dir.path().join("server.pem"), "needle\n").unwrap();
+ std::fs::write(dir.path().join(".npmrc"), "//registry/:_authToken=needle\n").unwrap();
std::fs::write(dir.path().join("notes.txt"), "needle\n").unwrap();
let read = execute_tool(
@@ -4462,6 +4463,17 @@ mod tests {
Some("WORKSPACE_PATH_DENIED")
);
+ let npmrc = execute_tool(
+ Some(dir.path()),
+ None,
+ "Read",
+ &serde_json::json!({ "path": ".npmrc" }),
+ 5_000,
+ )
+ .await;
+ assert!(!npmrc.ok);
+ assert_eq!(npmrc.error_code.as_deref(), Some("WORKSPACE_PATH_DENIED"));
+
let example = execute_tool(
Some(dir.path()),
None,
@@ -4496,6 +4508,7 @@ mod tests {
assert!(shown.contains(".env.example"), "{shown}");
assert!(!shown.contains("\".env\""), "{shown}");
assert!(!shown.contains("server.pem"), "{shown}");
+ assert!(!shown.contains(".npmrc"), "{shown}");
let glob = execute_tool(
Some(dir.path()),
@@ -4509,6 +4522,7 @@ mod tests {
assert!(shown.contains("notes.txt"), "{shown}");
assert!(!shown.contains("server.pem"), "{shown}");
assert!(!shown.contains("\".env\""), "{shown}");
+ assert!(!shown.contains(".npmrc"), "{shown}");
}
#[tokio::test]
diff --git a/docs/spec/06-delivery/e2e/tools-and-workspace.md b/docs/spec/06-delivery/e2e/tools-and-workspace.md
index c8e45e402..324106caa 100644
--- a/docs/spec/06-delivery/e2e/tools-and-workspace.md
+++ b/docs/spec/06-delivery/e2e/tools-and-workspace.md
@@ -2188,10 +2188,10 @@ are withdrawn with ADR 0165.
## E2E-234: Workspace security denylist and ignore layers
- **Preconditions**: A project containing `.env`, `.env.example`,
- `server.pem`, `keys/id_rsa`, `notes.txt`, `node_modules/pkg/index.js`,
- `generated/out.txt`, `debug.log`, and a root `.pi-desktopignore` with
- `generated/`. Every file contains the word `needle`. The session is Agent
- in `auto` permission mode.
+ `server.pem`, `.npmrc`, `keys/id_rsa`, `notes.txt`,
+ `node_modules/pkg/index.js`, `generated/out.txt`, `debug.log`, and a root
+ `.pi-desktopignore` with `generated/`. Every file contains the word `needle`.
+ The session is Agent in `auto` permission mode.
- **Steps**: 1) Ask for `Read` of `.env`, then of `.env.example`. 2) Ask for
`Write` to `keys/id_rsa`. 3) Run an unscoped `Grep` and `Glob` for `needle`.
4) Run `Grep` with `path: node_modules/pkg` and with `path: generated`.
@@ -2200,9 +2200,9 @@ are withdrawn with ADR 0165.
- **Expected**: Steps 1 and 2 fail with `WORKSPACE_PATH_DENIED`, the
`.env.example` read succeeds, and no `keys/id_rsa` file is created. The
unscoped search lists `notes.txt` and `.env.example` only: `.env`,
- `server.pem`, `node_modules`, `generated`, and `debug.log` are absent. The
- explicit-path searches return one hit each. The in-process walker and the
- `rg` fast path produce the same file set.
+ `server.pem`, `.npmrc`, `node_modules`, `generated`, and `debug.log` are
+ absent. The explicit-path searches return one hit each. The in-process
+ walker and the `rg` fast path produce the same file set.
- **Specs linked**: `03-runtime/15-workspace-ignore-rules.md`,
`03-runtime/08-error-codes.md` §3.3, D032
- **Acceptance**: B (workspace tools), Security