bugxhunter 0.12.0 → 0.14.0
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/README.md +261 -39
- package/package.json +1 -1
- package/server/dist/auth.js +4 -0
- package/server/dist/index.js +202 -11
- package/server/dist/recon-batch.js +202 -0
- package/server/dist/recon-driver.js +642 -30
- package/server/dist/recon-evidence.js +53 -0
- package/server/dist/recon-memory.js +227 -0
- package/server/dist/recon-run.js +62 -5
- package/server/dist/recon-session.js +260 -0
- package/server/dist/recon.js +76 -6
- package/server/dist/vault.js +11 -0
- package/server/dist/zip.js +54 -0
- package/web/dist/assets/index-DTJE8gwZ.js +303 -0
- package/web/dist/assets/{index-B1Wq0jKz.css → index-Du7TnY-M.css} +1 -1
- package/web/dist/bxh-extension/background.js +21 -0
- package/web/dist/bxh-extension/manifest.json +11 -0
- package/web/dist/bxh-extension/payload.d.ts +12 -0
- package/web/dist/bxh-extension/payload.js +43 -0
- package/web/dist/bxh-extension/popup.css +14 -0
- package/web/dist/bxh-extension/popup.html +24 -0
- package/web/dist/bxh-extension/popup.js +61 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-0S40kM52.js +0 -303
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A logged-in session for a recon target: the cookies (and, if the app uses one, the
|
|
3
|
+
* Authorization header) of a browser the person logged in with themselves, so the test can
|
|
4
|
+
* go past the login screen, 2FA included.
|
|
5
|
+
*
|
|
6
|
+
* How it gets here: the person asks the runner for a pairing code for one target, pastes it
|
|
7
|
+
* into the BugXHunter browser extension, logs in to the target and presses send. The
|
|
8
|
+
* extension posts the session with the code; the code is single-use, expires in ten
|
|
9
|
+
* minutes, and only accepts a session for the target it was issued for.
|
|
10
|
+
*
|
|
11
|
+
* Where it lives: sealed with the vault key next to the vault (sessions/, on the runner-only
|
|
12
|
+
* volume in Docker), one file per target, nothing about the target in the clear. For a run
|
|
13
|
+
* it is written into the project folder as two files curl can read (a cookie jar and a
|
|
14
|
+
* header file) and removed when the run ends. The values are never put in a prompt; the
|
|
15
|
+
* agent is given the file names. It can still read the files: use a test account.
|
|
16
|
+
*/
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import crypto from "node:crypto";
|
|
20
|
+
import { VAULT_FILE, isInitialised, isUnsealed, openData, sealData } from "./vault.js";
|
|
21
|
+
import { httpError } from "./errors.js";
|
|
22
|
+
import { audit } from "./audit.js";
|
|
23
|
+
import { originOf } from "./recon.js";
|
|
24
|
+
import { isInside, projectPath } from "./opencode.js";
|
|
25
|
+
const dir = () => process.env.OPEN_RUNNER_SESSION_DIR ?? path.join(path.dirname(VAULT_FILE), "sessions");
|
|
26
|
+
export const PAIRING_TTL_MS = 10 * 60_000;
|
|
27
|
+
const MAX_PAIRINGS = 5;
|
|
28
|
+
const MAX_COOKIES = 150;
|
|
29
|
+
const MAX_VALUE = 8192;
|
|
30
|
+
const MAX_TARGETS = 100;
|
|
31
|
+
/** The folder, inside the project, that holds session files: one subfolder per run. */
|
|
32
|
+
export const SESSION_FOLDER = ".bugxhunter";
|
|
33
|
+
const ID = /^[a-f0-9]{24}$/;
|
|
34
|
+
const key = (scope) => {
|
|
35
|
+
const { host, port } = originOf(scope.trim());
|
|
36
|
+
return host ? `${host}:${port}` : undefined;
|
|
37
|
+
};
|
|
38
|
+
/* ─────────────── reading what the extension sent ─────────────── */
|
|
39
|
+
/** A cookie name, per RFC 6265: a token. */
|
|
40
|
+
const NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,256}$/;
|
|
41
|
+
/** No control characters, so a value can never start a new line in the jar or the header file. */
|
|
42
|
+
const CLEAN = /^[^\x00-\x1f\x7f]*$/;
|
|
43
|
+
const HOST = /^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?$/;
|
|
44
|
+
/** Would a cookie with this domain be sent to `host`? */
|
|
45
|
+
function sentTo(host, domain, subdomains) {
|
|
46
|
+
return host === domain || (subdomains && host.endsWith(`.${domain}`));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate a capture and keep only what belongs to the target: cookies the browser would
|
|
50
|
+
* send to its host, with clean names and values. Anything malformed is dropped, and a
|
|
51
|
+
* capture with nothing usable left is refused.
|
|
52
|
+
*/
|
|
53
|
+
export function parseCapture(raw, scope, now = Date.now()) {
|
|
54
|
+
const target = key(scope);
|
|
55
|
+
const host = originOf(scope).host;
|
|
56
|
+
if (!target || !host)
|
|
57
|
+
throw httpError(400, "The pairing code is not for a valid target.");
|
|
58
|
+
const r = (raw && typeof raw === "object" ? raw : {});
|
|
59
|
+
const from = typeof r.origin === "string" ? key(r.origin) : undefined;
|
|
60
|
+
if (from !== target)
|
|
61
|
+
throw httpError(400, `This pairing code is for ${target}. Open that site's tab and send again.`);
|
|
62
|
+
const cookies = [];
|
|
63
|
+
for (const c of Array.isArray(r.cookies) ? r.cookies.slice(0, 1000) : []) {
|
|
64
|
+
const o = (c && typeof c === "object" ? c : {});
|
|
65
|
+
const name = typeof o.name === "string" ? o.name : "";
|
|
66
|
+
const value = typeof o.value === "string" ? o.value : "";
|
|
67
|
+
const rawDomain = typeof o.domain === "string" ? o.domain.trim().toLowerCase() : "";
|
|
68
|
+
const domain = rawDomain.replace(/^\./, "");
|
|
69
|
+
const subdomains = o.hostOnly === false || (o.hostOnly === undefined && rawDomain.startsWith("."));
|
|
70
|
+
const p = typeof o.path === "string" && o.path.startsWith("/") ? o.path : "/";
|
|
71
|
+
if (!NAME.test(name) || value.length > MAX_VALUE || !CLEAN.test(value) || /\s/.test(value))
|
|
72
|
+
continue;
|
|
73
|
+
if (!HOST.test(domain) || !sentTo(host, domain, subdomains))
|
|
74
|
+
continue;
|
|
75
|
+
if (p.length > 1024 || !CLEAN.test(p) || /\s/.test(p))
|
|
76
|
+
continue;
|
|
77
|
+
const expires = typeof o.expirationDate === "number" && Number.isFinite(o.expirationDate) ? Math.floor(o.expirationDate) : undefined;
|
|
78
|
+
if (expires !== undefined && expires * 1000 <= now)
|
|
79
|
+
continue; // already expired
|
|
80
|
+
cookies.push({ name, value, domain, subdomains, path: p, secure: o.secure === true, httpOnly: o.httpOnly === true, ...(expires !== undefined ? { expires } : {}) });
|
|
81
|
+
if (cookies.length >= MAX_COOKIES)
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
const auth = typeof r.authorization === "string" ? r.authorization.trim() : "";
|
|
85
|
+
const authorization = auth && auth.length <= MAX_VALUE && CLEAN.test(auth) ? auth : undefined;
|
|
86
|
+
if (!cookies.length && !authorization)
|
|
87
|
+
throw httpError(400, "Nothing to capture: no cookies for this site and no Authorization header seen. Log in first, then send.");
|
|
88
|
+
return { target, capturedAt: now, cookies, ...(authorization ? { authorization } : {}) };
|
|
89
|
+
}
|
|
90
|
+
const pairings = new Map();
|
|
91
|
+
const digest = (token) => crypto.createHash("sha256").update(token).digest("hex");
|
|
92
|
+
/** A single-use code the extension sends a session with. Good for one target, for ten minutes. */
|
|
93
|
+
export function issuePairing(scope, now = Date.now()) {
|
|
94
|
+
const target = key(scope);
|
|
95
|
+
if (!target)
|
|
96
|
+
throw httpError(400, "scope must be one host or URL");
|
|
97
|
+
if (!isInitialised())
|
|
98
|
+
throw httpError(409, "Set up the vault (sidebar → keys) first: a captured session is encrypted with it.");
|
|
99
|
+
if (!isUnsealed())
|
|
100
|
+
throw httpError(503, "The vault is sealed (locked). Unlock it to capture a session.");
|
|
101
|
+
for (const [k, p] of pairings)
|
|
102
|
+
if (p.expiresAt <= now)
|
|
103
|
+
pairings.delete(k);
|
|
104
|
+
while (pairings.size >= MAX_PAIRINGS)
|
|
105
|
+
pairings.delete(pairings.keys().next().value);
|
|
106
|
+
const token = crypto.randomBytes(24).toString("base64url");
|
|
107
|
+
const expiresAt = now + PAIRING_TTL_MS;
|
|
108
|
+
pairings.set(digest(token), { scope: scope.trim(), target, expiresAt });
|
|
109
|
+
audit("recon.session.pairing", {});
|
|
110
|
+
return { token, target, expiresAt };
|
|
111
|
+
}
|
|
112
|
+
/** The extension's post: check the code, keep the session, and spend the code. */
|
|
113
|
+
export function redeem(token, raw, now = Date.now()) {
|
|
114
|
+
const id = typeof token === "string" && token ? digest(token) : "";
|
|
115
|
+
const p = pairings.get(id);
|
|
116
|
+
if (!p || p.expiresAt <= now) {
|
|
117
|
+
if (p)
|
|
118
|
+
pairings.delete(id);
|
|
119
|
+
audit("recon.session.refused", { reason: "code" });
|
|
120
|
+
throw httpError(401, "That pairing code is not valid or has expired. Get a new one in BugXHunter's recon dialog.");
|
|
121
|
+
}
|
|
122
|
+
const session = parseCapture(raw, p.scope, now); // a bad capture leaves the code usable: fix and resend
|
|
123
|
+
save(session);
|
|
124
|
+
pairings.delete(id);
|
|
125
|
+
audit("recon.session.captured", { cookies: session.cookies.length, authorization: Boolean(session.authorization) });
|
|
126
|
+
return info(session);
|
|
127
|
+
}
|
|
128
|
+
const aad = (id) => `recon-session:${id}:body`;
|
|
129
|
+
const file = (id) => path.join(dir(), `${id}.json`);
|
|
130
|
+
function stored() {
|
|
131
|
+
if (isInitialised() && !isUnsealed())
|
|
132
|
+
throw httpError(503, "The vault is sealed (locked). Unlock it to use a captured session.");
|
|
133
|
+
let names;
|
|
134
|
+
try {
|
|
135
|
+
names = fs.readdirSync(dir());
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
const out = [];
|
|
141
|
+
for (const name of names) {
|
|
142
|
+
const id = name.endsWith(".json") ? name.slice(0, -5) : "";
|
|
143
|
+
if (!ID.test(id))
|
|
144
|
+
continue;
|
|
145
|
+
try {
|
|
146
|
+
const r = JSON.parse(fs.readFileSync(file(id), "utf8"));
|
|
147
|
+
if (r?.v !== 1 || r.id !== id)
|
|
148
|
+
continue;
|
|
149
|
+
const session = JSON.parse(openData(r.body, aad(id)));
|
|
150
|
+
if (typeof session?.target === "string" && Array.isArray(session.cookies))
|
|
151
|
+
out.push({ id, session });
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
if (e.status === 503)
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
function save(session) {
|
|
161
|
+
const all = stored();
|
|
162
|
+
const prev = all.find((s) => s.session.target === session.target);
|
|
163
|
+
if (!prev && all.length >= MAX_TARGETS)
|
|
164
|
+
throw httpError(409, `Sessions for up to ${MAX_TARGETS} targets are kept; forget some first.`);
|
|
165
|
+
const id = prev?.id ?? crypto.randomBytes(12).toString("hex");
|
|
166
|
+
const record = { v: 1, id, body: sealData(JSON.stringify(session), aad(id)) };
|
|
167
|
+
fs.mkdirSync(dir(), { recursive: true, mode: 0o700 });
|
|
168
|
+
const tmp = `${file(id)}.${process.pid}.tmp`;
|
|
169
|
+
fs.writeFileSync(tmp, JSON.stringify(record), { mode: 0o600 });
|
|
170
|
+
fs.renameSync(tmp, file(id));
|
|
171
|
+
}
|
|
172
|
+
function info(s) {
|
|
173
|
+
const expiries = s.cookies.map((c) => c.expires).filter((e) => e !== undefined);
|
|
174
|
+
return {
|
|
175
|
+
target: s.target, capturedAt: s.capturedAt, cookies: s.cookies.length, authorization: Boolean(s.authorization),
|
|
176
|
+
...(expiries.length ? { firstExpiry: Math.min(...expiries) * 1000 } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function find(scope) {
|
|
180
|
+
const target = key(scope);
|
|
181
|
+
return target ? stored().find((s) => s.session.target === target)?.session : undefined;
|
|
182
|
+
}
|
|
183
|
+
/** What is held for a target, without any value. Throws 503 while the vault is locked. */
|
|
184
|
+
export function sessionInfo(scope) {
|
|
185
|
+
const s = find(scope);
|
|
186
|
+
return s ? info(s) : null;
|
|
187
|
+
}
|
|
188
|
+
/** Forget the session held for a target. */
|
|
189
|
+
export function forgetSession(scope) {
|
|
190
|
+
const target = key(scope);
|
|
191
|
+
const hit = target ? stored().find((s) => s.session.target === target) : undefined;
|
|
192
|
+
if (!hit)
|
|
193
|
+
return false;
|
|
194
|
+
fs.rmSync(file(hit.id), { force: true });
|
|
195
|
+
audit("recon.session.forgotten", {});
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/* ─────────────── handing it to a run ─────────────── */
|
|
199
|
+
/**
|
|
200
|
+
* The cookies as a Netscape cookie jar, the format `curl -b <file>` reads: curl then sends
|
|
201
|
+
* each cookie only where its domain, path and secure flag allow, as the browser would.
|
|
202
|
+
* Expired cookies are left out. A session cookie has expiry 0.
|
|
203
|
+
*/
|
|
204
|
+
export function cookieJar(cookies, now = Date.now()) {
|
|
205
|
+
const lines = ["# Netscape HTTP Cookie File", "# Written by BugXHunter for one recon run. Removed when the run ends."];
|
|
206
|
+
for (const c of cookies) {
|
|
207
|
+
if (c.expires !== undefined && c.expires * 1000 <= now)
|
|
208
|
+
continue;
|
|
209
|
+
const domain = `${c.httpOnly ? "#HttpOnly_" : ""}${c.subdomains ? "." : ""}${c.domain}`;
|
|
210
|
+
lines.push([domain, c.subdomains ? "TRUE" : "FALSE", c.path, c.secure ? "TRUE" : "FALSE", String(c.expires ?? 0), c.name, c.value].join("\t"));
|
|
211
|
+
}
|
|
212
|
+
return lines.join("\n") + "\n";
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Write a target's session into the project folder for one run, and say where. Returns
|
|
216
|
+
* undefined when nothing is held for the target (or the vault is locked: a run never
|
|
217
|
+
* fails for want of a session it was only offered). `cleanup` removes the files.
|
|
218
|
+
*/
|
|
219
|
+
export function materialise(scope, directory, now = Date.now()) {
|
|
220
|
+
let s;
|
|
221
|
+
try {
|
|
222
|
+
s = find(scope);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
if (!s)
|
|
228
|
+
return undefined;
|
|
229
|
+
const live = s.cookies.filter((c) => c.expires === undefined || c.expires * 1000 > now);
|
|
230
|
+
if (!live.length && !s.authorization)
|
|
231
|
+
return undefined;
|
|
232
|
+
// One folder per run, so two runs in the same project never share or remove each other's files.
|
|
233
|
+
const rel = `${SESSION_FOLDER}/session-${crypto.randomBytes(4).toString("hex")}`;
|
|
234
|
+
const root = projectPath(directory, "", "dir"); // the project folder itself, symlinks resolved
|
|
235
|
+
const folder = path.join(root, ...rel.split("/"));
|
|
236
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
237
|
+
// The project's contents are the agent's to change: if .bugxhunter was made a link to somewhere
|
|
238
|
+
// else, the session must not follow it out of the project.
|
|
239
|
+
if (!isInside(fs.realpathSync(folder), root)) {
|
|
240
|
+
audit("recon.session.refused", { reason: "folder" });
|
|
241
|
+
throw httpError(400, "The project's .bugxhunter folder points outside the project. Remove it and start again.");
|
|
242
|
+
}
|
|
243
|
+
// Keeps the folder out of the project's changes and commits. Never replaces one that is there.
|
|
244
|
+
try {
|
|
245
|
+
fs.writeFileSync(path.join(path.dirname(folder), ".gitignore"), "*\n", { flag: "wx" });
|
|
246
|
+
}
|
|
247
|
+
catch { /* already there */ }
|
|
248
|
+
const use = { capturedAt: s.capturedAt, cookies: live.length, authorization: Boolean(s.authorization), cleanup: () => fs.rmSync(folder, { recursive: true, force: true }) };
|
|
249
|
+
if (live.length) {
|
|
250
|
+
fs.writeFileSync(path.join(folder, "cookies.txt"), cookieJar(live, now), { mode: 0o600 });
|
|
251
|
+
use.cookieFile = `${rel}/cookies.txt`;
|
|
252
|
+
}
|
|
253
|
+
if (s.authorization) {
|
|
254
|
+
fs.writeFileSync(path.join(folder, "headers.txt"), `Authorization: ${s.authorization}\n`, { mode: 0o600 });
|
|
255
|
+
use.headerFile = `${rel}/headers.txt`;
|
|
256
|
+
}
|
|
257
|
+
audit("recon.session.used", { cookies: live.length, authorization: Boolean(s.authorization) });
|
|
258
|
+
return use;
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=recon-session.js.map
|
package/server/dist/recon.js
CHANGED
|
@@ -24,6 +24,32 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { readFileSync } from "node:fs";
|
|
26
26
|
const ROLES = ["executor", "triage", "verify", "escalate"];
|
|
27
|
+
export const CHAIN_PASS_DEFAULTS = { enabled: true, maxCandidates: 3, maxRoundsPerChain: 3, reservePercent: 15 };
|
|
28
|
+
/** Upper bounds: a profile or a request can lower the caps, never lift them past these. */
|
|
29
|
+
export const CHAIN_PASS_LIMITS = { maxCandidates: 5, maxRoundsPerChain: 5, reservePercent: 50 };
|
|
30
|
+
/** The chain pass settings with the defaults filled in. */
|
|
31
|
+
export function resolveChainPass(c) {
|
|
32
|
+
return { ...CHAIN_PASS_DEFAULTS, ...(c ?? {}) };
|
|
33
|
+
}
|
|
34
|
+
function parseChainPass(raw) {
|
|
35
|
+
if (!raw || typeof raw !== "object")
|
|
36
|
+
return undefined;
|
|
37
|
+
const r = raw;
|
|
38
|
+
const c = {};
|
|
39
|
+
const int = (v, min, max) => (typeof v === "number" && Number.isInteger(v) && v >= min && v <= max ? v : undefined);
|
|
40
|
+
if (typeof r.enabled === "boolean")
|
|
41
|
+
c.enabled = r.enabled;
|
|
42
|
+
const candidates = int(r.maxCandidates, 1, CHAIN_PASS_LIMITS.maxCandidates);
|
|
43
|
+
const rounds = int(r.maxRoundsPerChain, 1, CHAIN_PASS_LIMITS.maxRoundsPerChain);
|
|
44
|
+
const reserve = int(r.reservePercent, 0, CHAIN_PASS_LIMITS.reservePercent);
|
|
45
|
+
if (candidates !== undefined)
|
|
46
|
+
c.maxCandidates = candidates;
|
|
47
|
+
if (rounds !== undefined)
|
|
48
|
+
c.maxRoundsPerChain = rounds;
|
|
49
|
+
if (reserve !== undefined)
|
|
50
|
+
c.reservePercent = reserve;
|
|
51
|
+
return Object.keys(c).length ? c : undefined;
|
|
52
|
+
}
|
|
27
53
|
/** Built-in profiles, cheap -> capable (authored cheapest-role-first so shedding
|
|
28
54
|
* and budget fallback pick the cheapest). `scx/*` is open-weight, `anthropic/*`
|
|
29
55
|
* is Claude. `recon-open` works with no Anthropic key. */
|
|
@@ -64,6 +90,9 @@ export function parseReconHarness(raw) {
|
|
|
64
90
|
h.tools = r.tools;
|
|
65
91
|
if (r.effort === "low" || r.effort === "medium" || r.effort === "high")
|
|
66
92
|
h.effort = r.effort;
|
|
93
|
+
const chainPass = parseChainPass(r.chainPass);
|
|
94
|
+
if (chainPass)
|
|
95
|
+
h.chainPass = chainPass;
|
|
67
96
|
return Object.keys(h).length ? h : undefined;
|
|
68
97
|
}
|
|
69
98
|
export function parseProfile(def) {
|
|
@@ -268,7 +297,8 @@ export function classifyCommand(command, ctx = {}) {
|
|
|
268
297
|
// Shell metacharacters make a string's effect shell-dependent and unpredictable.
|
|
269
298
|
// Reject them all: the allowed subset then runs identically via argv or a shell.
|
|
270
299
|
// (`|` is handled by splitting into stages; `||` leaves an empty stage -> ask.)
|
|
271
|
-
|
|
300
|
+
// The one exception is a query string, the commonest thing a read carries: see queryCharsMasked.
|
|
301
|
+
if (/[\r\n\\$`;&<>(){}[\]*?!~]/.test(queryCharsMasked(command)))
|
|
272
302
|
return "ask";
|
|
273
303
|
if (command.includes("||"))
|
|
274
304
|
return "ask";
|
|
@@ -284,6 +314,33 @@ export function classifyCommand(command, ctx = {}) {
|
|
|
284
314
|
}
|
|
285
315
|
return "allow";
|
|
286
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* `command` with the two characters of a query string blanked where a shell reads them as
|
|
319
|
+
* plain text, so `curl "http://target/search?q=a&page=2"` is not held up for a person:
|
|
320
|
+
* - `?` inside quotes of either kind. Unquoted it is a glob.
|
|
321
|
+
* - `&` inside DOUBLE quotes only. Unquoted it backgrounds or chains; inside single quotes
|
|
322
|
+
* it is literal to a POSIX shell but not to cmd.exe, which does not treat `'` as a quote.
|
|
323
|
+
* Everything else the metacharacter test refuses stays refused inside quotes too (`$`, a
|
|
324
|
+
* backtick, a backslash, `;`, `|`, brackets). Quotes are read over the whole command, as
|
|
325
|
+
* the shell reads them, so a character blanked here is one the shell will not act on.
|
|
326
|
+
*/
|
|
327
|
+
function queryCharsMasked(command) {
|
|
328
|
+
let out = "", q = null;
|
|
329
|
+
for (const c of command) {
|
|
330
|
+
if (q) {
|
|
331
|
+
if (c === q)
|
|
332
|
+
q = null;
|
|
333
|
+
else if (c === "?" || (c === "&" && q === '"')) {
|
|
334
|
+
out += "_";
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if (c === '"' || c === "'")
|
|
339
|
+
q = c;
|
|
340
|
+
out += c;
|
|
341
|
+
}
|
|
342
|
+
return out;
|
|
343
|
+
}
|
|
287
344
|
/** Split a stage into argv, honouring single/double quotes. null = unbalanced (ask). */
|
|
288
345
|
function tokenize(s) {
|
|
289
346
|
const out = [];
|
|
@@ -338,6 +395,11 @@ function stageAllow(argv, isFirst, ctx) {
|
|
|
338
395
|
function curlAllow(args, ctx) {
|
|
339
396
|
if (!ctx.scopeHost)
|
|
340
397
|
return "ask";
|
|
398
|
+
// -v prints the request headers: with the captured session that would put its values in the transcript.
|
|
399
|
+
const usesSession = args.some((a) => (ctx.cookieFile && a === ctx.cookieFile) || (ctx.headerFile && a === `@${ctx.headerFile}`)
|
|
400
|
+
|| (ctx.cookieFile && a === `--cookie=${ctx.cookieFile}`) || (ctx.headerFile && a === `--header=@${ctx.headerFile}`));
|
|
401
|
+
if (usesSession && args.some((a) => a === "--verbose" || (/^-[A-Za-z0-9#]+$/.test(a) && a.includes("v"))))
|
|
402
|
+
return "ask";
|
|
341
403
|
let url = false;
|
|
342
404
|
for (let i = 0; i < args.length; i++) {
|
|
343
405
|
const a = args[i];
|
|
@@ -356,9 +418,9 @@ function curlAllow(args, ctx) {
|
|
|
356
418
|
const v = eq >= 0 ? a.slice(eq + 1) : args[++i];
|
|
357
419
|
if (v === undefined)
|
|
358
420
|
return "ask";
|
|
359
|
-
if (flag === "--header" && v.startsWith("@"))
|
|
421
|
+
if (flag === "--header" && v.startsWith("@") && !isSessionFile(v.slice(1), ctx.headerFile))
|
|
360
422
|
return "ask"; // @file read
|
|
361
|
-
if (flag === "--cookie" && !v.includes("="))
|
|
423
|
+
if (flag === "--cookie" && !v.includes("=") && !isSessionFile(v, ctx.cookieFile))
|
|
362
424
|
return "ask"; // no "=" -> curl reads it as a cookie FILE
|
|
363
425
|
continue;
|
|
364
426
|
}
|
|
@@ -371,9 +433,9 @@ function curlAllow(args, ctx) {
|
|
|
371
433
|
const v = args[++i];
|
|
372
434
|
if (v === undefined)
|
|
373
435
|
return "ask";
|
|
374
|
-
if (a === "-H" && v.startsWith("@"))
|
|
436
|
+
if (a === "-H" && v.startsWith("@") && !isSessionFile(v.slice(1), ctx.headerFile))
|
|
375
437
|
return "ask";
|
|
376
|
-
if (a === "-b" && !v.includes("="))
|
|
438
|
+
if (a === "-b" && !v.includes("=") && !isSessionFile(v, ctx.cookieFile))
|
|
377
439
|
return "ask"; // no "=" -> a cookie FILE
|
|
378
440
|
continue;
|
|
379
441
|
}
|
|
@@ -388,6 +450,14 @@ function curlAllow(args, ctx) {
|
|
|
388
450
|
}
|
|
389
451
|
return url ? "allow" : "ask";
|
|
390
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* The one file a run's curl may read: the captured session the runner wrote for it, named
|
|
455
|
+
* exactly as the runner named it (no other spelling of the path). The URL check still
|
|
456
|
+
* applies, so the session only ever goes to the in-scope origin.
|
|
457
|
+
*/
|
|
458
|
+
function isSessionFile(arg, allowed) {
|
|
459
|
+
return Boolean(allowed) && arg === allowed;
|
|
460
|
+
}
|
|
391
461
|
/** True if `arg` is an http(s) URL for exactly the in-scope origin, no userinfo. */
|
|
392
462
|
function okUrl(arg, ctx) {
|
|
393
463
|
let u;
|
|
@@ -643,7 +713,7 @@ const STATUS_RULE = `End every turn with exactly one final line: "${STATUS_LINE}
|
|
|
643
713
|
export const reconAgents = () => ({
|
|
644
714
|
recon: subagent(modelFor("executor"), "Supervised recon/autopwn executor: enumerate the in-scope target, hypothesise weaknesses, test them with low-impact probes, and hand candidates to recon-verify. Read-only shell; never mutates state without an approved step.", "You are the EXECUTOR in a supervised penetration test of a single, explicitly in-scope target. Work one hypothesis at a time: enumerate -> hypothesise a specific weakness (name the OWASP/API Top 10 or WSTG id) -> test it with the smallest, lowest-impact probe that settles it -> record exactly what you observed. Prefer read-only probes (GET, HEAD, nmap -sV, DNS, reading saved responses). Anything that changes state (POST that writes, PUT, PATCH, DELETE, file writes) is a RED LINE: stop and hand it to the human for approval, with the one request you want to run and why. When you believe you have a finding, call the recon-verify subagent with the evidence — do NOT promote it yourself. Stay strictly inside the declared scope. If you are stuck after a couple of tries, say so plainly rather than widening scope. " + STATUS_RULE, executorPermission(), "all"),
|
|
645
715
|
"recon-triage": subagent(modelFor("triage"), "Fast, cheap triage of tool output: is this response interesting, already seen, or noise? Returns a one-line verdict and the single most promising next direction.", "You triage raw tool output for the executor. In two or three sentences: is there anything security-relevant here, have we effectively seen it already, and what is the single most promising next probe? Do not run tools or speculate beyond the output you were given.", READ_ONLY),
|
|
646
|
-
"recon-verify": subagent(modelFor("verify"), "Adversarially verifies one candidate finding against the declared environment and the standards catalogue, assigns severity, and flags config-dependent findings before they are promoted.", "You VERIFY one candidate finding. Reject it unless there is concrete reproduction evidence (the request/command and the response that proves it). Assign severity with the project's rubric and cite the matching OWASP/API/WSTG id. CRITICAL: compare the finding against the declared environment fidelity — if it depends on a setting that differs from production (an auth flag off, a debug mode on, seed data), mark it config-dependent and say exactly what to re-test against production. Output exactly one fenced json block and nothing after it: {\"title\": \"short name of the finding\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"repro\": \"the request or command and the response that proves it\", \"prod_caveat\": \"what to re-test against production, or an empty string\"}.", READ_ONLY),
|
|
716
|
+
"recon-verify": subagent(modelFor("verify"), "Adversarially verifies one candidate finding, one attack path that builds on findings, or one retest of an earlier finding, against the declared environment and the standards catalogue, assigns severity, and flags config-dependent findings before they are promoted.", "You VERIFY one candidate finding. Reject it unless there is concrete reproduction evidence (the request/command and the response that proves it). Assign severity with the project's rubric and cite the matching OWASP/API/WSTG id. CRITICAL: compare the finding against the declared environment fidelity — if it depends on a setting that differs from production (an auth flag off, a debug mode on, seed data), mark it config-dependent and say exactly what to re-test against production. Output exactly one fenced json block and nothing after it: {\"title\": \"short name of the finding\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"repro\": \"the request or command and the response that proves it\", \"quotes\": [\"one to three short excerpts of the response that prove it, copied character for character\"], \"prod_caveat\": \"what to re-test against production, or an empty string\"}. The quotes are checked by the program against what the commands of this run really returned, so copy them exactly from the response you were shown, never from memory or from a summary, and give an empty list if you were not shown the response itself. When you are handed an ATTACK PATH (several steps that build on findings named F1, F2 and so on) instead of one finding, rule on the path as a whole. Reject it unless every step has its own request or command and response, and the evidence shows that what one step returned was used in the next: steps that each work but do not connect are not a path. A path that stops at a step that could not be shown is partial, never demonstrated. Rate severity on what the attacker ends up with, and apply the same environment check. For a path, output the block in this form instead: {\"kind\": \"chain\", \"title\": \"short name of the path\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"impact\": \"what the attacker ends up with\", \"links\": [\"F1\", \"F3\"], \"steps\": [{\"action\": \"what was done\", \"evidence\": \"the request or command and the response\"}], \"status\": \"demonstrated\" | \"partial\", \"blocked_at\": the number of the step it stopped at, or null, \"blocked_why\": \"why it stopped, or an empty string\", \"prod_caveat\": \"what to re-test against production, or an empty string\"}. When you are handed a RETEST (a finding an earlier run verified, with what the same request returns now), rule on whether it still holds, and on nothing else. It is \"still-reproducible\" only if the response now proves the weakness as it did then. It is \"fixed\" only if the same request now gets a response that shows the weakness is gone (a refusal, a corrected value): an error, a timeout, a missing page or a logged-out answer is not a fix. Anything else is \"cannot-confirm\". For a retest, output the block in this form instead: {\"kind\": \"retest\", \"title\": \"the finding's title as given\", \"result\": \"still-reproducible\" | \"fixed\" | \"cannot-confirm\", \"evidence\": \"the request or command and the response now\", \"quotes\": [\"one to three short excerpts of the response now, copied character for character\"], \"note\": \"one line on why\"}.", READ_ONLY),
|
|
647
717
|
"recon-escalate": subagent(modelFor("escalate"), "Frontier escalation: called only when the executor is stuck or a High/Critical candidate needs deep adversarial review or multi-step exploit-chain reasoning. Read-only.", "You are the escalation reviewer, called rarely and only for hard cases: a stuck executor, or a High/Critical candidate that must survive adversarial scrutiny before it is reported. Reason carefully about exploitability and chaining, demand evidence, and be willing to downgrade or reject. Do not run tools; reason over what you are given and return a precise recommendation.", READ_ONLY),
|
|
648
718
|
});
|
|
649
719
|
//# sourceMappingURL=recon.js.map
|
package/server/dist/vault.js
CHANGED
|
@@ -238,6 +238,17 @@ export function unseal(dekB64) {
|
|
|
238
238
|
dek = key;
|
|
239
239
|
lastUse = Date.now();
|
|
240
240
|
audit("vault.unsealed", {});
|
|
241
|
+
for (const listener of unsealListeners) {
|
|
242
|
+
try {
|
|
243
|
+
listener();
|
|
244
|
+
}
|
|
245
|
+
catch { /* a listener's failure must not fail the unlock */ }
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const unsealListeners = [];
|
|
249
|
+
/** Run `listener` whenever the vault is unlocked: for work that had to wait for the key. */
|
|
250
|
+
export function onUnsealed(listener) {
|
|
251
|
+
unsealListeners.push(listener);
|
|
241
252
|
}
|
|
242
253
|
const sealListeners = [];
|
|
243
254
|
/** Run `listener` whenever the vault is sealed: for secrets held outside it that a lock must drop too. */
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal zip writer (stored, no compression) for the handful of small text files the
|
|
3
|
+
* browser extension is made of. Enough for "download, unzip, load unpacked"; not a
|
|
4
|
+
* general-purpose archiver.
|
|
5
|
+
*/
|
|
6
|
+
import zlib from "node:zlib";
|
|
7
|
+
// A fixed date (1 Jan 2026) so the same files always give the same archive.
|
|
8
|
+
const DOS_TIME = 0;
|
|
9
|
+
const DOS_DATE = ((2026 - 1980) << 9) | (1 << 5) | 1;
|
|
10
|
+
export function zip(entries) {
|
|
11
|
+
const parts = [];
|
|
12
|
+
const central = [];
|
|
13
|
+
let offset = 0;
|
|
14
|
+
for (const e of entries) {
|
|
15
|
+
const name = Buffer.from(e.name.replace(/\\/g, "/"), "utf8");
|
|
16
|
+
const crc = zlib.crc32(e.data);
|
|
17
|
+
const local = Buffer.alloc(30);
|
|
18
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
19
|
+
local.writeUInt16LE(20, 4); // version needed
|
|
20
|
+
local.writeUInt16LE(0x0800, 6); // names are UTF-8
|
|
21
|
+
local.writeUInt16LE(0, 8); // stored
|
|
22
|
+
local.writeUInt16LE(DOS_TIME, 10);
|
|
23
|
+
local.writeUInt16LE(DOS_DATE, 12);
|
|
24
|
+
local.writeUInt32LE(crc, 14);
|
|
25
|
+
local.writeUInt32LE(e.data.length, 18);
|
|
26
|
+
local.writeUInt32LE(e.data.length, 22);
|
|
27
|
+
local.writeUInt16LE(name.length, 26);
|
|
28
|
+
parts.push(local, name, e.data);
|
|
29
|
+
const head = Buffer.alloc(46);
|
|
30
|
+
head.writeUInt32LE(0x02014b50, 0);
|
|
31
|
+
head.writeUInt16LE(20, 4);
|
|
32
|
+
head.writeUInt16LE(20, 6);
|
|
33
|
+
head.writeUInt16LE(0x0800, 8);
|
|
34
|
+
head.writeUInt16LE(0, 10);
|
|
35
|
+
head.writeUInt16LE(DOS_TIME, 12);
|
|
36
|
+
head.writeUInt16LE(DOS_DATE, 14);
|
|
37
|
+
head.writeUInt32LE(crc, 16);
|
|
38
|
+
head.writeUInt32LE(e.data.length, 20);
|
|
39
|
+
head.writeUInt32LE(e.data.length, 24);
|
|
40
|
+
head.writeUInt16LE(name.length, 28);
|
|
41
|
+
head.writeUInt32LE(offset, 42);
|
|
42
|
+
central.push(head, name);
|
|
43
|
+
offset += local.length + name.length + e.data.length;
|
|
44
|
+
}
|
|
45
|
+
const dir = Buffer.concat(central);
|
|
46
|
+
const end = Buffer.alloc(22);
|
|
47
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
48
|
+
end.writeUInt16LE(entries.length, 8);
|
|
49
|
+
end.writeUInt16LE(entries.length, 10);
|
|
50
|
+
end.writeUInt32LE(dir.length, 12);
|
|
51
|
+
end.writeUInt32LE(offset, 16);
|
|
52
|
+
return Buffer.concat([...parts, dir, end]);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=zip.js.map
|