dsh-perm-gate 5.5.5 → 5.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dsh.plugin.json +1 -1
- package/lib/cred-families.js +5 -1
- package/lib/evaluate.d.ts +2 -1
- package/lib/evaluate.js +23 -7
- package/lib/network-extract.d.ts +13 -0
- package/lib/network-extract.js +168 -0
- package/lib/preset-rules.d.ts +5 -3
- package/lib/preset-rules.js +44 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.5.7 (2026-11-22)
|
|
4
|
+
|
|
5
|
+
- **SSH 私钥变体覆盖(cc-safety-net `secret.variant.*` 对标)**:密钥被复制改名后(`id_rsa.bak`/`id_rsa-old`/`github_deploy_ed25519`)此前完全裸奔——现有 `*id_rsa` glob 不带尾星、裸点分名是段尾精确匹配。两层修复:① `cred-families.ts` ssh 家族补四个点分变体形状(`id_rsa.*`/`id_ed25519.*`/`id_ecdsa.*`/`id_dsa.*`,段首锚定,`myid_rsa.notes` 不吞),familyOfPath 命中 → P0 凭据写地板同步覆盖变体;② 预设表新增 2 行(表水位 v2→v3,新 id 不动旧行)——shell 读面 `secret.ssh-key-variants` 与文件工具读面 `cred.ssh-variants`,args 收 `*id_rsa*`/`*_rsa`/`*_ed25519`/`*_ecdsa` 宽底名 + 泛名 `credentials`/`*/credentials`。两行放在家族阶梯**之后**:规范形态保持家族 tag 与 rung 治理,只有阶梯漏掉的变体才落到新行;`cred.ssh-variants` 不受家族档位治理(readonly/readwrite 不静音它),误伤按行撤销。白名单对照(`docs/credentials-guide.md`、`config/credentials.json`、`credentials.yaml`)零命中。
|
|
6
|
+
|
|
7
|
+
## 5.5.6 (2026-11-22)
|
|
8
|
+
|
|
9
|
+
- **云元数据端点防护(cc-safety-net `network.cloud-metadata` 对标,双面闭环)**:`curl http://169.254.169.254/latest/meta-data/…` 这类一次请求即可取回实例 IAM/STS 凭据的调用,预执行面与代理面都被拦。预设表新增 4 行(`[deny-rule:network.cloud-metadata-ips/-domains/-ips-any/-domains-any]`,表水位 v1→v2 幂等补行):已知 HTTP 客户端/raw socket/解释器(curl/wget/nc/socat/python/node/ruby/perl/php 等 15 词)点名 8 个元数据端点(AWS/GCP/Azure ECS/阿里云,含 IPv6 形态)直接 deny;其余调用(echo、cat 等非客户端)点名端点降级 ask,误伤可逐条撤销。代理面(开网络代理时)对 attributed 流量按同一清单拦截,无需命令可见。预执行候选来自新纯模块 `src/network-extract.ts`——`decideRules` 像派生 commands/pathCands/urlCands 一样派生网络候选(commandText + url 系参数键;裸 IPv4、括号 IPv6、裸 hostname token;时间戳 `12:30:45` 不误报;候选按 host 去重、丰富形态优先,上限 16 条)。规则行只在自己的 network 子维度命中候选时才发起,普通 `curl https://registry.npmjs.org/…`、`git push origin main` 等日常动作零命中(白名单对照集全绿)。138 用例 + 15 提取器用例全绿;误伤申诉 = 设置卡把对应 `[deny-rule:network.cloud-metadata-*]` 行 `enabled:false` 或删除。
|
|
10
|
+
|
|
3
11
|
## 5.5.4
|
|
4
12
|
|
|
5
13
|
- i18n: add Portuguese (pt-BR) locale — runtime dictionary, package metadata and README/INSTALL/CHANGELOG mirrors.
|
package/dsh.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-perm-gate",
|
|
3
3
|
"name": "dsh-perm-gate",
|
|
4
|
-
"version": "5.5.
|
|
4
|
+
"version": "5.5.7",
|
|
5
5
|
"description": {
|
|
6
6
|
"en": "Deterministic-first, fail-closed permission gate for DeepSeek Harness 0.1.2+: a P0 hard-deny -> P1 precise session grant -> P2 static allow/deny rule chain -> P3 optional LLM classifier -> P4 ask pipeline over the tools/pre-execute waterfall, with a standalone CLI dry-run evaluator and an auditable decision log. Credential handling is a seven-family ladder (ssh/cloud/package/gitcreds/env/cli/db) with deny/ask/readonly/readwrite rungs kept in the rules document plus a paired write-exemption list; a protected-branch push switch keeps the P0 floor by default. It only vetoes with deny/ask and always delegates otherwise, and unknown or malformed rules fail loud instead of silently standing the gate down.",
|
|
7
7
|
"zh": "面向 DeepSeek Harness 0.1.2+ 的确定性优先、失败即拒的权限闸门:在 tools/pre-execute 瀑布上串起 P0 硬拒绝 → P1 精确会话授权 → P2 静态 allow/deny 规则链 → P3 可选 LLM 语义分类 → P4 ask,并附带独立 CLI 干跑评估器与可审计的决策日志。凭据处理为七族阶梯(ssh/cloud/package/gitcreds/env/cli/db)× deny/ask/readonly/readwrite 四档,档位存规则文档 + 成对写豁免清单;保护分支强推开关默认保留 P0 地板。只以 deny/ask 否决、其余一律放行,规则未知或非法时直接报错,绝不静默失效。",
|
package/lib/cred-families.js
CHANGED
|
@@ -28,7 +28,11 @@ export const CRED_FAMILY_IDS = ['ssh', 'cloud', 'package', 'gitcreds', 'env', 'c
|
|
|
28
28
|
* segment-tail fragment matched at any depth.
|
|
29
29
|
*/
|
|
30
30
|
export const CRED_FAMILIES = {
|
|
31
|
-
ssh:
|
|
31
|
+
// ssh: the dotted variants (id_rsa.bak / .old / .pem …) ride the cc-safety-net
|
|
32
|
+
// secret.variant.* shapes — keys get copied and renamed, and a backup of a
|
|
33
|
+
// private key is still a private key. Anchored at the segment start, so
|
|
34
|
+
// `myid_rsa.notes` stays unclaimed.
|
|
35
|
+
ssh: ['~/.ssh', 'id_rsa', 'id_ed25519', 'id_ecdsa', 'id_dsa', 'authorized_keys', 'id_rsa.*', 'id_ed25519.*', 'id_ecdsa.*', 'id_dsa.*'],
|
|
32
36
|
cloud: ['~/.aws', '~/.gcloud', '~/.config/gcloud', '~/.azure', '~/.azure/**', 'credentials.yaml', 'credentials.json'],
|
|
33
37
|
package: ['~/.npmrc', '.npmrc', '~/.pypirc', '~/.netrc', '.netrc', '.pypirc', '_netrc', '~/.pip/pip.conf'],
|
|
34
38
|
gitcreds: ['~/.git-credentials', '.git-credentials'],
|
package/lib/evaluate.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CompiledRuleEntry, type CompiledRuleset, type RuleAction } from './rule.js';
|
|
2
2
|
import { type SimpleCommand } from './shell.js';
|
|
3
|
+
import { type NetworkTargetLite } from './network-extract.js';
|
|
3
4
|
import type { ScanKeyPolicy } from './scan-text.js';
|
|
4
5
|
export interface ToolCallContext {
|
|
5
6
|
readonly tool: string;
|
|
@@ -67,6 +68,6 @@ export interface Decision {
|
|
|
67
68
|
*/
|
|
68
69
|
export declare const SHELL_TOOLS: Set<string>;
|
|
69
70
|
/** Whether one compiled rule matches the given call context. */
|
|
70
|
-
export declare function ruleMatches(rule: CompiledRuleEntry, ctx: ToolCallContext, commands: readonly SimpleCommand[], pathCands: readonly string[], urlCands: readonly string[]): boolean;
|
|
71
|
+
export declare function ruleMatches(rule: CompiledRuleEntry, ctx: ToolCallContext, commands: readonly SimpleCommand[], pathCands: readonly string[], urlCands: readonly string[], networkCands?: readonly NetworkTargetLite[]): boolean;
|
|
71
72
|
/** Compute the deterministic first-match decision (P2 chain). */
|
|
72
73
|
export declare function decideRules(ruleset: CompiledRuleset, ctx: ToolCallContext): Decision;
|
package/lib/evaluate.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { normalizeWorkspacePath } from './path.js';
|
|
7
7
|
import { extractPathCandidates, extractUrlCandidates, } from './rule.js';
|
|
8
8
|
import { commandArgv, decomposeShellCommand, isForceDeletion, isRecursiveDeletion } from './shell.js';
|
|
9
|
+
import { extractNetworkTargets } from './network-extract.js';
|
|
9
10
|
import { compileCidr, compilePortSpec, compileDomainPattern } from './compiler.js';
|
|
10
11
|
import { dispatchCommand } from './command-dispatcher.js';
|
|
11
12
|
import { SHELL_TOOLS as IMPORTED_SHELL_TOOLS, WRITE_TOOLS as IMPORTED_WRITE_TOOLS, executableCommandOf, } from './tool-names.js';
|
|
@@ -24,7 +25,7 @@ import { SHELL_TOOLS as IMPORTED_SHELL_TOOLS, WRITE_TOOLS as IMPORTED_WRITE_TOOL
|
|
|
24
25
|
*/
|
|
25
26
|
export const SHELL_TOOLS = IMPORTED_SHELL_TOOLS;
|
|
26
27
|
/** Whether one compiled rule matches the given call context. */
|
|
27
|
-
export function ruleMatches(rule, ctx, commands, pathCands, urlCands) {
|
|
28
|
+
export function ruleMatches(rule, ctx, commands, pathCands, urlCands, networkCands) {
|
|
28
29
|
if (!rule.enabled)
|
|
29
30
|
return false;
|
|
30
31
|
// tools dimension: any glob matches.
|
|
@@ -115,9 +116,16 @@ export function ruleMatches(rule, ctx, commands, pathCands, urlCands) {
|
|
|
115
116
|
if (!compiled.some((g) => g.test(pipelineText) || argvs.some((s) => g.test(s))))
|
|
116
117
|
return false;
|
|
117
118
|
}
|
|
118
|
-
// network dimension: all present sub-dimensions must match.
|
|
119
|
+
// network dimension: all present sub-dimensions must match. Pre-execution
|
|
120
|
+
// candidates (harvested from the call's own command text and url-ish args,
|
|
121
|
+
// see network-extract.ts) match when ANY of them satisfies every present
|
|
122
|
+
// sub-dimension — one URL naming a metadata endpoint is enough, a rule may
|
|
123
|
+
// not rely on the other URLs in the same command being benign. A hand-built
|
|
124
|
+
// context with a single explicit `network` target keeps its original shape.
|
|
119
125
|
if (rule.network !== undefined) {
|
|
120
|
-
|
|
126
|
+
const dim = rule.network;
|
|
127
|
+
const candidates = networkCands ?? (ctx.network !== undefined ? [ctx.network] : []);
|
|
128
|
+
if (!candidates.some((t) => matchNetworkOne(dim, t)))
|
|
121
129
|
return false;
|
|
122
130
|
}
|
|
123
131
|
// branch dimension: git semantics only; non-git commands satisfy no branch
|
|
@@ -221,9 +229,16 @@ export function decideRules(ruleset, ctx) {
|
|
|
221
229
|
const commands = shellText !== undefined ? decomposeSafe(shellText) : [];
|
|
222
230
|
const pathCands = extractPathCandidates(ctx.args);
|
|
223
231
|
const urlCands = extractUrlCandidates(ctx.args);
|
|
232
|
+
// Network candidates are derived like every other candidate family: from the
|
|
233
|
+
// call's own text and arguments, so hand-built contexts (tests, embedders)
|
|
234
|
+
// get the same treatment as runtime calls. An explicit single target, when
|
|
235
|
+
// the caller pins one (dry-run rules panel), is consulted first.
|
|
236
|
+
const networkCands = extractNetworkTargets(shellText, ctx.args);
|
|
237
|
+
if (ctx.network !== undefined)
|
|
238
|
+
networkCands.unshift(ctx.network);
|
|
224
239
|
const scan = (list, _action) => {
|
|
225
240
|
for (const rule of list) {
|
|
226
|
-
if (ruleMatches(rule, ctx, commands, pathCands, urlCands)) {
|
|
241
|
+
if (ruleMatches(rule, ctx, commands, pathCands, urlCands, networkCands)) {
|
|
227
242
|
return { action: rule.action, reason: rule.reason, ruleIndex: rule.index };
|
|
228
243
|
}
|
|
229
244
|
}
|
|
@@ -360,10 +375,11 @@ function matchWhen(when) {
|
|
|
360
375
|
return true;
|
|
361
376
|
}
|
|
362
377
|
/**
|
|
363
|
-
* Match the network dimension: all present sub-dimensions
|
|
364
|
-
* Within a sub-dimension, entries are OR.
|
|
378
|
+
* Match the network dimension against ONE target: all present sub-dimensions
|
|
379
|
+
* must match. Within a sub-dimension, entries are OR. Multi-candidate matching
|
|
380
|
+
* (any-of) happens at the call site, over the harvested candidates.
|
|
365
381
|
*/
|
|
366
|
-
function
|
|
382
|
+
function matchNetworkOne(network, ctx) {
|
|
367
383
|
if (ctx === undefined)
|
|
368
384
|
return false;
|
|
369
385
|
// domains
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** One extracted network candidate, shaped for `matchNetwork` in evaluate.ts. */
|
|
2
|
+
export interface NetworkTargetLite {
|
|
3
|
+
readonly domain?: string;
|
|
4
|
+
readonly ip?: string;
|
|
5
|
+
readonly port?: number;
|
|
6
|
+
readonly scheme?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Harvest network targets from a call's command text and arguments. The depth walk
|
|
10
|
+
* mirrors `extractUrlCandidates`; a url-key value without a scheme falls back to
|
|
11
|
+
* bare-host parsing (`{url: "169.254.169.254"}` from a raw-socket tool call).
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractNetworkTargets(commandText: string | undefined, args: Record<string, unknown> | undefined): NetworkTargetLite[];
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-execution network-target extraction for the rule layer's `network` dimension.
|
|
3
|
+
*
|
|
4
|
+
* The proxy layer (`network.ts`) sees real connections from attributed shell
|
|
5
|
+
* subprocesses; the rule layer sees only the tool call's own arguments. This module
|
|
6
|
+
* bridges the two: it harvests URL / IP-literal / hostname candidates with the same
|
|
7
|
+
* key lists and URL regex the args dimension uses (`rule.ts`), so a preset row with
|
|
8
|
+
* a `network:` dimension can fire BEFORE a shell command runs — the pre-execution
|
|
9
|
+
* half of the cloud-metadata guard (the proxy half needs no extractor).
|
|
10
|
+
*
|
|
11
|
+
* Extraction is deliberately generous and rule-agnostic: it fills candidates, and a
|
|
12
|
+
* rule only fires when its own `network` sub-dimensions match one of them (an ips
|
|
13
|
+
* list, domain globs, ports, schemes). Garbage candidates can never match a precise
|
|
14
|
+
* row — the row's own list is the gate. Pure — no I/O, no execution.
|
|
15
|
+
*/
|
|
16
|
+
import { isIpLiteral, parseUrlTarget } from './network.js';
|
|
17
|
+
/** The url-ish argument keys, mirroring `rule.ts` URL_CANDIDATE_KEYS. */
|
|
18
|
+
const URL_KEYS = ['url', 'urls', 'uri', 'endpoint', 'remote', 'repo', 'repository'];
|
|
19
|
+
/** The command-ish argument keys, mirroring `rule.ts` COMMAND_CANDIDATE_KEYS. */
|
|
20
|
+
const COMMAND_KEYS = ['command', 'cmd', 'script', 'command_line', 'commandLine'];
|
|
21
|
+
/**
|
|
22
|
+
* The URL shape scanned from free text. Unlike `rule.ts`'s args-dimension regex
|
|
23
|
+
* this one keeps `]` inside the match — a bracketed IPv6 host (`http://[fd00:ec2::254]/`)
|
|
24
|
+
* would otherwise be truncated mid-bracket and unparsable.
|
|
25
|
+
*/
|
|
26
|
+
const URL_RE = /https?:\/\/[^\s"'<>)(\\]+/g;
|
|
27
|
+
/** Bare IPv4 dotted quad (octet sanity is irrelevant — the rule's ips list gates). */
|
|
28
|
+
const IPV4_RE = /(?:\d{1,3}\.){3}\d{1,3}/g;
|
|
29
|
+
/**
|
|
30
|
+
* Bracketed IPv6 (`[fd00:ec2::254]`) — the URL parser's canonical form for a
|
|
31
|
+
* literal IPv6 host. Unbracketed IPv6 from free text goes through the token walk
|
|
32
|
+
* below with a stricter shape gate instead.
|
|
33
|
+
*/
|
|
34
|
+
const BRACKETED_V6_RE = /\[[0-9a-fA-F:.]+:[0-9a-fA-F:.]+\]/g;
|
|
35
|
+
/**
|
|
36
|
+
* Hostname-ish token: dotted with an alphabetic TLD. Broad by design — `app.ts`
|
|
37
|
+
* becomes a candidate and that is fine, because a rule only fires when its own
|
|
38
|
+
* domains globs match the candidate.
|
|
39
|
+
*/
|
|
40
|
+
const HOSTNAME_RE = /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;
|
|
41
|
+
/**
|
|
42
|
+
* A bare unbracketed IPv6 token must look unlike a timestamp or a port list:
|
|
43
|
+
* `12:30:45` (all-numeric, no empty group) is a wall clock; `fd00:ec2::254`
|
|
44
|
+
* carries a hex letter or an empty (`::`) group. This gate exists to keep
|
|
45
|
+
* candidate lists readable — a metadata row could never match a timestamp
|
|
46
|
+
* either way.
|
|
47
|
+
*/
|
|
48
|
+
function isPlausibleBareIpv6(token) {
|
|
49
|
+
if (!/^[0-9a-fA-F:]+$/.test(token) || !token.includes(':'))
|
|
50
|
+
return false;
|
|
51
|
+
const groups = token.split(':');
|
|
52
|
+
return groups.length >= 3 && (groups.some((g) => g === '') || groups.some((g) => /[a-f]/i.test(g)));
|
|
53
|
+
}
|
|
54
|
+
/** Hard cap so a pathological command cannot balloon the candidate list. */
|
|
55
|
+
const MAX_TARGETS = 16;
|
|
56
|
+
/** Tokens long beyond any hostname/IP shape are skipped outright. */
|
|
57
|
+
const MAX_TOKEN_LENGTH = 253;
|
|
58
|
+
/**
|
|
59
|
+
* Candidates dedupe by HOST: a bare `nc 169.254.169.254` harvest and a parsed
|
|
60
|
+
* `http://169.254.169.254/` URL are the same target, and the richer shape (port,
|
|
61
|
+
* scheme) wins so a rule with port/scheme sub-dimensions sees the full form.
|
|
62
|
+
*/
|
|
63
|
+
function hostKeyOf(t) {
|
|
64
|
+
return t.domain ?? t.ip ?? '';
|
|
65
|
+
}
|
|
66
|
+
function richnessOf(t) {
|
|
67
|
+
return (t.port !== undefined ? 2 : 0) + (t.scheme !== undefined ? 1 : 0);
|
|
68
|
+
}
|
|
69
|
+
function pushTarget(out, target) {
|
|
70
|
+
if (target === undefined)
|
|
71
|
+
return;
|
|
72
|
+
const key = hostKeyOf(target);
|
|
73
|
+
const existing = out.get(key);
|
|
74
|
+
if (existing === undefined) {
|
|
75
|
+
if (out.size < MAX_TARGETS)
|
|
76
|
+
out.set(key, target);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (richnessOf(target) > richnessOf(existing))
|
|
80
|
+
out.set(key, target);
|
|
81
|
+
}
|
|
82
|
+
/** A URL string → target; the host becomes `ip` for literals, `domain` otherwise. */
|
|
83
|
+
function targetFromUrl(raw) {
|
|
84
|
+
const parsed = parseUrlTarget(raw.trim());
|
|
85
|
+
if (parsed === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
// WHATWG URL keeps brackets on an IPv6 hostname (`[fd00:ec2::254]`) — strip
|
|
88
|
+
// them so the literal is recognized and dedupes against the bare form.
|
|
89
|
+
const host = parsed.host.replace(/^\[|\]$/g, '');
|
|
90
|
+
return isIpLiteral(host)
|
|
91
|
+
? { ip: host, port: parsed.port, scheme: parsed.scheme }
|
|
92
|
+
: { domain: host, port: parsed.port, scheme: parsed.scheme };
|
|
93
|
+
}
|
|
94
|
+
/** A bare host token → target (no scheme/port known). */
|
|
95
|
+
function targetFromHost(host) {
|
|
96
|
+
const h = host.toLowerCase();
|
|
97
|
+
if (h.length === 0 || h.length > MAX_TOKEN_LENGTH)
|
|
98
|
+
return undefined;
|
|
99
|
+
if (isIpLiteral(h)) {
|
|
100
|
+
// `isIpLiteral` also accepts `12:30:45`; only real IPv4 shapes and
|
|
101
|
+
// plausible IPv6 shapes deserve a candidate slot.
|
|
102
|
+
if (h.includes('.') || isPlausibleBareIpv6(h))
|
|
103
|
+
return { ip: h };
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return HOSTNAME_RE.test(h) ? { domain: h } : undefined;
|
|
107
|
+
}
|
|
108
|
+
function collectTextTargets(text, out) {
|
|
109
|
+
for (const m of text.matchAll(URL_RE))
|
|
110
|
+
pushTarget(out, targetFromUrl(m[0]));
|
|
111
|
+
for (const m of text.matchAll(IPV4_RE))
|
|
112
|
+
pushTarget(out, targetFromHost(m[0]));
|
|
113
|
+
for (const m of text.matchAll(BRACKETED_V6_RE))
|
|
114
|
+
pushTarget(out, targetFromHost(m[0].slice(1, -1)));
|
|
115
|
+
// Bare tokens: netcat-style raw-socket calls name their target without a
|
|
116
|
+
// scheme (`nc metadata.goog 80`, `nc fd00:ec2::254 80`). A token that still
|
|
117
|
+
// carries a scheme prefix (`urlopen('http://fd00:ec2::254/…')` inside a
|
|
118
|
+
// quoted interpreter argument — the URL parser rejects an unbracketed IPv6
|
|
119
|
+
// host) is cut down to its authority segment first.
|
|
120
|
+
for (const tok of text.split(/[\s"'`<>()\\;,|&]+/)) {
|
|
121
|
+
if (tok.length === 0)
|
|
122
|
+
continue;
|
|
123
|
+
let candidate = tok;
|
|
124
|
+
const schemeIdx = candidate.indexOf('://');
|
|
125
|
+
if (schemeIdx >= 0) {
|
|
126
|
+
candidate = candidate.slice(schemeIdx + 3);
|
|
127
|
+
const slash = candidate.indexOf('/');
|
|
128
|
+
if (slash >= 0)
|
|
129
|
+
candidate = candidate.slice(0, slash);
|
|
130
|
+
}
|
|
131
|
+
pushTarget(out, targetFromHost(candidate));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Harvest network targets from a call's command text and arguments. The depth walk
|
|
136
|
+
* mirrors `extractUrlCandidates`; a url-key value without a scheme falls back to
|
|
137
|
+
* bare-host parsing (`{url: "169.254.169.254"}` from a raw-socket tool call).
|
|
138
|
+
*/
|
|
139
|
+
export function extractNetworkTargets(commandText, args) {
|
|
140
|
+
const out = new Map();
|
|
141
|
+
if (typeof commandText === 'string' && commandText.length > 0)
|
|
142
|
+
collectTextTargets(commandText, out);
|
|
143
|
+
if (args !== undefined && typeof args === 'object') {
|
|
144
|
+
const walk = (node, depth) => {
|
|
145
|
+
if (depth > 8)
|
|
146
|
+
return;
|
|
147
|
+
if (Array.isArray(node)) {
|
|
148
|
+
for (const e of node)
|
|
149
|
+
walk(e, depth + 1);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (node === null || typeof node !== 'object')
|
|
153
|
+
return;
|
|
154
|
+
for (const [k, v] of Object.entries(node)) {
|
|
155
|
+
if (URL_KEYS.includes(k)) {
|
|
156
|
+
const values = typeof v === 'string' ? [v] : Array.isArray(v) ? v.filter((e) => typeof e === 'string') : [];
|
|
157
|
+
for (const raw of values)
|
|
158
|
+
pushTarget(out, targetFromUrl(raw) ?? targetFromHost(raw.trim()));
|
|
159
|
+
}
|
|
160
|
+
if (COMMAND_KEYS.includes(k) && typeof v === 'string')
|
|
161
|
+
collectTextTargets(v, out);
|
|
162
|
+
walk(v, depth + 1);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
walk(args, 0);
|
|
166
|
+
}
|
|
167
|
+
return [...out.values()];
|
|
168
|
+
}
|
package/lib/preset-rules.d.ts
CHANGED
|
@@ -33,9 +33,11 @@ import { type CredFamily } from './cred-families.js';
|
|
|
33
33
|
* Shipped version of the preset table. Activation backfills (idempotent, revocation-
|
|
34
34
|
* preserving) whenever the stored `presetRulesVersion` lags this number — bump it
|
|
35
35
|
* whenever `PRESET_RULES_YAML` gains entries that existing installs must receive
|
|
36
|
-
* (v1 added the seven `cred.*` family rows
|
|
36
|
+
* (v1 added the seven `cred.*` family rows; v2 added the four
|
|
37
|
+
* `network.cloud-metadata*` rows with the pre-execution extractor; v3 added the
|
|
38
|
+
* two ssh-key-variant rows and the dotted-variant shapes to the ssh family).
|
|
37
39
|
*/
|
|
38
|
-
export declare const PRESET_TABLE_VERSION =
|
|
40
|
+
export declare const PRESET_TABLE_VERSION = 3;
|
|
39
41
|
/** Tag prefix carried by every preset entry's reason; locates an entry for revocation. */
|
|
40
42
|
export declare const PRESET_RULE_MARKER = "[deny-rule:";
|
|
41
43
|
/** Extract the `[deny-rule:<id>]` tag from one reason string (undefined when untagged). */
|
|
@@ -48,7 +50,7 @@ export declare function presetRuleId(reason: unknown): string | undefined;
|
|
|
48
50
|
* the joined pipeline — see evaluate.ts), token co-occurrence NEVER through
|
|
49
51
|
* args (args is any-token OR).
|
|
50
52
|
*/
|
|
51
|
-
export declare const PRESET_RULES_YAML = "defaultAction: ask\n\ndeny:\n # \u2500\u2500 Git \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n - command: [git]\n argv: { pipeline: [\"git reset --hard*\", \"git reset *--hard*\"] }\n reason: \"[deny-rule:git.reset-hard] Hard reset discards uncommitted changes. Use git reset --soft/--mixed, or git stash first.\"\n - command: [git]\n argv: { pipeline: [\"git reset --merge*\", \"git reset --abort*\"] }\n reason: \"[deny-rule:git.reset-merge] Merge reset discards in-progress merge work. Stash first, then reset --soft/--mixed.\"\n - command: [git]\n argv: { pipeline: [\"git clean *-f*\", \"git clean *--force*\"] }\n reason: \"[deny-rule:git.clean-force] git clean permanently deletes untracked files. Dry-run first: git clean -nd.\"\n - command: [git]\n argv: { pipeline: [\"git push origin *--delete*\", \"git push * --delete *\", \"git push --delete*\"] }\n reason: \"[deny-rule:git.push-delete] Deleting remote refs is visible to collaborators and needs explicit consent.\"\n - command: [git]\n argv: { pipeline: [\"git push --mirror*\", \"git push * --mirror\"] }\n reason: \"[deny-rule:git.push-mirror] Mirror push force-updates and deletes remote refs wholesale.\"\n - command: [git]\n argv: { pipeline: [\"git branch -D*\", \"git branch * -D\", \"git branch *--force-delete*\"] }\n reason: \"[deny-rule:git.branch-force-delete] git branch -D drops unmerged commits. Prefer merged-safe git branch -d.\"\n - command: [git]\n argv: { pipeline: [\"git stash drop*\"] }\n reason: \"[deny-rule:git.stash-drop] Dropping a stash entry is unrecoverable after GC. Verify with git stash list.\"\n - command: [git]\n argv: { pipeline: [\"git stash clear*\"] }\n reason: \"[deny-rule:git.stash-clear] Clearing all stashes destroys every saved worktree state.\"\n - command: [git]\n argv: { pipeline: [\"git tag -d*\", \"git tag --delete*\"] }\n reason: \"[deny-rule:git.tag-delete] Tag deletion removes release anchors.\"\n - command: [git]\n argv: { pipeline: [\"git reflog delete*\", \"git reflog expire*\"] }\n reason: \"[deny-rule:git.reflog-delete] Reflog deletion removes the last recovery path for lost commits.\"\n - command: [git]\n argv: { pipeline: [\"git rebase --abort*\"] }\n reason: \"[deny-rule:git.rebase-abort] Aborting a rebase discards resolution work. Prefer --continue/--skip.\"\n - command: [git]\n argv: { pipeline: [\"git merge --abort*\"] }\n reason: \"[deny-rule:git.merge-abort] Aborting a merge discards conflict resolution.\"\n - command: [git]\n argv: { pipeline: [\"git rm -rf *\", \"git rm *-rf *\", \"git rm * -rf\", \"git rm -fr *\", \"git rm --force *\", \"git rm * --force\", \"git rm -f *\", \"git rm * -f\"] }\n reason: \"[deny-rule:git.rm-force] git rm -f deletes working-tree files even when modified. Stash them first.\"\n - command: [git]\n argv: { pipeline: [\"git checkout --force *\", \"git checkout * --force\", \"git checkout -f *\", \"git checkout * -f\", \"git checkout -f\", \"git checkout * --force *\"] }\n reason: \"[deny-rule:git.checkout-force] Forced checkout overwrites local changes. git stash, then checkout.\"\n - command: [git]\n argv: { pipeline: [\"git checkout -- *\"] }\n reason: \"[deny-rule:git.checkout-double-dash] Path restore from checkout discards local edits. Use git stash push -- <path>.\"\n - command: [git]\n argv: { pipeline: [\"git checkout * -- *\"] }\n reason: \"[deny-rule:git.checkout-ref-path] Checking out a ref with a path overwrites working-tree files. Stash the paths first.\"\n - command: [git]\n argv: { pipeline: [\"git checkout *--pathspec-from-file*\"] }\n reason: \"[deny-rule:git.checkout-pathspec-from-file] Bulk path restore from a file can silently overwrite edits. List the pathspec, stash, then restore.\"\n - command: [git]\n argv: { pipeline: [\"git switch *--discard-changes*\"] }\n reason: \"[deny-rule:git.switch-discard-changes] --discard-changes throws away edits. git stash first.\"\n - command: [git]\n argv: { pipeline: [\"git switch --force *\", \"git switch * --force\", \"git switch -f *\", \"git switch * -f\"] }\n reason: \"[deny-rule:git.switch-force] Forced switch overwrites local changes. git stash first.\"\n - command: [git]\n # git restore <bare path> (the plain unstaged discard) is NOT ported here:\n # any glob broad enough to catch it also catches the harmless\n # git restore --staged <path> (G6) \u2014 only the explicit discard forms are\n # denied, the bare-path case stays in the prompt layer.\n argv: { pipeline: [\"git restore --worktree *\", \"git restore * --worktree *\", \"git restore * --worktree\", \"git restore -W *\"] }\n reason: \"[deny-rule:git.restore-worktree] Worktree restore discards local edits. git stash push -- <path> first.\"\n - command: [git]\n argv: { pipeline: [\"git worktree remove --force *\", \"git worktree remove * --force\", \"git worktree remove -f *\", \"git worktree remove * -f\"] }\n reason: \"[deny-rule:git.worktree-remove-force] Forced worktree removal discards uncommitted work in that tree.\"\n - command: [git]\n args: [\"alias.*\"]\n reason: \"[deny-rule:git.alias-config] Command-line Git aliases run arbitrary shell and cannot be analyzed.\"\n # params matches the RAW command string: the env-assignment word lands as the\n # simple command's lowercased word, so a command:[git] dimension would never\n # see this form \u2014 match on params alone.\n - params: { command: [\"*GIT_SSH_COMMAND=*\", \"*git_ssh_command=*\", \"*GIT_SSH=*\", \"*git_ssh=*\"] }\n reason: \"[deny-rule:git.ssh-env] Git network ops with an SSH env override execute unanalyzable code.\"\n\n # \u2500\u2500 Filesystem \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n - command: [\"rm#recursive\", \"rm#force\"]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:rm.git-metadata] Removing Git metadata destroys history and the gate's audit anchors.\"\n - command: [find]\n argv: { pipeline: [\"find .git*\"] }\n reason: \"[deny-rule:find.delete-git-metadata] Selecting .git for deletion destroys repository state.\"\n - command: [find]\n argv: { pipeline: [\"find * -delete\"] }\n reason: \"[deny-rule:find.delete] find -delete removes everything selected. Enumerate with plain find first.\"\n - command: [find]\n argv: { pipeline: [\"find *-exec rm*\", \"find *-delete*\"] }\n reason: \"[deny-rule:find.exec-rm-recursive-force] find -exec rm removes the whole tree per match. Dry-run plain find, delete explicit paths.\"\n - command: [rsync]\n argv: { pipeline: [\"rsync * --delete*\", \"rsync --delete*\"] }\n reason: \"[deny-rule:rsync.delete] rsync --delete erases destination files absent from the source. Dry-run with rsync -n --delete first.\"\n - command: [dd]\n argv: { pipeline: [\"dd * of=/dev/sd*\", \"dd * of=/dev/nvme*\", \"dd * of=/dev/mmcblk*\"] }\n reason: \"[deny-rule:dd.device-write] dd writing to a block device destroys the disk.\"\n - command: [mkfs, mke2fs, newfs, \"mkfs.*\"]\n reason: \"[deny-rule:mkfs.device] Formatting a device erases it.\"\n - command: [diskutil, wipefs, sgdisk, parted]\n reason: \"[deny-rule:disk.erase] Disk erase/partition/wipe operations destroy data.\"\n - command: [shred]\n reason: \"[deny-rule:shred.target] shred irreversibly destroys files (even --help/--version reach it).\"\n - command: [cat, head, tail, dd]\n args: [\"*/dev/sd*\", \"*/dev/nvme*\", \"*/dev/disk*\", \"*/dev/mmcblk*\"]\n reason: \"[deny-rule:redirect.block-device] Redirect target resolving to a disk device path.\"\n\n # \u2500\u2500 PowerShell \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # Command words are lowercased by the decomposer \u2014 command dimensions must\n # carry the lowercased verb (Remove-Item \u2192 remove-item).\n - command: [\"remove-item#recursive\"]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:powershell.remove-item-git-metadata] Never target .git.\"\n - command: [powershell, pwsh]\n argv: { pipeline: [\"pwsh *Remove-Item*\", \"powershell *Remove-Item*\", \"pwsh *remove-item*\", \"powershell *remove-item*\"] }\n reason: \"[deny-rule:powershell.nested-recursive-delete-unread] A delete handed to pwsh/powershell in a non-literal form cannot be verified before it runs.\"\n - command: [\"remove-item#recursive\"]\n args: [\".\", \"./\"]\n reason: \"[deny-rule:powershell.remove-item-recursive-force-cwd-self] Deleting the current directory removes the project.\"\n - command: [\"remove-item#recursive\"]\n args: [\"../*\", \"..\\\\*\"]\n reason: \"[deny-rule:powershell.remove-item-recursive-force-outside-cwd] Deleting above the cwd escapes task scope.\"\n\n # \u2500\u2500 Command Prompt \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # (The cc escaped-quote-collapse rule cannot be expressed faithfully with\n # these globs \u2014 every cmd /c recursion is nested behind a second parser,\n # so its true target is undecidable: it moves to the ask section instead.)\n - command: [cmd, rmdir, del]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:cmd.recursive-delete-git-metadata] Never target .git.\"\n - command: [rmdir, del]\n args: [\".\", \"./\"]\n reason: \"[deny-rule:cmd.recursive-delete-cwd-self] Deleting the current directory removes the project.\"\n - command: [rmdir, del]\n args: [\"../*\", \"..\\\\*\"]\n reason: \"[deny-rule:cmd.recursive-delete-outside-cwd] Delete above cwd escapes task scope.\"\n\n # \u2500\u2500 Secret targets (write/delete deny; reads are the ask section below) \u2500\u2500\n - command: [\"rm#recursive\", \"remove-item#recursive\", rmdir, del]\n args: [\"*/.ssh\", \"*/.aws\", \"*/.gnupg\", \".ssh\", \".aws\"]\n reason: \"[deny-rule:secret.delete-credential-path] Deleting credential stores destroys keys you cannot regenerate.\"\n - command: [echo, \"set-content\", \"out-file\"]\n args: [\".env\", \".env.*\"]\n reason: \"[deny-rule:secret.write-overwrite-env] Overwriting .env destroys existing secrets. Edit specific lines.\"\n - command: [\"rm#recursive\", \"remove-item#recursive\", rmdir, del]\n args: [\"*/.git-credentials\", \".git-credentials\"]\n reason: \"[deny-rule:secret.delete-git-credentials] Deleting the git credential store breaks push/pull auth.\"\n\nask:\n # Force push: ask, not deny (revoked from cc's deny ruling 2026-10-13).\n - command: [git]\n argv: { pipeline: [\"git push *--force*\", \"git push *-f*\"] }\n reason: \"[deny-rule:git.push-force] Force push rewrites shared history. Prefer git push --force-with-lease.\"\n\n # cmd /c recursion hides the real target behind a second parser (and quoting):\n # undecidable \u2192 ask, where cc denied only the drive-root-collapse variant.\n - command: [cmd]\n argv: { pipeline: [\"cmd /c *rmdir /s*\", \"cmd /c *del /s*\"] }\n reason: \"[deny-rule:cmd.recursive-delete-nested] cmd /c recursion nests a second parser; the real target cannot be resolved. Run rmdir/del directly so the gate can see the target.\"\n\n # Dynamic targets: this gate's ruling is \"undecidable \u2192 ask\", not fail-closed deny.\n - command: [\"rm#recursive\", \"remove-item#recursive\"]\n args: [\"$*\"]\n reason: \"[deny-rule:rm.recursive-force-dynamic-target] Recursive delete of a substitution-assembled target \u2014 verify the variable yourself.\"\n # The wrapper word xargs is stripped by the decomposer, so pipeline patterns\n # never see it \u2014 match the raw command string through the params dimension.\n - params: { command: [\"*xargs rm*\", \"*xargs del*\"] }\n reason: \"[deny-rule:xargs.rm-recursive-force-dynamic] xargs-fed removals have unverifiable target sets.\"\n - command: [parallel]\n argv: { pipeline: [\"parallel *rm*\", \"*| parallel*\"] }\n reason: \"[deny-rule:parallel.rm-recursive-force-dynamic] parallel-fed rm has unresolvable targets.\"\n - command: [awk]\n args: [\"*system(*\"]\n reason: \"[deny-rule:awk.system-dynamic] awk program text containing system() cannot be analyzed.\"\n # NOTE: cc's git checkout <ref> <path> ambiguity (G5) is NOT ported \u2014 a glob\n # cannot tell ref candidates from paths, and a broad pattern would prompt on\n # every git checkout -b new-branch. Documented residual gap.\n\n # Credential reads: ask (A2 ruling kept; egress combos stay in the prompt layer).\n - command: [cat, head, tail, type, \"get-content\", ls, dir, \"get-childitem\", \"select-string\"]\n args: [\".env\", \".env.*\", \"*.env\", \".npmrc\", \".pypirc\", \".netrc\", \".git-credentials\", \"id_rsa\", \"id_ed25519\", \"id_ecdsa\"]\n reason: \"[deny-rule:secret.read-credential-file] Reading a credential file requires confirmation. Echo only the keys you need via a filtered command.\"\n - command: [cat, head, tail, type, \"get-content\", ls, dir, \"get-childitem\"]\n args: [\"*/.ssh\", \"*/.ssh/*\", \"*/.aws\", \"*/.aws/*\", \"*/.gnupg\", \"*/.gnupg/*\", \"*/.config/gcloud/*\", \"*/.claude/*\", \"*/.codex/*\"]\n reason: \"[deny-rule:secret.read-home-credential-dirs] Browsing ssh/cloud/coding-CLI credential stores requires confirmation.\"\n\n # \u2500\u2500 Credential family ladder (read side) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # One row per family, restricted to the file-READ tools: decide() pre-queries the\n # rule layer for READ calls, so these rows are what a read hits (shell reads stay\n # under the secret.* rows above, which match first in this section). The settings\n # face rewrites each row as the family's rung: deny - moved to the deny section;\n # ask - stays here; readonly/readwrite - enabled:false (readwrite additionally\n # lists the family in credWriteExemptFamilies for the engine's write clause).\n # Custom credentialPaths have no family and are never write-exempt.\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.ssh\", \"*/.ssh/*\", \"*id_rsa\", \"*id_ed25519\", \"*id_ecdsa\", \"*id_dsa\", \"*authorized_keys\"]\n reason: \"[deny-rule:cred.ssh] Reading SSH keys or authorized_keys needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.aws\", \"*/.aws/*\", \"*/.config/gcloud\", \"*/.config/gcloud/*\", \"*/.azure\", \"*/.azure/*\", \"*credentials.yaml\", \"*credentials.json\"]\n reason: \"[deny-rule:cred.cloud] Reading cloud-provider credential stores needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.npmrc\", \"*.npmrc\", \"*/.pypirc\", \"*/.netrc\", \"*_netrc\", \"*/pip.conf\"]\n reason: \"[deny-rule:cred.package] Reading package-registry auth files needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.git-credentials\", \"*.git-credentials\"]\n reason: \"[deny-rule:cred.gitcreds] Reading the git credential store needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.env\", \"*/.env.*\", \"*.env\"]\n reason: \"[deny-rule:cred.env] Reading project env files needs confirmation (family rung: ask; readwrite also lets edits, npm-login-style).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.claude\", \"*/.claude/*\", \"*/.codex\", \"*/.codex/*\", \"*/.config/gh\", \"*/.config/gh/*\"]\n reason: \"[deny-rule:cred.cli] Reading coding-CLI credential stores needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.pgpass\", \"*pgpass\", \"*/.my.cnf\"]\n reason: \"[deny-rule:cred.db] Reading database credential files needs confirmation (family rung: ask).\"\n\n # Self-protection: editing the gate's own rule sources needs confirmation \u2014\n # revocation must be a human act, not something an agent can slide through.\n # (Settings-namespace edits go through the host UI, not a tool call, and are\n # out of reach of this entry; documented gap.)\n - args: [\"*rules.yml\", \"*rules.yaml\", \"*deny-defaults*\"]\n reason: \"[deny-rule:gate.self-protection] This call touches the permission gate's own rule sources; changes here alter what the gate enforces.\"\n";
|
|
53
|
+
export declare const PRESET_RULES_YAML = "defaultAction: ask\n\ndeny:\n # \u2500\u2500 Git \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n - command: [git]\n argv: { pipeline: [\"git reset --hard*\", \"git reset *--hard*\"] }\n reason: \"[deny-rule:git.reset-hard] Hard reset discards uncommitted changes. Use git reset --soft/--mixed, or git stash first.\"\n - command: [git]\n argv: { pipeline: [\"git reset --merge*\", \"git reset --abort*\"] }\n reason: \"[deny-rule:git.reset-merge] Merge reset discards in-progress merge work. Stash first, then reset --soft/--mixed.\"\n - command: [git]\n argv: { pipeline: [\"git clean *-f*\", \"git clean *--force*\"] }\n reason: \"[deny-rule:git.clean-force] git clean permanently deletes untracked files. Dry-run first: git clean -nd.\"\n - command: [git]\n argv: { pipeline: [\"git push origin *--delete*\", \"git push * --delete *\", \"git push --delete*\"] }\n reason: \"[deny-rule:git.push-delete] Deleting remote refs is visible to collaborators and needs explicit consent.\"\n - command: [git]\n argv: { pipeline: [\"git push --mirror*\", \"git push * --mirror\"] }\n reason: \"[deny-rule:git.push-mirror] Mirror push force-updates and deletes remote refs wholesale.\"\n - command: [git]\n argv: { pipeline: [\"git branch -D*\", \"git branch * -D\", \"git branch *--force-delete*\"] }\n reason: \"[deny-rule:git.branch-force-delete] git branch -D drops unmerged commits. Prefer merged-safe git branch -d.\"\n - command: [git]\n argv: { pipeline: [\"git stash drop*\"] }\n reason: \"[deny-rule:git.stash-drop] Dropping a stash entry is unrecoverable after GC. Verify with git stash list.\"\n - command: [git]\n argv: { pipeline: [\"git stash clear*\"] }\n reason: \"[deny-rule:git.stash-clear] Clearing all stashes destroys every saved worktree state.\"\n - command: [git]\n argv: { pipeline: [\"git tag -d*\", \"git tag --delete*\"] }\n reason: \"[deny-rule:git.tag-delete] Tag deletion removes release anchors.\"\n - command: [git]\n argv: { pipeline: [\"git reflog delete*\", \"git reflog expire*\"] }\n reason: \"[deny-rule:git.reflog-delete] Reflog deletion removes the last recovery path for lost commits.\"\n - command: [git]\n argv: { pipeline: [\"git rebase --abort*\"] }\n reason: \"[deny-rule:git.rebase-abort] Aborting a rebase discards resolution work. Prefer --continue/--skip.\"\n - command: [git]\n argv: { pipeline: [\"git merge --abort*\"] }\n reason: \"[deny-rule:git.merge-abort] Aborting a merge discards conflict resolution.\"\n - command: [git]\n argv: { pipeline: [\"git rm -rf *\", \"git rm *-rf *\", \"git rm * -rf\", \"git rm -fr *\", \"git rm --force *\", \"git rm * --force\", \"git rm -f *\", \"git rm * -f\"] }\n reason: \"[deny-rule:git.rm-force] git rm -f deletes working-tree files even when modified. Stash them first.\"\n - command: [git]\n argv: { pipeline: [\"git checkout --force *\", \"git checkout * --force\", \"git checkout -f *\", \"git checkout * -f\", \"git checkout -f\", \"git checkout * --force *\"] }\n reason: \"[deny-rule:git.checkout-force] Forced checkout overwrites local changes. git stash, then checkout.\"\n - command: [git]\n argv: { pipeline: [\"git checkout -- *\"] }\n reason: \"[deny-rule:git.checkout-double-dash] Path restore from checkout discards local edits. Use git stash push -- <path>.\"\n - command: [git]\n argv: { pipeline: [\"git checkout * -- *\"] }\n reason: \"[deny-rule:git.checkout-ref-path] Checking out a ref with a path overwrites working-tree files. Stash the paths first.\"\n - command: [git]\n argv: { pipeline: [\"git checkout *--pathspec-from-file*\"] }\n reason: \"[deny-rule:git.checkout-pathspec-from-file] Bulk path restore from a file can silently overwrite edits. List the pathspec, stash, then restore.\"\n - command: [git]\n argv: { pipeline: [\"git switch *--discard-changes*\"] }\n reason: \"[deny-rule:git.switch-discard-changes] --discard-changes throws away edits. git stash first.\"\n - command: [git]\n argv: { pipeline: [\"git switch --force *\", \"git switch * --force\", \"git switch -f *\", \"git switch * -f\"] }\n reason: \"[deny-rule:git.switch-force] Forced switch overwrites local changes. git stash first.\"\n - command: [git]\n # git restore <bare path> (the plain unstaged discard) is NOT ported here:\n # any glob broad enough to catch it also catches the harmless\n # git restore --staged <path> (G6) \u2014 only the explicit discard forms are\n # denied, the bare-path case stays in the prompt layer.\n argv: { pipeline: [\"git restore --worktree *\", \"git restore * --worktree *\", \"git restore * --worktree\", \"git restore -W *\"] }\n reason: \"[deny-rule:git.restore-worktree] Worktree restore discards local edits. git stash push -- <path> first.\"\n - command: [git]\n argv: { pipeline: [\"git worktree remove --force *\", \"git worktree remove * --force\", \"git worktree remove -f *\", \"git worktree remove * -f\"] }\n reason: \"[deny-rule:git.worktree-remove-force] Forced worktree removal discards uncommitted work in that tree.\"\n - command: [git]\n args: [\"alias.*\"]\n reason: \"[deny-rule:git.alias-config] Command-line Git aliases run arbitrary shell and cannot be analyzed.\"\n # params matches the RAW command string: the env-assignment word lands as the\n # simple command's lowercased word, so a command:[git] dimension would never\n # see this form \u2014 match on params alone.\n - params: { command: [\"*GIT_SSH_COMMAND=*\", \"*git_ssh_command=*\", \"*GIT_SSH=*\", \"*git_ssh=*\"] }\n reason: \"[deny-rule:git.ssh-env] Git network ops with an SSH env override execute unanalyzable code.\"\n\n # \u2500\u2500 Filesystem \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n - command: [\"rm#recursive\", \"rm#force\"]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:rm.git-metadata] Removing Git metadata destroys history and the gate's audit anchors.\"\n - command: [find]\n argv: { pipeline: [\"find .git*\"] }\n reason: \"[deny-rule:find.delete-git-metadata] Selecting .git for deletion destroys repository state.\"\n - command: [find]\n argv: { pipeline: [\"find * -delete\"] }\n reason: \"[deny-rule:find.delete] find -delete removes everything selected. Enumerate with plain find first.\"\n - command: [find]\n argv: { pipeline: [\"find *-exec rm*\", \"find *-delete*\"] }\n reason: \"[deny-rule:find.exec-rm-recursive-force] find -exec rm removes the whole tree per match. Dry-run plain find, delete explicit paths.\"\n - command: [rsync]\n argv: { pipeline: [\"rsync * --delete*\", \"rsync --delete*\"] }\n reason: \"[deny-rule:rsync.delete] rsync --delete erases destination files absent from the source. Dry-run with rsync -n --delete first.\"\n - command: [dd]\n argv: { pipeline: [\"dd * of=/dev/sd*\", \"dd * of=/dev/nvme*\", \"dd * of=/dev/mmcblk*\"] }\n reason: \"[deny-rule:dd.device-write] dd writing to a block device destroys the disk.\"\n - command: [mkfs, mke2fs, newfs, \"mkfs.*\"]\n reason: \"[deny-rule:mkfs.device] Formatting a device erases it.\"\n - command: [diskutil, wipefs, sgdisk, parted]\n reason: \"[deny-rule:disk.erase] Disk erase/partition/wipe operations destroy data.\"\n - command: [shred]\n reason: \"[deny-rule:shred.target] shred irreversibly destroys files (even --help/--version reach it).\"\n - command: [cat, head, tail, dd]\n args: [\"*/dev/sd*\", \"*/dev/nvme*\", \"*/dev/disk*\", \"*/dev/mmcblk*\"]\n reason: \"[deny-rule:redirect.block-device] Redirect target resolving to a disk device path.\"\n\n # \u2500\u2500 Network \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # Cloud metadata endpoints (cc-safety-net network.cloud-metadata): one request\n # returns the instance's IAM/STS credentials. The known HTTP clients, raw\n # sockets and interpreters are denied outright; anything else that merely\n # names an endpoint escalates to ask (the catch-all rows in the ask section).\n # ips and domains live on separate rows \u2014 the dimension's sub-dimensions are\n # AND, and one target can only ever be one of the two shapes. At the proxy\n # face these rows fire for attributed traffic regardless of the command\n # (command is invisible there); pre-execution the network candidates come\n # from network-extract.ts.\n - command: [curl, wget, http, httpie, nc, ncat, netcat, socat, python, python3, node, deno, ruby, perl, php]\n network: { ips: [\"169.254.169.254\", \"169.254.170.2\", \"169.254.170.23\", \"fd00:ec2::254\", \"fd00:ec2::23\", \"100.100.100.200\"] }\n reason: \"[deny-rule:network.cloud-metadata-ips] A cloud metadata endpoint returns the instance's IAM credentials to whoever asks. Fetch through the platform SDK or IMDSv2 session auth \u2014 never a bare client call.\"\n - command: [curl, wget, http, httpie, nc, ncat, netcat, socat, python, python3, node, deno, ruby, perl, php]\n network: { domains: [\"metadata.google.internal\", \"metadata.goog\"] }\n reason: \"[deny-rule:network.cloud-metadata-domains] A cloud metadata endpoint returns the instance's IAM credentials to whoever asks. Fetch through the platform SDK or IMDSv2 session auth \u2014 never a bare client call.\"\n\n # \u2500\u2500 PowerShell \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # Command words are lowercased by the decomposer \u2014 command dimensions must\n # carry the lowercased verb (Remove-Item \u2192 remove-item).\n - command: [\"remove-item#recursive\"]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:powershell.remove-item-git-metadata] Never target .git.\"\n - command: [powershell, pwsh]\n argv: { pipeline: [\"pwsh *Remove-Item*\", \"powershell *Remove-Item*\", \"pwsh *remove-item*\", \"powershell *remove-item*\"] }\n reason: \"[deny-rule:powershell.nested-recursive-delete-unread] A delete handed to pwsh/powershell in a non-literal form cannot be verified before it runs.\"\n - command: [\"remove-item#recursive\"]\n args: [\".\", \"./\"]\n reason: \"[deny-rule:powershell.remove-item-recursive-force-cwd-self] Deleting the current directory removes the project.\"\n - command: [\"remove-item#recursive\"]\n args: [\"../*\", \"..\\\\*\"]\n reason: \"[deny-rule:powershell.remove-item-recursive-force-outside-cwd] Deleting above the cwd escapes task scope.\"\n\n # \u2500\u2500 Command Prompt \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # (The cc escaped-quote-collapse rule cannot be expressed faithfully with\n # these globs \u2014 every cmd /c recursion is nested behind a second parser,\n # so its true target is undecidable: it moves to the ask section instead.)\n - command: [cmd, rmdir, del]\n args: [\".git\", \".git/*\", \"*/.git\"]\n reason: \"[deny-rule:cmd.recursive-delete-git-metadata] Never target .git.\"\n - command: [rmdir, del]\n args: [\".\", \"./\"]\n reason: \"[deny-rule:cmd.recursive-delete-cwd-self] Deleting the current directory removes the project.\"\n - command: [rmdir, del]\n args: [\"../*\", \"..\\\\*\"]\n reason: \"[deny-rule:cmd.recursive-delete-outside-cwd] Delete above cwd escapes task scope.\"\n\n # \u2500\u2500 Secret targets (write/delete deny; reads are the ask section below) \u2500\u2500\n - command: [\"rm#recursive\", \"remove-item#recursive\", rmdir, del]\n args: [\"*/.ssh\", \"*/.aws\", \"*/.gnupg\", \".ssh\", \".aws\"]\n reason: \"[deny-rule:secret.delete-credential-path] Deleting credential stores destroys keys you cannot regenerate.\"\n - command: [echo, \"set-content\", \"out-file\"]\n args: [\".env\", \".env.*\"]\n reason: \"[deny-rule:secret.write-overwrite-env] Overwriting .env destroys existing secrets. Edit specific lines.\"\n - command: [\"rm#recursive\", \"remove-item#recursive\", rmdir, del]\n args: [\"*/.git-credentials\", \".git-credentials\"]\n reason: \"[deny-rule:secret.delete-git-credentials] Deleting the git credential store breaks push/pull auth.\"\n\nask:\n # Force push: ask, not deny (revoked from cc's deny ruling 2026-10-13).\n - command: [git]\n argv: { pipeline: [\"git push *--force*\", \"git push *-f*\"] }\n reason: \"[deny-rule:git.push-force] Force push rewrites shared history. Prefer git push --force-with-lease.\"\n\n # cmd /c recursion hides the real target behind a second parser (and quoting):\n # undecidable \u2192 ask, where cc denied only the drive-root-collapse variant.\n - command: [cmd]\n argv: { pipeline: [\"cmd /c *rmdir /s*\", \"cmd /c *del /s*\"] }\n reason: \"[deny-rule:cmd.recursive-delete-nested] cmd /c recursion nests a second parser; the real target cannot be resolved. Run rmdir/del directly so the gate can see the target.\"\n\n # Dynamic targets: this gate's ruling is \"undecidable \u2192 ask\", not fail-closed deny.\n - command: [\"rm#recursive\", \"remove-item#recursive\"]\n args: [\"$*\"]\n reason: \"[deny-rule:rm.recursive-force-dynamic-target] Recursive delete of a substitution-assembled target \u2014 verify the variable yourself.\"\n # The wrapper word xargs is stripped by the decomposer, so pipeline patterns\n # never see it \u2014 match the raw command string through the params dimension.\n - params: { command: [\"*xargs rm*\", \"*xargs del*\"] }\n reason: \"[deny-rule:xargs.rm-recursive-force-dynamic] xargs-fed removals have unverifiable target sets.\"\n - command: [parallel]\n argv: { pipeline: [\"parallel *rm*\", \"*| parallel*\"] }\n reason: \"[deny-rule:parallel.rm-recursive-force-dynamic] parallel-fed rm has unresolvable targets.\"\n - command: [awk]\n args: [\"*system(*\"]\n reason: \"[deny-rule:awk.system-dynamic] awk program text containing system() cannot be analyzed.\"\n # NOTE: cc's git checkout <ref> <path> ambiguity (G5) is NOT ported \u2014 a glob\n # cannot tell ref candidates from paths, and a broad pattern would prompt on\n # every git checkout -b new-branch. Documented residual gap.\n\n # The catch-all half of the metadata guard: a non-client call (echo, cat, a\n # script) that merely names an endpoint is a question, not a theft \u2014 ask.\n - network: { ips: [\"169.254.169.254\", \"169.254.170.2\", \"169.254.170.23\", \"fd00:ec2::254\", \"fd00:ec2::23\", \"100.100.100.200\"] }\n reason: \"[deny-rule:network.cloud-metadata-ips-any] This call names a cloud metadata endpoint. Confirm why instance credentials are being addressed before it runs.\"\n - network: { domains: [\"metadata.google.internal\", \"metadata.goog\"] }\n reason: \"[deny-rule:network.cloud-metadata-domains-any] This call names a cloud metadata endpoint. Confirm why instance credentials are being addressed before it runs.\"\n\n # Credential reads: ask (A2 ruling kept; egress combos stay in the prompt layer).\n - command: [cat, head, tail, type, \"get-content\", ls, dir, \"get-childitem\", \"select-string\"]\n args: [\".env\", \".env.*\", \"*.env\", \".npmrc\", \".pypirc\", \".netrc\", \".git-credentials\", \"id_rsa\", \"id_ed25519\", \"id_ecdsa\"]\n reason: \"[deny-rule:secret.read-credential-file] Reading a credential file requires confirmation. Echo only the keys you need via a filtered command.\"\n - command: [cat, head, tail, type, \"get-content\", ls, dir, \"get-childitem\"]\n args: [\"*/.ssh\", \"*/.ssh/*\", \"*/.aws\", \"*/.aws/*\", \"*/.gnupg\", \"*/.gnupg/*\", \"*/.config/gcloud/*\", \"*/.claude/*\", \"*/.codex/*\"]\n reason: \"[deny-rule:secret.read-home-credential-dirs] Browsing ssh/cloud/coding-CLI credential stores requires confirmation.\"\n\n # \u2500\u2500 Credential family ladder (read side) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # One row per family, restricted to the file-READ tools: decide() pre-queries the\n # rule layer for READ calls, so these rows are what a read hits (shell reads stay\n # under the secret.* rows above, which match first in this section). The settings\n # face rewrites each row as the family's rung: deny - moved to the deny section;\n # ask - stays here; readonly/readwrite - enabled:false (readwrite additionally\n # lists the family in credWriteExemptFamilies for the engine's write clause).\n # Custom credentialPaths have no family and are never write-exempt.\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.ssh\", \"*/.ssh/*\", \"*id_rsa\", \"*id_ed25519\", \"*id_ecdsa\", \"*id_dsa\", \"*authorized_keys\"]\n reason: \"[deny-rule:cred.ssh] Reading SSH keys or authorized_keys needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.aws\", \"*/.aws/*\", \"*/.config/gcloud\", \"*/.config/gcloud/*\", \"*/.azure\", \"*/.azure/*\", \"*credentials.yaml\", \"*credentials.json\"]\n reason: \"[deny-rule:cred.cloud] Reading cloud-provider credential stores needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.npmrc\", \"*.npmrc\", \"*/.pypirc\", \"*/.netrc\", \"*_netrc\", \"*/pip.conf\"]\n reason: \"[deny-rule:cred.package] Reading package-registry auth files needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.git-credentials\", \"*.git-credentials\"]\n reason: \"[deny-rule:cred.gitcreds] Reading the git credential store needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.env\", \"*/.env.*\", \"*.env\"]\n reason: \"[deny-rule:cred.env] Reading project env files needs confirmation (family rung: ask; readwrite also lets edits, npm-login-style).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.claude\", \"*/.claude/*\", \"*/.codex\", \"*/.codex/*\", \"*/.config/gh\", \"*/.config/gh/*\"]\n reason: \"[deny-rule:cred.cli] Reading coding-CLI credential stores needs confirmation (family rung: ask).\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*/.pgpass\", \"*pgpass\", \"*/.my.cnf\"]\n reason: \"[deny-rule:cred.db] Reading database credential files needs confirmation (family rung: ask).\"\n\n # SSH key variants (cc-safety-net secret.variant.* + the broad *_rsa|dsa|ed25519|ecdsa\n # shape + the generic \"credentials\" basename): keys get copied and renamed \u2014\n # id_rsa.bak, github_deploy_ed25519 and id_rsa-old deserve the same ask the\n # canonical names get. New rows (not a mutation of the seeded originals): the\n # watermark backfill is id-based and a mutated row would never reach existing\n # installs. They sit AFTER the family ladder so canonical shapes keep their\n # family tag (and rung governance); only what the ladder missed falls through.\n # The cred.ssh-variants row is NOT family-governed \u2014 a readonly/readwrite rung\n # on the ssh family does not silence it; revoke it by row if unwanted.\n - command: [cat, head, tail, type, \"get-content\", ls, dir, \"get-childitem\", \"select-string\"]\n args: [\"*id_rsa*\", \"*id_ed25519*\", \"*id_ecdsa*\", \"*id_dsa*\", \"*_rsa\", \"*_dsa\", \"*_ed25519\", \"*_ecdsa\", \"credentials\", \"*/credentials\"]\n reason: \"[deny-rule:secret.ssh-key-variants] This path looks like a private key under a renamed or variant basename. Reading key material needs confirmation.\"\n - tools: [read, read_image, grep, glob, ls, lsp]\n args: [\"*id_rsa*\", \"*id_ed25519*\", \"*id_ecdsa*\", \"*id_dsa*\", \"*_rsa\", \"*_dsa\", \"*_ed25519\", \"*_ecdsa\", \"credentials\", \"*/credentials\"]\n reason: \"[deny-rule:cred.ssh-variants] Reading a private-key variant basename needs confirmation (not family-governed; revoke by row).\"\n\n # Self-protection: editing the gate's own rule sources needs confirmation \u2014\n # revocation must be a human act, not something an agent can slide through.\n # (Settings-namespace edits go through the host UI, not a tool call, and are\n # out of reach of this entry; documented gap.)\n - args: [\"*rules.yml\", \"*rules.yaml\", \"*deny-defaults*\"]\n reason: \"[deny-rule:gate.self-protection] This call touches the permission gate's own rule sources; changes here alter what the gate enforces.\"\n";
|
|
52
54
|
export declare function parsePresetDoc(): PermissionsDoc;
|
|
53
55
|
/** Every preset id, in table order. Client view + tests use this as the row key. */
|
|
54
56
|
export declare function presetRuleIds(): string[];
|
package/lib/preset-rules.js
CHANGED
|
@@ -35,9 +35,11 @@ import { CRED_FAMILY_IDS } from './cred-families.js';
|
|
|
35
35
|
* Shipped version of the preset table. Activation backfills (idempotent, revocation-
|
|
36
36
|
* preserving) whenever the stored `presetRulesVersion` lags this number — bump it
|
|
37
37
|
* whenever `PRESET_RULES_YAML` gains entries that existing installs must receive
|
|
38
|
-
* (v1 added the seven `cred.*` family rows
|
|
38
|
+
* (v1 added the seven `cred.*` family rows; v2 added the four
|
|
39
|
+
* `network.cloud-metadata*` rows with the pre-execution extractor; v3 added the
|
|
40
|
+
* two ssh-key-variant rows and the dotted-variant shapes to the ssh family).
|
|
39
41
|
*/
|
|
40
|
-
export const PRESET_TABLE_VERSION =
|
|
42
|
+
export const PRESET_TABLE_VERSION = 3;
|
|
41
43
|
/** Tag prefix carried by every preset entry's reason; locates an entry for revocation. */
|
|
42
44
|
export const PRESET_RULE_MARKER = '[deny-rule:';
|
|
43
45
|
/** Extract the `[deny-rule:<id>]` tag from one reason string (undefined when untagged). */
|
|
@@ -164,6 +166,23 @@ deny:
|
|
|
164
166
|
args: ["*/dev/sd*", "*/dev/nvme*", "*/dev/disk*", "*/dev/mmcblk*"]
|
|
165
167
|
reason: "[deny-rule:redirect.block-device] Redirect target resolving to a disk device path."
|
|
166
168
|
|
|
169
|
+
# ── Network ───────────────────────────────────────────────────────────────
|
|
170
|
+
# Cloud metadata endpoints (cc-safety-net network.cloud-metadata): one request
|
|
171
|
+
# returns the instance's IAM/STS credentials. The known HTTP clients, raw
|
|
172
|
+
# sockets and interpreters are denied outright; anything else that merely
|
|
173
|
+
# names an endpoint escalates to ask (the catch-all rows in the ask section).
|
|
174
|
+
# ips and domains live on separate rows — the dimension's sub-dimensions are
|
|
175
|
+
# AND, and one target can only ever be one of the two shapes. At the proxy
|
|
176
|
+
# face these rows fire for attributed traffic regardless of the command
|
|
177
|
+
# (command is invisible there); pre-execution the network candidates come
|
|
178
|
+
# from network-extract.ts.
|
|
179
|
+
- command: [curl, wget, http, httpie, nc, ncat, netcat, socat, python, python3, node, deno, ruby, perl, php]
|
|
180
|
+
network: { ips: ["169.254.169.254", "169.254.170.2", "169.254.170.23", "fd00:ec2::254", "fd00:ec2::23", "100.100.100.200"] }
|
|
181
|
+
reason: "[deny-rule:network.cloud-metadata-ips] A cloud metadata endpoint returns the instance's IAM credentials to whoever asks. Fetch through the platform SDK or IMDSv2 session auth — never a bare client call."
|
|
182
|
+
- command: [curl, wget, http, httpie, nc, ncat, netcat, socat, python, python3, node, deno, ruby, perl, php]
|
|
183
|
+
network: { domains: ["metadata.google.internal", "metadata.goog"] }
|
|
184
|
+
reason: "[deny-rule:network.cloud-metadata-domains] A cloud metadata endpoint returns the instance's IAM credentials to whoever asks. Fetch through the platform SDK or IMDSv2 session auth — never a bare client call."
|
|
185
|
+
|
|
167
186
|
# ── PowerShell ───────────────────────────────────────────────────────────
|
|
168
187
|
# Command words are lowercased by the decomposer — command dimensions must
|
|
169
188
|
# carry the lowercased verb (Remove-Item → remove-item).
|
|
@@ -235,6 +254,13 @@ ask:
|
|
|
235
254
|
# cannot tell ref candidates from paths, and a broad pattern would prompt on
|
|
236
255
|
# every git checkout -b new-branch. Documented residual gap.
|
|
237
256
|
|
|
257
|
+
# The catch-all half of the metadata guard: a non-client call (echo, cat, a
|
|
258
|
+
# script) that merely names an endpoint is a question, not a theft — ask.
|
|
259
|
+
- network: { ips: ["169.254.169.254", "169.254.170.2", "169.254.170.23", "fd00:ec2::254", "fd00:ec2::23", "100.100.100.200"] }
|
|
260
|
+
reason: "[deny-rule:network.cloud-metadata-ips-any] This call names a cloud metadata endpoint. Confirm why instance credentials are being addressed before it runs."
|
|
261
|
+
- network: { domains: ["metadata.google.internal", "metadata.goog"] }
|
|
262
|
+
reason: "[deny-rule:network.cloud-metadata-domains-any] This call names a cloud metadata endpoint. Confirm why instance credentials are being addressed before it runs."
|
|
263
|
+
|
|
238
264
|
# Credential reads: ask (A2 ruling kept; egress combos stay in the prompt layer).
|
|
239
265
|
- command: [cat, head, tail, type, "get-content", ls, dir, "get-childitem", "select-string"]
|
|
240
266
|
args: [".env", ".env.*", "*.env", ".npmrc", ".pypirc", ".netrc", ".git-credentials", "id_rsa", "id_ed25519", "id_ecdsa"]
|
|
@@ -273,6 +299,22 @@ ask:
|
|
|
273
299
|
args: ["*/.pgpass", "*pgpass", "*/.my.cnf"]
|
|
274
300
|
reason: "[deny-rule:cred.db] Reading database credential files needs confirmation (family rung: ask)."
|
|
275
301
|
|
|
302
|
+
# SSH key variants (cc-safety-net secret.variant.* + the broad *_rsa|dsa|ed25519|ecdsa
|
|
303
|
+
# shape + the generic "credentials" basename): keys get copied and renamed —
|
|
304
|
+
# id_rsa.bak, github_deploy_ed25519 and id_rsa-old deserve the same ask the
|
|
305
|
+
# canonical names get. New rows (not a mutation of the seeded originals): the
|
|
306
|
+
# watermark backfill is id-based and a mutated row would never reach existing
|
|
307
|
+
# installs. They sit AFTER the family ladder so canonical shapes keep their
|
|
308
|
+
# family tag (and rung governance); only what the ladder missed falls through.
|
|
309
|
+
# The cred.ssh-variants row is NOT family-governed — a readonly/readwrite rung
|
|
310
|
+
# on the ssh family does not silence it; revoke it by row if unwanted.
|
|
311
|
+
- command: [cat, head, tail, type, "get-content", ls, dir, "get-childitem", "select-string"]
|
|
312
|
+
args: ["*id_rsa*", "*id_ed25519*", "*id_ecdsa*", "*id_dsa*", "*_rsa", "*_dsa", "*_ed25519", "*_ecdsa", "credentials", "*/credentials"]
|
|
313
|
+
reason: "[deny-rule:secret.ssh-key-variants] This path looks like a private key under a renamed or variant basename. Reading key material needs confirmation."
|
|
314
|
+
- tools: [read, read_image, grep, glob, ls, lsp]
|
|
315
|
+
args: ["*id_rsa*", "*id_ed25519*", "*id_ecdsa*", "*id_dsa*", "*_rsa", "*_dsa", "*_ed25519", "*_ecdsa", "credentials", "*/credentials"]
|
|
316
|
+
reason: "[deny-rule:cred.ssh-variants] Reading a private-key variant basename needs confirmation (not family-governed; revoke by row)."
|
|
317
|
+
|
|
276
318
|
# Self-protection: editing the gate's own rule sources needs confirmation —
|
|
277
319
|
# revocation must be a human act, not something an agent can slide through.
|
|
278
320
|
# (Settings-namespace edits go through the host UI, not a tool call, and are
|