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
package/src/scan/generator.js
CHANGED
|
@@ -1,351 +1,418 @@
|
|
|
1
|
-
import YAML from "yaml";
|
|
2
|
-
|
|
3
|
-
export const DEFAULT_SCAN_WORKFLOW_PATH = ".github/workflows/omar-gate.yml";
|
|
4
|
-
export const DEFAULT_SCAN_SECRET_NAME = "SENTINELAYER_TOKEN";
|
|
5
|
-
export const SENTINELAYER_ACTION_REF = "mrrCarter/sentinelayer-v1-action@55a2c158f637d7d92e26ab0ef3ba81db791da4be";
|
|
6
|
-
export const SUPPORTED_E2E_HINTS = Object.freeze(["auto", "yes", "no"]);
|
|
7
|
-
export const SUPPORTED_PLAYWRIGHT_MODES = Object.freeze(["auto", "off", "baseline", "audit"]);
|
|
8
|
-
|
|
9
|
-
const CHECKOUT_ACTION_REF = "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683";
|
|
10
|
-
const SETUP_NODE_ACTION_REF = "actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020";
|
|
11
|
-
const SECRET_NAME_REGEX = /^[A-Z][A-Z0-9_]*$/;
|
|
12
|
-
const REPO_SLUG_REGEX = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
13
|
-
|
|
14
|
-
function normalizeChoice(rawValue, allowed, label) {
|
|
15
|
-
const normalized = String(rawValue || "").trim().toLowerCase();
|
|
16
|
-
if (!normalized) {
|
|
17
|
-
return allowed[0];
|
|
18
|
-
}
|
|
19
|
-
if (!allowed.includes(normalized)) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Invalid ${label} '${rawValue}'. Allowed values: ${allowed.join(", ")}`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return normalized;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function normalizeSeverityGate(rawValue) {
|
|
28
|
-
const normalized = String(rawValue || "").trim().toUpperCase();
|
|
29
|
-
if (!normalized) {
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
if (normalized === "NONE") {
|
|
33
|
-
return "none";
|
|
34
|
-
}
|
|
35
|
-
if (normalized === "P0" || normalized === "P1" || normalized === "P2") {
|
|
36
|
-
return normalized;
|
|
37
|
-
}
|
|
38
|
-
return normalized;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function normalizeMode(rawValue, fallback) {
|
|
42
|
-
const normalized = String(rawValue || "").trim().toLowerCase();
|
|
43
|
-
return normalized || fallback;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function hasAnyKeyword(text, keywords) {
|
|
47
|
-
return keywords.some((keyword) => text.includes(keyword));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function computeRiskScore(text) {
|
|
51
|
-
const weightedSignals = [
|
|
52
|
-
["auth", 2],
|
|
53
|
-
["authorization", 2],
|
|
54
|
-
["oauth", 2],
|
|
55
|
-
["token", 2],
|
|
56
|
-
["payment", 3],
|
|
57
|
-
["billing", 2],
|
|
58
|
-
["pii", 3],
|
|
59
|
-
["compliance", 2],
|
|
60
|
-
["encryption", 2],
|
|
61
|
-
["secrets", 2],
|
|
62
|
-
["supply_chain", 2],
|
|
63
|
-
["supply chain", 2],
|
|
64
|
-
["dependency", 1],
|
|
65
|
-
["admin", 1],
|
|
66
|
-
["tenant", 1],
|
|
67
|
-
["security checklist", 1],
|
|
68
|
-
["critical", 1],
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
return weightedSignals.reduce(
|
|
72
|
-
(score, [keyword, weight]) => (text.includes(keyword) ? score + weight : score),
|
|
73
|
-
0
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function parseSecretReference(rawValue) {
|
|
78
|
-
const text = String(rawValue || "");
|
|
79
|
-
const match = text.match(/\$\{\{\s*secrets\.([A-Za-z0-9_]+)\s*\}\}/);
|
|
80
|
-
return match ? String(match[1]).toUpperCase() : "";
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function sanitizeSecretName(secretName) {
|
|
84
|
-
const normalized = String(secretName || "")
|
|
85
|
-
.trim()
|
|
86
|
-
.toUpperCase();
|
|
87
|
-
return SECRET_NAME_REGEX.test(normalized) ? normalized : DEFAULT_SCAN_SECRET_NAME;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function inferScanProfile({ specMarkdown, hasE2ETests = "auto", playwrightMode = "auto" } = {}) {
|
|
91
|
-
const specText = String(specMarkdown || "").trim().toLowerCase();
|
|
92
|
-
if (!specText) {
|
|
93
|
-
throw new Error("Spec content is empty. Generate or provide a spec before configuring scan workflow.");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const normalizedE2EHint = normalizeChoice(hasE2ETests, SUPPORTED_E2E_HINTS, "has-e2e-tests");
|
|
97
|
-
const normalizedPlaywrightMode = normalizeChoice(
|
|
98
|
-
playwrightMode,
|
|
99
|
-
SUPPORTED_PLAYWRIGHT_MODES,
|
|
100
|
-
"playwright-mode"
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const inferredHasE2E = hasAnyKeyword(specText, [
|
|
104
|
-
"e2e",
|
|
105
|
-
"end-to-end",
|
|
106
|
-
"playwright",
|
|
107
|
-
"cypress",
|
|
108
|
-
"integration test",
|
|
109
|
-
]);
|
|
110
|
-
const riskScore = computeRiskScore(specText);
|
|
111
|
-
const deepScanRecommended = riskScore >= 7;
|
|
112
|
-
|
|
113
|
-
const scanMode = deepScanRecommended ? "deep" : "baseline";
|
|
114
|
-
const severityGate = deepScanRecommended ? "P2" : "P1";
|
|
115
|
-
|
|
116
|
-
const hasSupplyChainSignal = hasAnyKeyword(specText, [
|
|
117
|
-
"supply_chain",
|
|
118
|
-
"supply chain",
|
|
119
|
-
"dependency",
|
|
120
|
-
"dependencies",
|
|
121
|
-
"sbom",
|
|
122
|
-
]);
|
|
123
|
-
const sbomMode = hasSupplyChainSignal ? (deepScanRecommended ? "audit" : "baseline") : "off";
|
|
124
|
-
|
|
125
|
-
let resolvedPlaywrightMode = "off";
|
|
126
|
-
if (normalizedPlaywrightMode !== "auto") {
|
|
127
|
-
resolvedPlaywrightMode = normalizedPlaywrightMode;
|
|
128
|
-
} else if (normalizedE2EHint === "yes") {
|
|
129
|
-
resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
|
|
130
|
-
} else if (normalizedE2EHint === "auto" && inferredHasE2E) {
|
|
131
|
-
resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
scanMode,
|
|
136
|
-
severityGate,
|
|
137
|
-
playwrightMode: resolvedPlaywrightMode,
|
|
138
|
-
sbomMode,
|
|
139
|
-
riskScore,
|
|
140
|
-
inferredHasE2E,
|
|
141
|
-
hasE2ETests: normalizedE2EHint,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function buildSecurityReviewWorkflow({ secretName = DEFAULT_SCAN_SECRET_NAME, profile } = {}) {
|
|
146
|
-
if (!profile) {
|
|
147
|
-
throw new Error("Scan profile is required to build workflow config.");
|
|
148
|
-
}
|
|
149
|
-
const normalizedSecret = sanitizeSecretName(secretName);
|
|
150
|
-
|
|
151
|
-
const document = {
|
|
152
|
-
name: "Omar Gate",
|
|
153
|
-
on: {
|
|
154
|
-
pull_request: {
|
|
155
|
-
types: ["opened", "synchronize", "reopened"],
|
|
156
|
-
},
|
|
157
|
-
workflow_dispatch: {
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
: "
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
1
|
+
import YAML from "yaml";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_SCAN_WORKFLOW_PATH = ".github/workflows/omar-gate.yml";
|
|
4
|
+
export const DEFAULT_SCAN_SECRET_NAME = "SENTINELAYER_TOKEN";
|
|
5
|
+
export const SENTINELAYER_ACTION_REF = "mrrCarter/sentinelayer-v1-action@55a2c158f637d7d92e26ab0ef3ba81db791da4be";
|
|
6
|
+
export const SUPPORTED_E2E_HINTS = Object.freeze(["auto", "yes", "no"]);
|
|
7
|
+
export const SUPPORTED_PLAYWRIGHT_MODES = Object.freeze(["auto", "off", "baseline", "audit"]);
|
|
8
|
+
|
|
9
|
+
const CHECKOUT_ACTION_REF = "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683";
|
|
10
|
+
const SETUP_NODE_ACTION_REF = "actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020";
|
|
11
|
+
const SECRET_NAME_REGEX = /^[A-Z][A-Z0-9_]*$/;
|
|
12
|
+
const REPO_SLUG_REGEX = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
13
|
+
|
|
14
|
+
function normalizeChoice(rawValue, allowed, label) {
|
|
15
|
+
const normalized = String(rawValue || "").trim().toLowerCase();
|
|
16
|
+
if (!normalized) {
|
|
17
|
+
return allowed[0];
|
|
18
|
+
}
|
|
19
|
+
if (!allowed.includes(normalized)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Invalid ${label} '${rawValue}'. Allowed values: ${allowed.join(", ")}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return normalized;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeSeverityGate(rawValue) {
|
|
28
|
+
const normalized = String(rawValue || "").trim().toUpperCase();
|
|
29
|
+
if (!normalized) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
if (normalized === "NONE") {
|
|
33
|
+
return "none";
|
|
34
|
+
}
|
|
35
|
+
if (normalized === "P0" || normalized === "P1" || normalized === "P2") {
|
|
36
|
+
return normalized;
|
|
37
|
+
}
|
|
38
|
+
return normalized;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function normalizeMode(rawValue, fallback) {
|
|
42
|
+
const normalized = String(rawValue || "").trim().toLowerCase();
|
|
43
|
+
return normalized || fallback;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hasAnyKeyword(text, keywords) {
|
|
47
|
+
return keywords.some((keyword) => text.includes(keyword));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function computeRiskScore(text) {
|
|
51
|
+
const weightedSignals = [
|
|
52
|
+
["auth", 2],
|
|
53
|
+
["authorization", 2],
|
|
54
|
+
["oauth", 2],
|
|
55
|
+
["token", 2],
|
|
56
|
+
["payment", 3],
|
|
57
|
+
["billing", 2],
|
|
58
|
+
["pii", 3],
|
|
59
|
+
["compliance", 2],
|
|
60
|
+
["encryption", 2],
|
|
61
|
+
["secrets", 2],
|
|
62
|
+
["supply_chain", 2],
|
|
63
|
+
["supply chain", 2],
|
|
64
|
+
["dependency", 1],
|
|
65
|
+
["admin", 1],
|
|
66
|
+
["tenant", 1],
|
|
67
|
+
["security checklist", 1],
|
|
68
|
+
["critical", 1],
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
return weightedSignals.reduce(
|
|
72
|
+
(score, [keyword, weight]) => (text.includes(keyword) ? score + weight : score),
|
|
73
|
+
0
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseSecretReference(rawValue) {
|
|
78
|
+
const text = String(rawValue || "");
|
|
79
|
+
const match = text.match(/\$\{\{\s*secrets\.([A-Za-z0-9_]+)\s*\}\}/);
|
|
80
|
+
return match ? String(match[1]).toUpperCase() : "";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function sanitizeSecretName(secretName) {
|
|
84
|
+
const normalized = String(secretName || "")
|
|
85
|
+
.trim()
|
|
86
|
+
.toUpperCase();
|
|
87
|
+
return SECRET_NAME_REGEX.test(normalized) ? normalized : DEFAULT_SCAN_SECRET_NAME;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function inferScanProfile({ specMarkdown, hasE2ETests = "auto", playwrightMode = "auto" } = {}) {
|
|
91
|
+
const specText = String(specMarkdown || "").trim().toLowerCase();
|
|
92
|
+
if (!specText) {
|
|
93
|
+
throw new Error("Spec content is empty. Generate or provide a spec before configuring scan workflow.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const normalizedE2EHint = normalizeChoice(hasE2ETests, SUPPORTED_E2E_HINTS, "has-e2e-tests");
|
|
97
|
+
const normalizedPlaywrightMode = normalizeChoice(
|
|
98
|
+
playwrightMode,
|
|
99
|
+
SUPPORTED_PLAYWRIGHT_MODES,
|
|
100
|
+
"playwright-mode"
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const inferredHasE2E = hasAnyKeyword(specText, [
|
|
104
|
+
"e2e",
|
|
105
|
+
"end-to-end",
|
|
106
|
+
"playwright",
|
|
107
|
+
"cypress",
|
|
108
|
+
"integration test",
|
|
109
|
+
]);
|
|
110
|
+
const riskScore = computeRiskScore(specText);
|
|
111
|
+
const deepScanRecommended = riskScore >= 7;
|
|
112
|
+
|
|
113
|
+
const scanMode = deepScanRecommended ? "deep" : "baseline";
|
|
114
|
+
const severityGate = deepScanRecommended ? "P2" : "P1";
|
|
115
|
+
|
|
116
|
+
const hasSupplyChainSignal = hasAnyKeyword(specText, [
|
|
117
|
+
"supply_chain",
|
|
118
|
+
"supply chain",
|
|
119
|
+
"dependency",
|
|
120
|
+
"dependencies",
|
|
121
|
+
"sbom",
|
|
122
|
+
]);
|
|
123
|
+
const sbomMode = hasSupplyChainSignal ? (deepScanRecommended ? "audit" : "baseline") : "off";
|
|
124
|
+
|
|
125
|
+
let resolvedPlaywrightMode = "off";
|
|
126
|
+
if (normalizedPlaywrightMode !== "auto") {
|
|
127
|
+
resolvedPlaywrightMode = normalizedPlaywrightMode;
|
|
128
|
+
} else if (normalizedE2EHint === "yes") {
|
|
129
|
+
resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
|
|
130
|
+
} else if (normalizedE2EHint === "auto" && inferredHasE2E) {
|
|
131
|
+
resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
scanMode,
|
|
136
|
+
severityGate,
|
|
137
|
+
playwrightMode: resolvedPlaywrightMode,
|
|
138
|
+
sbomMode,
|
|
139
|
+
riskScore,
|
|
140
|
+
inferredHasE2E,
|
|
141
|
+
hasE2ETests: normalizedE2EHint,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function buildSecurityReviewWorkflow({ secretName = DEFAULT_SCAN_SECRET_NAME, profile } = {}) {
|
|
146
|
+
if (!profile) {
|
|
147
|
+
throw new Error("Scan profile is required to build workflow config.");
|
|
148
|
+
}
|
|
149
|
+
const normalizedSecret = sanitizeSecretName(secretName);
|
|
150
|
+
|
|
151
|
+
const document = {
|
|
152
|
+
name: "Omar Gate",
|
|
153
|
+
on: {
|
|
154
|
+
pull_request: {
|
|
155
|
+
types: ["opened", "synchronize", "reopened"],
|
|
156
|
+
},
|
|
157
|
+
workflow_dispatch: {
|
|
158
|
+
inputs: {
|
|
159
|
+
scan_mode: {
|
|
160
|
+
description: "Sentinelayer scan profile",
|
|
161
|
+
required: false,
|
|
162
|
+
default: profile.scanMode || "deep",
|
|
163
|
+
type: "choice",
|
|
164
|
+
options: ["deep", "nightly"],
|
|
165
|
+
},
|
|
166
|
+
severity_gate: {
|
|
167
|
+
description: "Severity threshold that blocks merge",
|
|
168
|
+
required: false,
|
|
169
|
+
default: profile.severityGate || "P1",
|
|
170
|
+
type: "choice",
|
|
171
|
+
options: ["P0", "P1", "P2", "none"],
|
|
172
|
+
},
|
|
173
|
+
p2_max_allowed: {
|
|
174
|
+
description: "Maximum allowed P2 findings",
|
|
175
|
+
required: false,
|
|
176
|
+
default: "5",
|
|
177
|
+
type: "string",
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
permissions: {
|
|
183
|
+
contents: "read",
|
|
184
|
+
"pull-requests": "write",
|
|
185
|
+
checks: "write",
|
|
186
|
+
"id-token": "write",
|
|
187
|
+
},
|
|
188
|
+
env: {
|
|
189
|
+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true",
|
|
190
|
+
},
|
|
191
|
+
jobs: {
|
|
192
|
+
omar_gate: {
|
|
193
|
+
name: "Omar Gate",
|
|
194
|
+
"runs-on": "ubuntu-latest",
|
|
195
|
+
"timeout-minutes": 20,
|
|
196
|
+
permissions: {
|
|
197
|
+
contents: "read",
|
|
198
|
+
checks: "write",
|
|
199
|
+
"pull-requests": "write",
|
|
200
|
+
"id-token": "write",
|
|
201
|
+
},
|
|
202
|
+
steps: [
|
|
203
|
+
{
|
|
204
|
+
name: "Checkout",
|
|
205
|
+
uses: CHECKOUT_ACTION_REF,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "Validate Sentinelayer token",
|
|
209
|
+
shell: "bash",
|
|
210
|
+
env: {
|
|
211
|
+
SENTINELAYER_TOKEN: `\${{ secrets.${normalizedSecret} }}`,
|
|
212
|
+
},
|
|
213
|
+
run: [
|
|
214
|
+
'set -euo pipefail',
|
|
215
|
+
'if [ -z "${SENTINELAYER_TOKEN}" ]; then',
|
|
216
|
+
` echo "::warning::${normalizedSecret} not set. Run: gh secret set ${normalizedSecret} --body <token>"`,
|
|
217
|
+
' echo "Skipping — run locally: npx sentinelayer-cli@latest /omargate deep --path ."',
|
|
218
|
+
' exit 0',
|
|
219
|
+
'fi',
|
|
220
|
+
].join("\n"),
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "Run Omar Gate",
|
|
224
|
+
id: "omar",
|
|
225
|
+
uses: SENTINELAYER_ACTION_REF,
|
|
226
|
+
with: {
|
|
227
|
+
sentinelayer_token: `\${{ secrets.${normalizedSecret} }}`,
|
|
228
|
+
scan_mode: profile.scanMode || "deep",
|
|
229
|
+
severity_gate: profile.severityGate || "P1",
|
|
230
|
+
playwright_mode: profile.playwrightMode || "off",
|
|
231
|
+
sbom_mode: profile.sbomMode || "off",
|
|
232
|
+
wait_for_completion: "true",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: "Enforce merge thresholds",
|
|
237
|
+
shell: "bash",
|
|
238
|
+
env: {
|
|
239
|
+
P0_COUNT: "${{ steps.omar.outputs.p0_count || '0' }}",
|
|
240
|
+
P1_COUNT: "${{ steps.omar.outputs.p1_count || '0' }}",
|
|
241
|
+
P2_COUNT: "${{ steps.omar.outputs.p2_count || '0' }}",
|
|
242
|
+
P2_MAX: "${{ github.event_name == 'workflow_dispatch' && inputs.p2_max_allowed || '5' }}",
|
|
243
|
+
},
|
|
244
|
+
run: [
|
|
245
|
+
'set -euo pipefail',
|
|
246
|
+
'p0="$(echo "${P0_COUNT}" | tr -d \'\\r\' | xargs)"',
|
|
247
|
+
'p1="$(echo "${P1_COUNT}" | tr -d \'\\r\' | xargs)"',
|
|
248
|
+
'p2="$(echo "${P2_COUNT}" | tr -d \'\\r\' | xargs)"',
|
|
249
|
+
'p2_max="$(echo "${P2_MAX}" | tr -d \'\\r\' | xargs)"',
|
|
250
|
+
'if [ "${p0:-0}" -gt 0 ] || [ "${p1:-0}" -gt 0 ]; then',
|
|
251
|
+
' echo "::error::Omar Gate blocked: P0=${p0}, P1=${p1}"',
|
|
252
|
+
' exit 1',
|
|
253
|
+
'fi',
|
|
254
|
+
'if [ "${p2:-0}" -gt "${p2_max:-5}" ]; then',
|
|
255
|
+
' echo "::error::Omar Gate blocked: P2=${p2} exceeds max ${p2_max}"',
|
|
256
|
+
' exit 1',
|
|
257
|
+
'fi',
|
|
258
|
+
].join("\n"),
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "Omar summary",
|
|
262
|
+
shell: "bash",
|
|
263
|
+
run: [
|
|
264
|
+
'echo "## Omar Gate" >> "$GITHUB_STEP_SUMMARY"',
|
|
265
|
+
'echo "- gate: \\`${{ steps.omar.outputs.gate_status }}\\`" >> "$GITHUB_STEP_SUMMARY"',
|
|
266
|
+
'echo "- findings: P0=${{ steps.omar.outputs.p0_count }} P1=${{ steps.omar.outputs.p1_count }} P2=${{ steps.omar.outputs.p2_count }} P3=${{ steps.omar.outputs.p3_count }}" >> "$GITHUB_STEP_SUMMARY"',
|
|
267
|
+
].join("\n"),
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
return YAML.stringify(document, { lineWidth: 0 });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function extractScanActionStep(workflowMarkdown) {
|
|
278
|
+
const parsed = YAML.parse(String(workflowMarkdown || "")) || {};
|
|
279
|
+
const jobs = parsed.jobs && typeof parsed.jobs === "object" ? parsed.jobs : {};
|
|
280
|
+
|
|
281
|
+
for (const [jobId, job] of Object.entries(jobs)) {
|
|
282
|
+
const steps = Array.isArray(job?.steps) ? job.steps : [];
|
|
283
|
+
for (let stepIndex = 0; stepIndex < steps.length; stepIndex += 1) {
|
|
284
|
+
const step = steps[stepIndex] || {};
|
|
285
|
+
const uses = String(step.uses || "").trim();
|
|
286
|
+
if (uses.includes("mrrCarter/sentinelayer-v1-action")) {
|
|
287
|
+
return {
|
|
288
|
+
jobId,
|
|
289
|
+
stepIndex,
|
|
290
|
+
uses,
|
|
291
|
+
with: step.with && typeof step.with === "object" ? step.with : {},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function validateSecurityReviewWorkflow({
|
|
301
|
+
workflowMarkdown,
|
|
302
|
+
expectedProfile,
|
|
303
|
+
expectedSecretName = DEFAULT_SCAN_SECRET_NAME,
|
|
304
|
+
} = {}) {
|
|
305
|
+
if (!expectedProfile) {
|
|
306
|
+
throw new Error("Expected scan profile is required for validation.");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const actionStep = extractScanActionStep(workflowMarkdown);
|
|
310
|
+
const expected = {
|
|
311
|
+
action: "mrrCarter/sentinelayer-v1-action",
|
|
312
|
+
scan_mode: normalizeMode(expectedProfile.scanMode, "deep"),
|
|
313
|
+
severity_gate: normalizeSeverityGate(expectedProfile.severityGate),
|
|
314
|
+
playwright_mode: normalizeMode(expectedProfile.playwrightMode, "off"),
|
|
315
|
+
sbom_mode: normalizeMode(expectedProfile.sbomMode, "off"),
|
|
316
|
+
secret_name: sanitizeSecretName(expectedSecretName),
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
if (!actionStep) {
|
|
320
|
+
return {
|
|
321
|
+
aligned: false,
|
|
322
|
+
expected,
|
|
323
|
+
actual: null,
|
|
324
|
+
mismatches: [
|
|
325
|
+
{
|
|
326
|
+
field: "action",
|
|
327
|
+
expected: expected.action,
|
|
328
|
+
actual: "not found",
|
|
329
|
+
message: "Workflow does not include mrrCarter/sentinelayer-v1-action step.",
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const withConfig = actionStep.with || {};
|
|
336
|
+
const actual = {
|
|
337
|
+
action: actionStep.uses,
|
|
338
|
+
scan_mode: normalizeMode(withConfig.scan_mode, ""),
|
|
339
|
+
severity_gate: normalizeSeverityGate(withConfig.severity_gate),
|
|
340
|
+
playwright_mode: normalizeMode(withConfig.playwright_mode, "off"),
|
|
341
|
+
sbom_mode: normalizeMode(withConfig.sbom_mode, "off"),
|
|
342
|
+
secret_name: parseSecretReference(withConfig.sentinelayer_token),
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const mismatches = [];
|
|
346
|
+
|
|
347
|
+
if (actual.scan_mode !== expected.scan_mode) {
|
|
348
|
+
mismatches.push({
|
|
349
|
+
field: "scan_mode",
|
|
350
|
+
expected: expected.scan_mode,
|
|
351
|
+
actual: actual.scan_mode || "(missing)",
|
|
352
|
+
message: "scan_mode does not match spec-derived recommendation.",
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (actual.severity_gate !== expected.severity_gate) {
|
|
356
|
+
mismatches.push({
|
|
357
|
+
field: "severity_gate",
|
|
358
|
+
expected: expected.severity_gate,
|
|
359
|
+
actual: actual.severity_gate || "(missing)",
|
|
360
|
+
message: "severity_gate does not match spec-derived recommendation.",
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (actual.playwright_mode !== expected.playwright_mode) {
|
|
364
|
+
mismatches.push({
|
|
365
|
+
field: "playwright_mode",
|
|
366
|
+
expected: expected.playwright_mode,
|
|
367
|
+
actual: actual.playwright_mode || "(missing)",
|
|
368
|
+
message: "playwright_mode does not match e2e/spec profile.",
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (actual.sbom_mode !== expected.sbom_mode) {
|
|
372
|
+
mismatches.push({
|
|
373
|
+
field: "sbom_mode",
|
|
374
|
+
expected: expected.sbom_mode,
|
|
375
|
+
actual: actual.sbom_mode || "(missing)",
|
|
376
|
+
message: "sbom_mode does not match supply-chain profile.",
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (actual.secret_name !== expected.secret_name) {
|
|
380
|
+
mismatches.push({
|
|
381
|
+
field: "sentinelayer_token",
|
|
382
|
+
expected: `\${{ secrets.${expected.secret_name} }}`,
|
|
383
|
+
actual: actual.secret_name ? `\${{ secrets.${actual.secret_name} }}` : "(missing)",
|
|
384
|
+
message: "sentinelayer_token secret binding does not match expected secret name.",
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return {
|
|
389
|
+
aligned: mismatches.length === 0,
|
|
390
|
+
expected,
|
|
391
|
+
actual,
|
|
392
|
+
mismatches,
|
|
393
|
+
location: {
|
|
394
|
+
jobId: actionStep.jobId,
|
|
395
|
+
stepIndex: actionStep.stepIndex,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function buildSecretSetupInstructions(
|
|
401
|
+
secretName = DEFAULT_SCAN_SECRET_NAME,
|
|
402
|
+
{ repoSlug = "" } = {}
|
|
403
|
+
) {
|
|
404
|
+
const normalizedSecret = sanitizeSecretName(secretName);
|
|
405
|
+
const normalizedRepoSlug = String(repoSlug || "").trim();
|
|
406
|
+
const resolvedRepoSlug = REPO_SLUG_REGEX.test(normalizedRepoSlug)
|
|
407
|
+
? normalizedRepoSlug
|
|
408
|
+
: "<owner/repo>";
|
|
409
|
+
return [
|
|
410
|
+
"Set the Sentinelayer token secret before relying on this workflow in PR checks:",
|
|
411
|
+
`- gh secret set ${normalizedSecret} --repo ${resolvedRepoSlug}`,
|
|
412
|
+
`- Verify secret visibility: gh secret list --repo ${resolvedRepoSlug}`,
|
|
413
|
+
"- Commit and push .github/workflows/omar-gate.yml",
|
|
414
|
+
"- For manual setup: https://sentinelayer.com/docs/getting-started/install-workflow",
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
|