sentinelayer-cli 0.1.2 → 0.3.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 +996 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +62 -54
- package/src/agents/jules/config/definition.js +209 -209
- package/src/agents/jules/config/system-prompt.js +175 -175
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +377 -377
- package/src/agents/jules/loop.js +367 -367
- package/src/agents/jules/pulse.js +319 -319
- package/src/agents/jules/stream.js +186 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +308 -308
- package/src/agents/jules/tools/auth-audit.js +226 -222
- package/src/agents/jules/tools/dispatch.js +327 -327
- package/src/agents/jules/tools/file-edit.js +180 -180
- package/src/agents/jules/tools/file-read.js +100 -100
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +168 -168
- package/src/agents/jules/tools/grep.js +228 -228
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +161 -161
- package/src/agents/jules/tools/runtime-audit.js +493 -493
- package/src/agents/jules/tools/shell.js +383 -383
- package/src/ai/aidenid.js +972 -945
- package/src/ai/client.js +508 -508
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/http.js +113 -113
- package/src/auth/service.js +891 -848
- package/src/auth/session-store.js +359 -345
- package/src/cli.js +252 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1337
- package/src/commands/ai/provision-governance.js +1272 -1246
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1166 -1166
- package/src/commands/auth.js +375 -366
- package/src/commands/chat.js +191 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +10 -10
- package/src/commands/mcp.js +461 -404
- package/src/commands/omargate.js +15 -15
- package/src/commands/persona.js +20 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +866 -788
- package/src/commands/spec.js +716 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +510 -510
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tracker.js +171 -171
- package/src/daemon/artifact-lineage.js +534 -534
- package/src/daemon/assignment-ledger.js +770 -770
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +626 -626
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/jira-lifecycle.js +632 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/watchdog.js +971 -971
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +918 -918
- package/src/legacy-cli.js +2548 -2435
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +118 -106
- package/src/review/ai-review.js +669 -669
- package/src/review/local-review.js +1284 -1284
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -0
- package/src/scaffold/templates.js +150 -0
- package/src/scan/generator.js +418 -351
- package/src/scan/gh-secrets.js +107 -0
- package/src/spec/generator.js +519 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +576 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/sync.js +96 -59
- package/src/ui/markdown.js +220 -220
|
@@ -1,222 +1,226 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import { randomUUID } from "node:crypto";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Jules Tanaka — Authenticated Page Audit
|
|
9
|
-
*
|
|
10
|
-
* Provisions an AIdenID ephemeral identity, uses Playwright to log in,
|
|
11
|
-
* then inspects authenticated pages (DevTools console, DOM, headers).
|
|
12
|
-
* Falls back gracefully when AIdenID or Playwright unavailable.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export function authAudit(input) {
|
|
16
|
-
if (!AUTH_OPS.has(input.operation)) {
|
|
17
|
-
throw new AuthAuditError("Unknown operation: " + input.operation + ". Valid: " + [...AUTH_OPS].join(", "));
|
|
18
|
-
}
|
|
19
|
-
return AUTH_DISPATCH[input.operation](input);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const AUTH_OPS = new Set([
|
|
23
|
-
"provision_test_identity",
|
|
24
|
-
"authenticated_page_check",
|
|
25
|
-
"check_auth_flow_security",
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const AUTH_DISPATCH = {
|
|
29
|
-
provision_test_identity: provisionTestIdentity,
|
|
30
|
-
authenticated_page_check: authenticatedPageCheck,
|
|
31
|
-
check_auth_flow_security: checkAuthFlowSecurity,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
async function provisionTestIdentity(input) {
|
|
35
|
-
try {
|
|
36
|
-
const { provisionEmailIdentity, resolveAidenIdCredentials } = await import("../../../ai/aidenid.js");
|
|
37
|
-
const creds = resolveAidenIdCredentials();
|
|
38
|
-
if (!creds.apiKey) {
|
|
39
|
-
return { available: false, reason: "AIdenID API key not configured (set AIDENID_API_KEY)" };
|
|
40
|
-
}
|
|
41
|
-
const result = await provisionEmailIdentity({
|
|
42
|
-
apiUrl: creds.apiUrl, apiKey: creds.apiKey,
|
|
43
|
-
tags: ["jules-audit", "frontend-test"],
|
|
44
|
-
ttlSeconds: 3600, dryRun: input.execute !== true,
|
|
45
|
-
});
|
|
46
|
-
return { available: true, dryRun: input.execute !== true, identity: result.identity || result };
|
|
47
|
-
} catch (err) {
|
|
48
|
-
return { available: false, reason: "AIdenID provisioning failed: " + err.message };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Run Playwright to authenticate and inspect the page.
|
|
54
|
-
* - URLs and credentials passed ONLY via env vars (no string interpolation)
|
|
55
|
-
* - Auth verification checks URL change + cookie presence (not just click success)
|
|
56
|
-
* - Console errors redacted to prevent sensitive data leakage
|
|
57
|
-
* - Cookie values never captured (names + flags only)
|
|
58
|
-
* - Temp script cleanup in finally block (not just success path)
|
|
59
|
-
*/
|
|
60
|
-
function authenticatedPageCheck(input) {
|
|
61
|
-
const url = input.url;
|
|
62
|
-
if (!url) throw new AuthAuditError("authenticated_page_check requires url");
|
|
63
|
-
if (!isValidUrl(url)) throw new AuthAuditError("Invalid URL: " + url);
|
|
64
|
-
|
|
65
|
-
const loginUrl = input.loginUrl || url + "/login";
|
|
66
|
-
let scriptPath = null;
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
scriptPath = secureTempFile("sl-auth-audit-" + randomUUID().slice(0, 8) + ".cjs");
|
|
70
|
-
fs.writeFileSync(scriptPath, PLAYWRIGHT_AUTH_SCRIPT);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return { available:
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
await page.
|
|
136
|
-
await page.
|
|
137
|
-
await page.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
'
|
|
177
|
-
'
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (headers["
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Jules Tanaka — Authenticated Page Audit
|
|
9
|
+
*
|
|
10
|
+
* Provisions an AIdenID ephemeral identity, uses Playwright to log in,
|
|
11
|
+
* then inspects authenticated pages (DevTools console, DOM, headers).
|
|
12
|
+
* Falls back gracefully when AIdenID or Playwright unavailable.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function authAudit(input) {
|
|
16
|
+
if (!AUTH_OPS.has(input.operation)) {
|
|
17
|
+
throw new AuthAuditError("Unknown operation: " + input.operation + ". Valid: " + [...AUTH_OPS].join(", "));
|
|
18
|
+
}
|
|
19
|
+
return AUTH_DISPATCH[input.operation](input);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const AUTH_OPS = new Set([
|
|
23
|
+
"provision_test_identity",
|
|
24
|
+
"authenticated_page_check",
|
|
25
|
+
"check_auth_flow_security",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
const AUTH_DISPATCH = {
|
|
29
|
+
provision_test_identity: provisionTestIdentity,
|
|
30
|
+
authenticated_page_check: authenticatedPageCheck,
|
|
31
|
+
check_auth_flow_security: checkAuthFlowSecurity,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
async function provisionTestIdentity(input) {
|
|
35
|
+
try {
|
|
36
|
+
const { provisionEmailIdentity, resolveAidenIdCredentials } = await import("../../../ai/aidenid.js");
|
|
37
|
+
const creds = await resolveAidenIdCredentials();
|
|
38
|
+
if (!creds.apiKey) {
|
|
39
|
+
return { available: false, reason: "AIdenID API key not configured (set AIDENID_API_KEY)" };
|
|
40
|
+
}
|
|
41
|
+
const result = await provisionEmailIdentity({
|
|
42
|
+
apiUrl: creds.apiUrl, apiKey: creds.apiKey,
|
|
43
|
+
tags: ["jules-audit", "frontend-test"],
|
|
44
|
+
ttlSeconds: 3600, dryRun: input.execute !== true,
|
|
45
|
+
});
|
|
46
|
+
return { available: true, dryRun: input.execute !== true, identity: result.identity || result };
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return { available: false, reason: "AIdenID provisioning failed: " + err.message };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Run Playwright to authenticate and inspect the page.
|
|
54
|
+
* - URLs and credentials passed ONLY via env vars (no string interpolation)
|
|
55
|
+
* - Auth verification checks URL change + cookie presence (not just click success)
|
|
56
|
+
* - Console errors redacted to prevent sensitive data leakage
|
|
57
|
+
* - Cookie values never captured (names + flags only)
|
|
58
|
+
* - Temp script cleanup in finally block (not just success path)
|
|
59
|
+
*/
|
|
60
|
+
async function authenticatedPageCheck(input) {
|
|
61
|
+
const url = input.url;
|
|
62
|
+
if (!url) throw new AuthAuditError("authenticated_page_check requires url");
|
|
63
|
+
if (!isValidUrl(url)) throw new AuthAuditError("Invalid URL: " + url);
|
|
64
|
+
|
|
65
|
+
const loginUrl = input.loginUrl || url + "/login";
|
|
66
|
+
let scriptPath = null;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
scriptPath = secureTempFile("sl-auth-audit-" + randomUUID().slice(0, 8) + ".cjs");
|
|
70
|
+
fs.writeFileSync(scriptPath, PLAYWRIGHT_AUTH_SCRIPT);
|
|
71
|
+
|
|
72
|
+
// Use scrubbed env — strip API keys/tokens from child process
|
|
73
|
+
const { buildScrubbedEnv } = await import("./shell.js");
|
|
74
|
+
const env = {
|
|
75
|
+
...buildScrubbedEnv(),
|
|
76
|
+
SL_AUDIT_TARGET_URL: url,
|
|
77
|
+
SL_AUDIT_LOGIN_URL: loginUrl,
|
|
78
|
+
SL_AUDIT_TEST_EMAIL: input.email || "",
|
|
79
|
+
SL_AUDIT_TEST_PASSWORD: input.password || "",
|
|
80
|
+
SL_AUDIT_EMAIL_FIELD: input.emailField || "",
|
|
81
|
+
SL_AUDIT_PASSWORD_FIELD: input.passwordField || "",
|
|
82
|
+
SL_AUDIT_SUBMIT_SELECTOR: input.submitSelector || "",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const output = execFileSync("node", [scriptPath], {
|
|
86
|
+
encoding: "utf-8", timeout: 60000,
|
|
87
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
88
|
+
env,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const result = JSON.parse(output.trim());
|
|
92
|
+
const findings = [];
|
|
93
|
+
for (const cookie of (result.cookies || [])) {
|
|
94
|
+
if (cookie.sensitive && !cookie.httpOnly) {
|
|
95
|
+
findings.push({ severity: "P1", title: "Sensitive cookie '" + cookie.name + "' missing httpOnly flag", file: url });
|
|
96
|
+
}
|
|
97
|
+
if (cookie.sensitive && !cookie.secure) {
|
|
98
|
+
findings.push({ severity: "P1", title: "Sensitive cookie '" + cookie.name + "' missing Secure flag", file: url });
|
|
99
|
+
}
|
|
100
|
+
if (cookie.sensitive && cookie.sameSite === "None") {
|
|
101
|
+
findings.push({ severity: "P2", title: "Sensitive cookie '" + cookie.name + "' has SameSite=None", file: url });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { available: true, method: "playwright", findings, ...result };
|
|
105
|
+
} catch (err) {
|
|
106
|
+
return { available: false, reason: "Playwright auth audit failed: " + err.message };
|
|
107
|
+
} finally {
|
|
108
|
+
// Clean up temp script AND its mkdtemp parent directory
|
|
109
|
+
if (scriptPath) {
|
|
110
|
+
try { fs.unlinkSync(scriptPath); } catch { /* best effort */ }
|
|
111
|
+
try { fs.rmdirSync(path.dirname(scriptPath)); } catch { /* best effort — dir may not be empty */ }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Playwright script as a constant — no string interpolation of URLs/credentials.
|
|
117
|
+
// All dynamic values come from environment variables at runtime.
|
|
118
|
+
const PLAYWRIGHT_AUTH_SCRIPT = `
|
|
119
|
+
const { chromium } = require('playwright');
|
|
120
|
+
(async () => {
|
|
121
|
+
const targetUrl = process.env.SL_AUDIT_TARGET_URL;
|
|
122
|
+
const loginUrl = process.env.SL_AUDIT_LOGIN_URL;
|
|
123
|
+
const email = process.env.SL_AUDIT_TEST_EMAIL;
|
|
124
|
+
const password = process.env.SL_AUDIT_TEST_PASSWORD;
|
|
125
|
+
const emailSelector = process.env.SL_AUDIT_EMAIL_FIELD || 'input[type="email"]';
|
|
126
|
+
const passwordSelector = process.env.SL_AUDIT_PASSWORD_FIELD || 'input[type="password"]';
|
|
127
|
+
const submitSelector = process.env.SL_AUDIT_SUBMIT_SELECTOR || 'button[type="submit"]';
|
|
128
|
+
|
|
129
|
+
const browser = await chromium.launch({ headless: true });
|
|
130
|
+
const page = await browser.newPage();
|
|
131
|
+
const results = { authenticated: false, errors: [], cookies: [], headers: {}, domStats: {} };
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
if (email && password && loginUrl) {
|
|
135
|
+
await page.goto(loginUrl, { waitUntil: 'networkidle', timeout: 30000 });
|
|
136
|
+
await page.fill(emailSelector, email);
|
|
137
|
+
await page.fill(passwordSelector, password);
|
|
138
|
+
await page.click(submitSelector);
|
|
139
|
+
await page.waitForNavigation({ waitUntil: 'networkidle', timeout: 15000 }).catch(() => {});
|
|
140
|
+
// P2 fix: verify auth by checking URL change + session cookie presence
|
|
141
|
+
const currentUrl = page.url();
|
|
142
|
+
const postCookies = await page.context().cookies();
|
|
143
|
+
results.authenticated = currentUrl !== loginUrl || postCookies.some(c => /session|token|auth/i.test(c.name));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await page.goto(targetUrl, { waitUntil: 'networkidle', timeout: 30000 });
|
|
147
|
+
|
|
148
|
+
// P2 fix: redact sensitive content from console errors
|
|
149
|
+
page.on('console', msg => {
|
|
150
|
+
if (msg.type() === 'error') {
|
|
151
|
+
const text = (msg.text() || '').slice(0, 200).replace(/Bearer\\s+\\S+/gi, 'Bearer [REDACTED]').replace(/token[=:]\\S+/gi, 'token=[REDACTED]');
|
|
152
|
+
results.errors.push({ text });
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// P2 fix: capture cookie names + flags only, never values
|
|
157
|
+
const cookies = await page.context().cookies();
|
|
158
|
+
results.cookies = cookies.map(c => ({
|
|
159
|
+
name: c.name, domain: c.domain,
|
|
160
|
+
httpOnly: c.httpOnly, secure: c.secure,
|
|
161
|
+
sameSite: c.sameSite,
|
|
162
|
+
sensitive: /session|token|auth|jwt/i.test(c.name),
|
|
163
|
+
}));
|
|
164
|
+
|
|
165
|
+
results.domStats = await page.evaluate(() => ({
|
|
166
|
+
title: document.title,
|
|
167
|
+
nodeCount: document.querySelectorAll('*').length,
|
|
168
|
+
formCount: document.querySelectorAll('form').length,
|
|
169
|
+
inputCount: document.querySelectorAll('input').length,
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
const response = await page.goto(targetUrl, { waitUntil: 'commit', timeout: 10000 }).catch(() => null);
|
|
173
|
+
if (response) {
|
|
174
|
+
const h = response.headers();
|
|
175
|
+
results.headers = {
|
|
176
|
+
'content-security-policy': h['content-security-policy'] || null,
|
|
177
|
+
'x-frame-options': h['x-frame-options'] || null,
|
|
178
|
+
'strict-transport-security': h['strict-transport-security'] || null,
|
|
179
|
+
'cache-control': h['cache-control'] || null,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
} catch (err) {
|
|
183
|
+
results.errors.push({ text: 'Navigation error: ' + (err.message || '').slice(0, 100) });
|
|
184
|
+
} finally {
|
|
185
|
+
try { console.log(JSON.stringify(results)); } catch { /* output failure non-blocking */ }
|
|
186
|
+
await browser.close();
|
|
187
|
+
}
|
|
188
|
+
})();
|
|
189
|
+
`;
|
|
190
|
+
|
|
191
|
+
function checkAuthFlowSecurity(input) {
|
|
192
|
+
const loginUrl = input.loginUrl || input.url;
|
|
193
|
+
if (!loginUrl) throw new AuthAuditError("check_auth_flow_security requires loginUrl or url");
|
|
194
|
+
if (!isValidUrl(loginUrl)) throw new AuthAuditError("Invalid URL: " + loginUrl);
|
|
195
|
+
|
|
196
|
+
const findings = [];
|
|
197
|
+
try {
|
|
198
|
+
const output = execFileSync("curl", ["-sI", "-L", "--max-time", "10", loginUrl], {
|
|
199
|
+
encoding: "utf-8", timeout: 15000, stdio: ["pipe", "pipe", "pipe"],
|
|
200
|
+
});
|
|
201
|
+
const headers = {};
|
|
202
|
+
for (const line of output.split("\n")) {
|
|
203
|
+
const idx = line.indexOf(":");
|
|
204
|
+
if (idx > 0) headers[line.slice(0, idx).trim().toLowerCase()] = line.slice(idx + 1).trim();
|
|
205
|
+
}
|
|
206
|
+
if (!headers["strict-transport-security"]) findings.push({ severity: "P1", title: "Login page missing HSTS header", file: loginUrl });
|
|
207
|
+
if (!headers["content-security-policy"]) findings.push({ severity: "P2", title: "Login page missing CSP header", file: loginUrl });
|
|
208
|
+
if (headers["x-powered-by"]) findings.push({ severity: "P2", title: "Login page exposes X-Powered-By: " + headers["x-powered-by"], file: loginUrl });
|
|
209
|
+
} catch (err) {
|
|
210
|
+
return { available: false, loginUrl, findings, reason: "curl failed: " + err.message };
|
|
211
|
+
}
|
|
212
|
+
return { available: true, loginUrl, findings };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function isValidUrl(url) {
|
|
216
|
+
try { const p = new URL(url); return p.protocol === "http:" || p.protocol === "https:"; } catch { return false; }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function secureTempFile(name) {
|
|
220
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "sl-auth-"));
|
|
221
|
+
return path.join(dir, name);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class AuthAuditError extends Error {
|
|
225
|
+
constructor(message) { super(message); this.name = "AuthAuditError"; }
|
|
226
|
+
}
|