qualiow-exploratory-testing 2.3.0 → 2.3.1
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +80 -0
- package/README.md +20 -13
- package/agents/qa-bug-judge.md +1 -1
- package/agents/qa-diff-indexer-agent.md +1 -1
- package/agents/qa-gather-agent.md +1 -1
- package/agents/qa-reporting-agent.md +1 -1
- package/bin/mobile-cli.mjs +74 -26
- package/bin/qualiow +7 -2
- package/bin/wk-ios +60 -6
- package/bin/wkeval.mjs +7 -2
- package/dist/cli/index.js +718 -172
- package/dist/index.d.ts +63 -19
- package/dist/index.js +586 -136
- package/docs/GETTING-STARTED.md +19 -9
- package/docs/MOBILE-SETUP.md +31 -0
- package/hooks/hooks.json +12 -2
- package/hooks/scripts/bash-guard.mjs +242 -0
- package/hooks/scripts/secret-patterns.d.mts +4 -1
- package/hooks/scripts/secret-patterns.mjs +126 -34
- package/hooks/scripts/write-guard.mjs +70 -15
- package/package.json +1 -1
- package/skills/qa-explore/SKILL.md +1 -1
- package/skills/qa-explore/references/evidence-triage.md +44 -12
- package/skills/qa-explore/references/output-contract.md +1 -1
- package/skills/qa-explore/references/security-rules.md +14 -2
- package/skills/qa-explore-cleanup/SKILL.md +1 -1
- package/skills/qa-explore-mobile/SKILL.md +13 -3
- package/skills/qa-explore-mobile/references/mobile-edges.md +3 -1
- package/skills/qa-explore-quick/SKILL.md +1 -1
- package/skills/qa-explore-report/SKILL.md +1 -1
- package/skills/qa-gather/SKILL.md +1 -1
- package/skills/qa-knowledge-add/SKILL.md +1 -1
- package/skills/qa-knowledge-list/SKILL.md +1 -1
- package/skills/qa-verify-backend/SKILL.md +1 -1
- package/skills/qa-verify-backend/phases/05-reporting.md +2 -1
package/docs/GETTING-STARTED.md
CHANGED
|
@@ -52,18 +52,22 @@ npx playwright-cli install --skills # optional: the official Playwright skill
|
|
|
52
52
|
qualiow init --hooks
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Optional, and only for npm projects — a plugin install already ships the same
|
|
55
|
+
Optional, and only for npm projects — a plugin install already ships the same three hooks and
|
|
56
56
|
has them on by default, so do not enable both in one project. `--hooks` copies the guard
|
|
57
|
-
scripts to `qa/hooks/` and merges into `.claude/settings.json`
|
|
58
|
-
three `permissions.allow` rules.
|
|
59
|
-
|
|
57
|
+
scripts to `qa/hooks/` and merges into `.claude/settings.json` three `PreToolUse` entries and
|
|
58
|
+
three `permissions.allow` rules. Running it again changes nothing, and hooks you already had
|
|
59
|
+
are kept; an older qualiow-only write-guard entry gets the new matcher. If `settings.json`
|
|
60
|
+
does not parse (a comment, a trailing comma), init stops without writing anything and prints
|
|
61
|
+
the entries to merge by hand.
|
|
60
62
|
|
|
61
63
|
What the guards do: `read-guard.mjs` denies a whole-file `Read` of a qualiow file over
|
|
62
64
|
`QUALIOW_READ_MAX_LINES` lines (default 300) — the knowledge manifest, a knowledge release
|
|
63
65
|
file, a session phase file or a raw snapshot — and names the cheaper route in the refusal; a
|
|
64
66
|
`Read` with `offset` or `limit` passes. `write-guard.mjs` refuses a `Write` or `Edit` under
|
|
65
|
-
`output/` whose content matches the redaction list, so a secret never reaches disk.
|
|
66
|
-
|
|
67
|
+
`output/` whose content matches the redaction list, so a secret never reaches disk.
|
|
68
|
+
`bash-guard.mjs` sees every `Bash` command but only acts on a few: it asks before
|
|
69
|
+
`playwright-cli run-code` and before `git` options that can run a shell, and denies `npx -c`
|
|
70
|
+
or `npx -y` of an unknown package. `QUALIOW_HOOKS=off` disables all three.
|
|
67
71
|
|
|
68
72
|
To write it by hand instead, this is the whole of it:
|
|
69
73
|
|
|
@@ -78,10 +82,16 @@ To write it by hand instead, this is the whole of it:
|
|
|
78
82
|
]
|
|
79
83
|
},
|
|
80
84
|
{
|
|
81
|
-
"matcher": "Write|Edit|MultiEdit",
|
|
85
|
+
"matcher": "Write|Edit|MultiEdit|NotebookEdit",
|
|
82
86
|
"hooks": [
|
|
83
87
|
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/qa/hooks/write-guard.mjs\"" }
|
|
84
88
|
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"matcher": "Bash",
|
|
92
|
+
"hooks": [
|
|
93
|
+
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/qa/hooks/bash-guard.mjs\"" }
|
|
94
|
+
]
|
|
85
95
|
}
|
|
86
96
|
]
|
|
87
97
|
},
|
|
@@ -406,11 +416,11 @@ decide which entries a skill always gets without touching the skill itself.
|
|
|
406
416
|
|
|
407
417
|
```bash
|
|
408
418
|
qualiow init --dry-run # preview what init would write
|
|
409
|
-
qualiow init --hooks # add the read/write guards to .claude/settings.json
|
|
419
|
+
qualiow init --hooks # add the read/write/bash guards to .claude/settings.json
|
|
410
420
|
qualiow validate --all # targets + qa/target.yml + domains + knowledge base
|
|
411
421
|
qualiow list sessions # also: knowledge | targets | domains
|
|
412
422
|
qualiow list knowledge --stats # also: --domain --tag --type --entry <id> --changelog
|
|
413
|
-
qualiow report -s latest -f html -o report.html
|
|
423
|
+
qualiow report -s latest -f html -o report.html # writes output/report.html
|
|
414
424
|
qualiow kb check
|
|
415
425
|
qualiow kb digest --for explore # the knowledge a session loads
|
|
416
426
|
qualiow session finalize latest # validate a finished session and index it
|
package/docs/MOBILE-SETUP.md
CHANGED
|
@@ -181,6 +181,37 @@ Requires `ios-webkit-debug-proxy`, `python3`, Node ≥ 22.4 (`wkeval.mjs` uses t
|
|
|
181
181
|
`WebSocket`), and a booted Simulator with Safari on a page. `WK_IOS_PORT` (default 9221) sets
|
|
182
182
|
the iwdp device-list port; pages are served on `WK_IOS_PORT + 1`.
|
|
183
183
|
|
|
184
|
+
> **⚠️ The proxy listens on every network interface, without authentication.**
|
|
185
|
+
> `ios-webkit-debug-proxy` (1.9.x) has no bind-address option, so ports `WK_IOS_PORT` to
|
|
186
|
+
> `WK_IOS_PORT + 101` are reachable from your LAN while it runs, and anyone who can reach them
|
|
187
|
+
> can evaluate JavaScript in the Simulator's pages — including their logged-in sessions. The
|
|
188
|
+
> proxy stays up between calls so each eval is fast; `wk-ios` prints a warning when it starts
|
|
189
|
+
> it. **Run `bin/wk-ios --stop` as soon as the session ends**, keep the macOS firewall on
|
|
190
|
+
> (System Settings → Network → Firewall), and avoid using the bridge on untrusted networks.
|
|
191
|
+
|
|
192
|
+
Safari keeps old tabs inspectable, so the newest page is not always the one under test. Set
|
|
193
|
+
`WK_PAGE_FILTER` to pin it. The filter is matched against the parsed page URL — never as a raw
|
|
194
|
+
substring, so a page cannot win by carrying the filter in its query string or fragment — and the
|
|
195
|
+
newest matching page is used:
|
|
196
|
+
|
|
197
|
+
| `WK_PAGE_FILTER` | Matches |
|
|
198
|
+
|---|---|
|
|
199
|
+
| `/account` | any page whose path starts with `/account` (any host) |
|
|
200
|
+
| `staging.example.com` | that host or any subdomain of it; `host:port` matches that exact host and port |
|
|
201
|
+
| `staging.example.com/account` | exactly that host, path starting with `/account` |
|
|
202
|
+
| `https://staging.example.com/account` | same scheme and host[:port], path starting with `/account` |
|
|
203
|
+
|
|
204
|
+
When no page matches, `wk-ios` stops with an error rather than evaluating in another tab. Prefer
|
|
205
|
+
a host-qualified form: a bare `/path` does not pin the host.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
WK_PAGE_FILTER=staging.example.com/account bin/wk-ios 'document.title'
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The proxy's pid and log files live in a private per-user directory,
|
|
212
|
+
`${TMPDIR:-/tmp}/wk-ios-<uid>/` (mode 700). Page values printed by `wk-ios`, and app labels
|
|
213
|
+
printed by `mcli snapshot` and `mcli logs`, have terminal control characters stripped.
|
|
214
|
+
|
|
184
215
|
## Why a Google **Play** (or `google_apis`) Android image
|
|
185
216
|
|
|
186
217
|
A stock **AOSP** system image ships **no `com.android.chrome`** — only a basic AOSP
|
package/hooks/hooks.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "qualiow routing guards: whole-file reads of qualiow data over the line threshold,
|
|
2
|
+
"description": "qualiow routing guards: whole-file reads of qualiow data over the line threshold, secrets in session output, and code-execution routes in Bash (playwright-cli run-code, arbitrary npx)",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"PreToolUse": [
|
|
5
5
|
{
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
]
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
"matcher": "Write|Edit|MultiEdit",
|
|
16
|
+
"matcher": "Write|Edit|MultiEdit|NotebookEdit",
|
|
17
17
|
"hooks": [
|
|
18
18
|
{
|
|
19
19
|
"type": "command",
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
"timeout": 10
|
|
22
22
|
}
|
|
23
23
|
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"matcher": "Bash",
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/bash-guard.mjs\"",
|
|
31
|
+
"timeout": 10
|
|
32
|
+
}
|
|
33
|
+
]
|
|
24
34
|
}
|
|
25
35
|
]
|
|
26
36
|
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* PreToolUse hook (matcher: Bash).
|
|
4
|
+
*
|
|
5
|
+
* Code-execution routes that a pre-approved `Bash(playwright-cli:*)`,
|
|
6
|
+
* `Bash(git -C:*)` or a permissive `npx` rule would otherwise let through
|
|
7
|
+
* without a prompt:
|
|
8
|
+
*
|
|
9
|
+
* - `playwright-cli run-code` (direct or via `npx playwright-cli`) runs its
|
|
10
|
+
* JavaScript in the Playwright node process, not in the browser sandbox —
|
|
11
|
+
* the `vm` context holding `page` is escapable to the host `process`. It is
|
|
12
|
+
* used legitimately, so the decision is `ask`: the user confirms every call.
|
|
13
|
+
* - `npx -c/--call <shell>`, and `npx -y`/`-p` of a package outside a short
|
|
14
|
+
* allowlist, install or run arbitrary code. The decision is `deny`.
|
|
15
|
+
* - `git -c <key>=<value>`, `--config-env`, `--upload-pack`, `--receive-pack`,
|
|
16
|
+
* `--exec`, `--ext-diff` and `--output` run a program or write an arbitrary
|
|
17
|
+
* file from an otherwise read-only git call — the skills pre-approve
|
|
18
|
+
* `git -C <repo> …` for the repository under test. The decision is `ask`.
|
|
19
|
+
*
|
|
20
|
+
* Compound commands are split on `&&`, `||`, `;`, `|`, `&` and newlines;
|
|
21
|
+
* leading `VAR=value` assignments and `env`/`command`/`exec`/`time`/`nohup`
|
|
22
|
+
* wrappers are skipped; `bash|sh|zsh -c '<cmd>'`, `eval`, `$(…)` and backticks
|
|
23
|
+
* are inspected as nested commands. A `deny` anywhere wins over an `ask`.
|
|
24
|
+
*
|
|
25
|
+
* Node built-ins only — a git-sourced plugin install has neither `dist/` nor
|
|
26
|
+
* `node_modules`. Never throws and never blocks on its own failure: any error
|
|
27
|
+
* here lets the command through (exit 0, no stdout) to the normal permission
|
|
28
|
+
* check rather than breaking the caller because of a hook bug.
|
|
29
|
+
*/
|
|
30
|
+
import { readFileSync } from 'node:fs';
|
|
31
|
+
|
|
32
|
+
const NPX_ALLOWED_PACKAGES = new Set(['playwright-cli', '@playwright/cli', 'qualiow-exploratory-testing']);
|
|
33
|
+
const PLAYWRIGHT_CLI_NAMES = new Set(['playwright-cli', '@playwright/cli']);
|
|
34
|
+
const WRAPPERS = new Set(['env', 'command', 'exec', 'time', 'nohup']);
|
|
35
|
+
const SHELLS = new Set(['bash', 'sh', 'zsh', 'dash']);
|
|
36
|
+
const MAX_DEPTH = 4;
|
|
37
|
+
|
|
38
|
+
function decide(permissionDecision, reason) {
|
|
39
|
+
process.stdout.write(
|
|
40
|
+
JSON.stringify({
|
|
41
|
+
hookSpecificOutput: {
|
|
42
|
+
hookEventName: 'PreToolUse',
|
|
43
|
+
permissionDecision,
|
|
44
|
+
permissionDecisionReason: reason,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Splits a command line into segments of words. Honours single and double
|
|
52
|
+
* quotes and backslash escapes; splits on unquoted && || ; | & and newlines.
|
|
53
|
+
*/
|
|
54
|
+
function segments(command) {
|
|
55
|
+
const out = [];
|
|
56
|
+
let words = [];
|
|
57
|
+
let word = '';
|
|
58
|
+
let inWord = false;
|
|
59
|
+
let quote = null;
|
|
60
|
+
const endWord = () => {
|
|
61
|
+
if (inWord) words.push(word);
|
|
62
|
+
word = '';
|
|
63
|
+
inWord = false;
|
|
64
|
+
};
|
|
65
|
+
const endSegment = () => {
|
|
66
|
+
endWord();
|
|
67
|
+
if (words.length) out.push(words);
|
|
68
|
+
words = [];
|
|
69
|
+
};
|
|
70
|
+
for (let i = 0; i < command.length; i++) {
|
|
71
|
+
const c = command[i];
|
|
72
|
+
if (quote) {
|
|
73
|
+
if (c === quote) quote = null;
|
|
74
|
+
else if (c === '\\' && quote === '"' && i + 1 < command.length) word += command[++i];
|
|
75
|
+
else word += c;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (c === '"' || c === "'") {
|
|
79
|
+
quote = c;
|
|
80
|
+
inWord = true;
|
|
81
|
+
} else if (c === '\\' && i + 1 < command.length) {
|
|
82
|
+
word += command[++i];
|
|
83
|
+
inWord = true;
|
|
84
|
+
} else if (c === ';' || c === '|' || c === '&' || c === '\n') {
|
|
85
|
+
endSegment();
|
|
86
|
+
} else if (c === ' ' || c === '\t' || c === '(' || c === ')' || c === '{' || c === '}') {
|
|
87
|
+
endWord();
|
|
88
|
+
} else {
|
|
89
|
+
word += c;
|
|
90
|
+
inWord = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
endSegment();
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `$(…)` and backtick bodies, inspected as nested commands. */
|
|
98
|
+
function substitutions(command) {
|
|
99
|
+
const found = [];
|
|
100
|
+
for (const m of command.matchAll(/\$\(([^()]*)\)/g)) found.push(m[1]);
|
|
101
|
+
for (const m of command.matchAll(/`([^`]*)`/g)) found.push(m[1]);
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function basename(word) {
|
|
106
|
+
const parts = word.split('/');
|
|
107
|
+
return parts[parts.length - 1];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `@scope/name@1.2.3` → `@scope/name`, `name@latest` → `name`. */
|
|
111
|
+
function packageName(spec) {
|
|
112
|
+
const at = spec.lastIndexOf('@');
|
|
113
|
+
return at > 0 ? spec.slice(0, at) : spec;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function runCodeIn(words) {
|
|
117
|
+
return words.includes('run-code');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const ASK_RUN_CODE =
|
|
121
|
+
'ask:playwright-cli run-code executes JavaScript in the Playwright node process (outside the browser sandbox); ' +
|
|
122
|
+
'confirm the code is yours and contains no text taken from page content. Set QUALIOW_HOOKS=off to disable.';
|
|
123
|
+
|
|
124
|
+
const GIT_EXEC_OPTION = /^(--upload-pack|--receive-pack|--exec|--ext-diff|--output|--config-env)(=|$)/;
|
|
125
|
+
|
|
126
|
+
/** A git option that runs a program or writes a file outside the read-only calls the skills make. */
|
|
127
|
+
function gitExecOption(words) {
|
|
128
|
+
let k = 0;
|
|
129
|
+
// Global options before the subcommand: `-c` is a config override there (and a
|
|
130
|
+
// harmless diff flag after it, as in `git log -c`).
|
|
131
|
+
while (k < words.length && words[k].startsWith('-')) {
|
|
132
|
+
if (words[k] === '-c') return '-c';
|
|
133
|
+
k += /^(-C|--git-dir|--work-tree|--namespace)$/.test(words[k]) ? 2 : 1;
|
|
134
|
+
}
|
|
135
|
+
const hit = words.slice(k).find((w) => GIT_EXEC_OPTION.test(w)) || words.slice(0, k).find((w) => GIT_EXEC_OPTION.test(w));
|
|
136
|
+
return hit ? hit.split('=')[0] : null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Returns 'deny:<reason>', 'ask:<reason>' or null for one segment's words. */
|
|
140
|
+
function checkWords(words, depth) {
|
|
141
|
+
let i = 0;
|
|
142
|
+
while (i < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i])) i++;
|
|
143
|
+
while (i < words.length && WRAPPERS.has(basename(words[i]))) {
|
|
144
|
+
i++;
|
|
145
|
+
while (i < words.length && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i]) || words[i].startsWith('-'))) i++;
|
|
146
|
+
}
|
|
147
|
+
if (i >= words.length) return null;
|
|
148
|
+
const program = basename(words[i]);
|
|
149
|
+
const rest = words.slice(i + 1);
|
|
150
|
+
|
|
151
|
+
if (SHELLS.has(program)) {
|
|
152
|
+
const c = rest.findIndex((w) => /^-[a-z]*c$/.test(w));
|
|
153
|
+
if (c >= 0 && rest[c + 1] != null) return checkCommand(rest[c + 1], depth + 1);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (program === 'eval') return checkCommand(rest.join(' '), depth + 1);
|
|
157
|
+
|
|
158
|
+
if (program === 'playwright-cli') return runCodeIn(rest) ? ASK_RUN_CODE : null;
|
|
159
|
+
|
|
160
|
+
if (program === 'git') {
|
|
161
|
+
const option = gitExecOption(rest);
|
|
162
|
+
return option
|
|
163
|
+
? `ask:git ${option} can run a program or write an arbitrary file; confirm it is intended. Set QUALIOW_HOOKS=off to disable.`
|
|
164
|
+
: null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (program !== 'npx') return null;
|
|
168
|
+
|
|
169
|
+
let yes = false;
|
|
170
|
+
const packages = [];
|
|
171
|
+
let j = 0;
|
|
172
|
+
for (; j < rest.length; j++) {
|
|
173
|
+
const w = rest[j];
|
|
174
|
+
if (w === '--') {
|
|
175
|
+
j++;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
if (!w.startsWith('-')) break;
|
|
179
|
+
if (w === '-c' || w === '--call' || w.startsWith('--call=')) {
|
|
180
|
+
return 'deny:npx -c/--call runs an arbitrary shell string; call the tool directly instead. Set QUALIOW_HOOKS=off to disable.';
|
|
181
|
+
}
|
|
182
|
+
if (w === '-y' || w === '--yes' || w.startsWith('--yes=')) yes = true;
|
|
183
|
+
else if (w === '-p' || w === '--package') {
|
|
184
|
+
if (rest[j + 1] != null) packages.push(rest[++j]);
|
|
185
|
+
} else if (w.startsWith('--package=')) packages.push(w.slice('--package='.length));
|
|
186
|
+
}
|
|
187
|
+
const command = rest.slice(j);
|
|
188
|
+
const candidates = packages.length ? packages : command.length ? [command[0]] : [];
|
|
189
|
+
if (packages.length || yes) {
|
|
190
|
+
const unknown = candidates.map(packageName).filter((p) => !NPX_ALLOWED_PACKAGES.has(p));
|
|
191
|
+
if (unknown.length) {
|
|
192
|
+
return (
|
|
193
|
+
`deny:npx would install and run ${unknown.join(', ')}, which is not on the qualiow allowlist ` +
|
|
194
|
+
`(${[...NPX_ALLOWED_PACKAGES].join(', ')}). Install it deliberately instead. Set QUALIOW_HOOKS=off to disable.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (command.length) {
|
|
199
|
+
const bin = PLAYWRIGHT_CLI_NAMES.has(packageName(command[0])) ? 'playwright-cli' : basename(command[0]);
|
|
200
|
+
if (bin === 'playwright-cli' && runCodeIn(command.slice(1))) return ASK_RUN_CODE;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Worst decision across every segment and nested command. */
|
|
206
|
+
function checkCommand(command, depth = 0) {
|
|
207
|
+
if (typeof command !== 'string' || depth > MAX_DEPTH) return null;
|
|
208
|
+
let ask = null;
|
|
209
|
+
const nested = substitutions(command).map((s) => checkCommand(s, depth + 1));
|
|
210
|
+
const direct = segments(command).map((w) => checkWords(w, depth));
|
|
211
|
+
for (const r of [...nested, ...direct]) {
|
|
212
|
+
if (!r) continue;
|
|
213
|
+
if (r.startsWith('deny:')) return r;
|
|
214
|
+
ask = ask || r;
|
|
215
|
+
}
|
|
216
|
+
return ask;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
if (process.env.QUALIOW_HOOKS === 'off') process.exit(0);
|
|
221
|
+
|
|
222
|
+
let raw = '';
|
|
223
|
+
try {
|
|
224
|
+
raw = readFileSync(0, 'utf-8');
|
|
225
|
+
} catch {
|
|
226
|
+
process.exit(0);
|
|
227
|
+
}
|
|
228
|
+
if (!raw || !raw.trim()) process.exit(0);
|
|
229
|
+
|
|
230
|
+
const input = JSON.parse(raw);
|
|
231
|
+
if (input.tool_name !== 'Bash') process.exit(0);
|
|
232
|
+
|
|
233
|
+
const command = (input.tool_input || {}).command;
|
|
234
|
+
if (!command || typeof command !== 'string') process.exit(0);
|
|
235
|
+
|
|
236
|
+
const result = checkCommand(command);
|
|
237
|
+
if (result && result.startsWith('deny:')) decide('deny', result.slice('deny:'.length));
|
|
238
|
+
else if (result && result.startsWith('ask:')) decide('ask', result.slice('ask:'.length));
|
|
239
|
+
process.exit(0);
|
|
240
|
+
} catch {
|
|
241
|
+
process.exit(0);
|
|
242
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export interface SecretPattern {
|
|
2
2
|
category: string;
|
|
3
3
|
re: RegExp;
|
|
4
|
-
|
|
4
|
+
/** Receives the match and its capture groups, as `String.prototype.replace` would. */
|
|
5
|
+
filter?: (match: string, ...groups: string[]) => boolean;
|
|
5
6
|
}
|
|
6
7
|
export const SECRET_PATTERNS: SecretPattern[];
|
|
7
8
|
/** Category names of every secret-shaped pattern found in `text`; never the matched text. */
|
|
8
9
|
export function findSecretCategories(text: string): string[];
|
|
10
|
+
/** Number of secret-shaped matches per category in `text`; never the matched text. */
|
|
11
|
+
export function countSecrets(text: string): Map<string, number>;
|
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Secret detection for the write-guard hook.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Carries the same rules as `src/utils/redact.ts`, regex for regex and in the
|
|
5
|
+
* same order (`tests/unit/redact-hardening.test.ts` compares the sources), so a
|
|
6
|
+
* hook denial matches what `qualiow session finalize --redact` would flag on
|
|
7
|
+
* the same text. Kept as a standalone, dependency-free ES module (Node
|
|
8
|
+
* built-ins only, no TS import) because a git-sourced plugin install has
|
|
9
|
+
* neither `dist/` nor `node_modules` to pull the real util from.
|
|
10
|
+
*
|
|
11
|
+
* Every pattern must stay linear on adversarial input: the hook has a timeout,
|
|
12
|
+
* and a hook that times out fails open.
|
|
9
13
|
*
|
|
10
14
|
* `findSecretCategories` never returns the matched text itself — only
|
|
11
15
|
* category names — so the hook that calls it can safely put the result in a
|
|
12
16
|
* denial reason without leaking the secret it found.
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
// Documentation domains only, matched exactly: `x@corp.example.com` is flagged.
|
|
20
|
+
const EMAIL_ALLOW = /@(?:example\.(?:com|org|net)|localhost)$/i;
|
|
21
|
+
|
|
22
|
+
// A value that is nothing but a redaction placeholder (optionally quoted, optionally
|
|
23
|
+
// after an auth scheme) is already clean; anything more than that is not.
|
|
24
|
+
const REDACTED_VALUE =
|
|
25
|
+
/^\s*\\?["']?(?:(?:bearer|basic|token|digest)\s+)?\[[A-Z0-9_]*REDACTED\]\\?["']?\s*$/i;
|
|
26
|
+
const JSON_LITERAL = /^(?:null|true|false)$/i;
|
|
27
|
+
|
|
28
|
+
const QUOTED = String.raw`\\"[^"\\\n]{1,4096}\\"|"(?:[^"\\\n]|\\.){1,4096}"|'(?:[^'\\\n]|\\.){1,4096}'`;
|
|
29
|
+
const LOOSE = String.raw`["']?[^\s,}"']+`;
|
|
30
|
+
const TOKENISH = String.raw`["']?[^\s,;}"'|]{8,}`;
|
|
31
|
+
const LINE_REST = String.raw`[^\s|](?:[^\r\n|]*[^\s|])?`;
|
|
32
|
+
|
|
33
|
+
function kv(keys, value, sepOps = ':=') {
|
|
34
|
+
return new RegExp(
|
|
35
|
+
String.raw`(${keys})((?:\\?["']|\*\*)?[ \t]*[${sepOps}][ \t]*(?:\*\*[ \t]*)?)(${QUOTED}|${value})`,
|
|
36
|
+
'gi',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PEM_HEAD = String.raw`-----BEGIN (?:[A-Z0-9]{1,20} ){0,3}PRIVATE KEY(?: BLOCK)?-----`;
|
|
41
|
+
const PEM_TAIL = String.raw`-----END (?:[A-Z0-9]{1,20} ){0,3}PRIVATE KEY(?: BLOCK)?-----`;
|
|
42
|
+
const NL = String.raw`(?:\r?\n|\\n)`;
|
|
43
|
+
const PEM_BODY = String.raw`(?:${NL}[ \t]*(?:(?:Proc-Type|DEK-Info|Version|Comment|Hash|Charset): [^\r\n]{0,256}|[A-Za-z0-9+/=]+(?:\.{2,}|…)?[ \t]*(?=${NL}|$|["'])|(?=${NL}|$)))*`;
|
|
16
44
|
|
|
17
45
|
function luhnValid(digits) {
|
|
18
46
|
let sum = 0;
|
|
@@ -31,29 +59,46 @@ function luhnValid(digits) {
|
|
|
31
59
|
return sum % 10 === 0;
|
|
32
60
|
}
|
|
33
61
|
|
|
62
|
+
// Key/value rules: the third group is the value; one that is already a placeholder is clean.
|
|
63
|
+
const keyValueFilter = (_match, _key, _sep, value) =>
|
|
64
|
+
!REDACTED_VALUE.test(value) && !JSON_LITERAL.test(value);
|
|
65
|
+
|
|
34
66
|
/**
|
|
35
67
|
* category: name surfaced in denial reasons (never the matched text).
|
|
36
|
-
* re: detection pattern (
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
68
|
+
* re: detection pattern (identical to the redact.ts rule of the same name).
|
|
69
|
+
* filter(match, ...groups): optional extra check a raw regex match can't
|
|
70
|
+
* express (Luhn validity, the example.com allow-list, a value that is
|
|
71
|
+
* already a redaction placeholder).
|
|
40
72
|
*/
|
|
41
73
|
export const SECRET_PATTERNS = [
|
|
42
74
|
{
|
|
43
75
|
category: 'Private key',
|
|
44
|
-
re:
|
|
76
|
+
re: new RegExp(
|
|
77
|
+
String.raw`${PEM_HEAD}(?:(?:(?!-----BEGIN )[\s\S]){0,16384}?${PEM_TAIL}|${PEM_BODY})`,
|
|
78
|
+
'g',
|
|
79
|
+
),
|
|
45
80
|
},
|
|
46
81
|
{
|
|
47
82
|
category: 'JWT',
|
|
48
|
-
re:
|
|
83
|
+
re: /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{8,}\.(?:[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}|eyJ[A-Za-z0-9_-]{6,}(?:\.[A-Za-z0-9_-]*)?)/g,
|
|
49
84
|
},
|
|
50
85
|
{
|
|
51
86
|
category: 'Authorization header',
|
|
52
|
-
re:
|
|
87
|
+
re: kv('authorization', LINE_REST),
|
|
88
|
+
filter: keyValueFilter,
|
|
53
89
|
},
|
|
54
90
|
{
|
|
55
91
|
category: 'Cookie header',
|
|
56
|
-
re:
|
|
92
|
+
re: kv('set-cookie|cookie', String.raw`[^\s|=]{1,256}=(?:[^\r\n|]*[^\s|])?`, ':=|'),
|
|
93
|
+
filter: keyValueFilter,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
category: 'Bearer token',
|
|
97
|
+
re: /\b(bearer|basic)([ \t]+)(?:(?=[A-Za-z._~+/-]*[0-9=])[A-Za-z0-9._~+/=-]{8,}|[A-Za-z0-9._~+/=-]{24,})/gi,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
category: 'AWS secret access key',
|
|
101
|
+
re: /(\b(?:AKIA|ASIA)[0-9A-Z]{16}\b|\[AWS_KEY_REDACTED\])([\s,;:|"'=]{1,8})[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+=])/g,
|
|
57
102
|
},
|
|
58
103
|
{
|
|
59
104
|
category: 'AWS access key id',
|
|
@@ -61,45 +106,77 @@ export const SECRET_PATTERNS = [
|
|
|
61
106
|
},
|
|
62
107
|
{
|
|
63
108
|
category: 'AWS secret access key',
|
|
64
|
-
re:
|
|
109
|
+
re: kv(String.raw`aws_secret_access_key|secret_?access_?key`, String.raw`["']?[^\s,;}"']+`),
|
|
110
|
+
filter: keyValueFilter,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
category: 'AWS session token',
|
|
114
|
+
re: kv(
|
|
115
|
+
String.raw`aws_session_token|session_?token|x-amz-security-token|security_?token`,
|
|
116
|
+
String.raw`["']?[^\s,;}"']+`,
|
|
117
|
+
),
|
|
118
|
+
filter: keyValueFilter,
|
|
65
119
|
},
|
|
66
120
|
{
|
|
67
121
|
category: 'OpenAI-style key',
|
|
68
|
-
re:
|
|
122
|
+
re: /(?<![A-Za-z0-9_-])sk-(?:proj-)?[A-Za-z0-9_-]{20,}/g,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
category: 'Stripe key',
|
|
126
|
+
re: /(?<![A-Za-z0-9_])(?:(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{10,}|whsec_[A-Za-z0-9+/=]{16,})/g,
|
|
69
127
|
},
|
|
70
128
|
{
|
|
71
129
|
category: 'GitHub token',
|
|
72
130
|
re: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/g,
|
|
73
131
|
},
|
|
132
|
+
{
|
|
133
|
+
category: 'GitLab token',
|
|
134
|
+
re: /(?<![A-Za-z0-9_-])glpat-[A-Za-z0-9_-]{20,}/g,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
category: 'npm token',
|
|
138
|
+
re: /\bnpm_[A-Za-z0-9]{36}\b/g,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
category: 'Google API key',
|
|
142
|
+
re: /\bAIza[0-9A-Za-z_-]{35}/g,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
category: 'Google OAuth token',
|
|
146
|
+
re: /\bya29\.[0-9A-Za-z_-]{20,}/g,
|
|
147
|
+
},
|
|
74
148
|
{
|
|
75
149
|
category: 'Slack token',
|
|
76
|
-
re:
|
|
150
|
+
re: /(?<![A-Za-z0-9-])xox[abposre](?:\.xox[a-z])?-[A-Za-z0-9-]{10,}/g,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
category: 'Slack webhook',
|
|
154
|
+
re: /(?:(?:https?:\/\/)?hooks\.slack\.com)?\/services\/T[A-Z0-9]{6,}\/B[A-Z0-9]{6,}\/[A-Za-z0-9]{16,}/g,
|
|
77
155
|
},
|
|
78
156
|
{
|
|
79
157
|
category: 'API key',
|
|
80
|
-
re:
|
|
158
|
+
re: kv(String.raw`x-api-key|api[_-]?key`, TOKENISH),
|
|
159
|
+
filter: keyValueFilter,
|
|
81
160
|
},
|
|
82
161
|
{
|
|
83
162
|
category: 'Password',
|
|
84
|
-
re:
|
|
163
|
+
re: kv('password|passwd|pwd', LOOSE),
|
|
164
|
+
filter: keyValueFilter,
|
|
85
165
|
},
|
|
86
166
|
{
|
|
87
167
|
category: 'Token',
|
|
88
|
-
re:
|
|
168
|
+
re: kv(String.raw`access[_-]?token|refresh[_-]?token|token`, TOKENISH),
|
|
169
|
+
filter: keyValueFilter,
|
|
89
170
|
},
|
|
90
171
|
{
|
|
91
172
|
category: 'Secret',
|
|
92
|
-
re:
|
|
173
|
+
re: kv(String.raw`secret(?:[_-]?(?:key|token|value))?`, LOOSE),
|
|
174
|
+
filter: keyValueFilter,
|
|
93
175
|
},
|
|
94
176
|
{
|
|
95
177
|
category: 'SSN',
|
|
96
178
|
re: /\b\d{3}-\d{2}-\d{4}\b/g,
|
|
97
179
|
},
|
|
98
|
-
{
|
|
99
|
-
category: 'Email',
|
|
100
|
-
re: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
101
|
-
filter: (match) => !EMAIL_ALLOW.test(match),
|
|
102
|
-
},
|
|
103
180
|
{
|
|
104
181
|
category: 'Credit card number',
|
|
105
182
|
re: /\b\d(?:[ -]?\d){12,18}\b/g,
|
|
@@ -110,26 +187,41 @@ export const SECRET_PATTERNS = [
|
|
|
110
187
|
return luhnValid(digits);
|
|
111
188
|
},
|
|
112
189
|
},
|
|
190
|
+
{
|
|
191
|
+
category: 'Email',
|
|
192
|
+
re: /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]{1,64}@(?:[A-Za-z0-9-]{1,63}\.){1,8}[A-Za-z]{2,24}\b/g,
|
|
193
|
+
filter: (match) => !EMAIL_ALLOW.test(match),
|
|
194
|
+
},
|
|
113
195
|
];
|
|
114
196
|
|
|
197
|
+
/** Number of secret-shaped matches per category in `text`; never the matched text. */
|
|
198
|
+
export function countSecrets(text) {
|
|
199
|
+
const counts = new Map();
|
|
200
|
+
for (const { category, re, filter } of SECRET_PATTERNS) {
|
|
201
|
+
re.lastIndex = 0;
|
|
202
|
+
let match;
|
|
203
|
+
while ((match = re.exec(text)) !== null) {
|
|
204
|
+
if (match[0].length === 0) re.lastIndex += 1;
|
|
205
|
+
if (filter && !filter(...match)) continue;
|
|
206
|
+
counts.set(category, (counts.get(category) || 0) + 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return counts;
|
|
210
|
+
}
|
|
211
|
+
|
|
115
212
|
/** Returns the category names of every secret-shaped pattern found in `text`. */
|
|
116
213
|
export function findSecretCategories(text) {
|
|
117
214
|
const found = new Set();
|
|
118
215
|
for (const { category, re, filter } of SECRET_PATTERNS) {
|
|
216
|
+
if (found.has(category)) continue;
|
|
119
217
|
re.lastIndex = 0;
|
|
120
218
|
let match;
|
|
121
219
|
while ((match = re.exec(text)) !== null) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (/REDACTED\]/.test(match[0])) {
|
|
125
|
-
if (match[0].length === 0) re.lastIndex += 1;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (!filter || filter(match[0])) {
|
|
220
|
+
if (match[0].length === 0) re.lastIndex += 1;
|
|
221
|
+
if (!filter || filter(...match)) {
|
|
129
222
|
found.add(category);
|
|
130
223
|
break;
|
|
131
224
|
}
|
|
132
|
-
if (match[0].length === 0) re.lastIndex += 1;
|
|
133
225
|
}
|
|
134
226
|
}
|
|
135
227
|
return [...found];
|