agentic-sdlc-mcp 1.9.0 → 2.0.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 +73 -14
- package/README_zh.md +432 -0
- package/dist/assessment/acceptance.d.ts +155 -0
- package/dist/assessment/acceptance.d.ts.map +1 -0
- package/dist/assessment/acceptance.js +278 -0
- package/dist/assessment/acceptance.js.map +1 -0
- package/dist/assessment/continuity.d.ts +266 -0
- package/dist/assessment/continuity.d.ts.map +1 -0
- package/dist/assessment/continuity.js +246 -0
- package/dist/assessment/continuity.js.map +1 -0
- package/dist/assessment/current-check.d.ts +36 -0
- package/dist/assessment/current-check.d.ts.map +1 -0
- package/dist/assessment/current-check.js +303 -0
- package/dist/assessment/current-check.js.map +1 -0
- package/dist/assessment/github-session.d.ts +15 -0
- package/dist/assessment/github-session.d.ts.map +1 -0
- package/dist/assessment/github-session.js +157 -0
- package/dist/assessment/github-session.js.map +1 -0
- package/dist/assessment/pr-assessment.d.ts +168 -0
- package/dist/assessment/pr-assessment.d.ts.map +1 -0
- package/dist/assessment/pr-assessment.js +140 -0
- package/dist/assessment/pr-assessment.js.map +1 -0
- package/dist/briefing/work-item-brief.d.ts.map +1 -1
- package/dist/briefing/work-item-brief.js +58 -12
- package/dist/briefing/work-item-brief.js.map +1 -1
- package/dist/cli/arguments.d.ts +14 -0
- package/dist/cli/arguments.d.ts.map +1 -0
- package/dist/cli/arguments.js +62 -0
- package/dist/cli/arguments.js.map +1 -0
- package/dist/cli/doctor.d.ts +28 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +56 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/github-client.d.ts +4 -0
- package/dist/cli/github-client.d.ts.map +1 -0
- package/dist/cli/github-client.js +11 -0
- package/dist/cli/github-client.js.map +1 -0
- package/dist/cli/run.d.ts +12 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +204 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +14 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -3
- package/dist/config.js.map +1 -1
- package/dist/contracts/mcp-manifest.d.ts +70 -0
- package/dist/contracts/mcp-manifest.d.ts.map +1 -0
- package/dist/contracts/mcp-manifest.js +615 -0
- package/dist/contracts/mcp-manifest.js.map +1 -0
- package/dist/evaluation/budgets.d.ts +89 -0
- package/dist/evaluation/budgets.d.ts.map +1 -0
- package/dist/evaluation/budgets.js +234 -0
- package/dist/evaluation/budgets.js.map +1 -0
- package/dist/evaluation/faults.d.ts +153 -0
- package/dist/evaluation/faults.d.ts.map +1 -0
- package/dist/evaluation/faults.js +95 -0
- package/dist/evaluation/faults.js.map +1 -0
- package/dist/evaluation/model.d.ts +115 -0
- package/dist/evaluation/model.d.ts.map +1 -0
- package/dist/evaluation/model.js +242 -0
- package/dist/evaluation/model.js.map +1 -0
- package/dist/evaluation/scorer.d.ts +46 -0
- package/dist/evaluation/scorer.d.ts.map +1 -0
- package/dist/evaluation/scorer.js +126 -0
- package/dist/evaluation/scorer.js.map +1 -0
- package/dist/evidence/model.d.ts +1 -0
- package/dist/evidence/model.d.ts.map +1 -1
- package/dist/evidence/model.js +3 -2
- package/dist/evidence/model.js.map +1 -1
- package/dist/evidence/render.d.ts.map +1 -1
- package/dist/evidence/render.js +2 -1
- package/dist/evidence/render.js.map +1 -1
- package/dist/evidence/timeout.d.ts +11 -0
- package/dist/evidence/timeout.d.ts.map +1 -1
- package/dist/evidence/timeout.js +31 -4
- package/dist/evidence/timeout.js.map +1 -1
- package/dist/github/client.d.ts +6 -0
- package/dist/github/client.d.ts.map +1 -1
- package/dist/github/client.js +44 -15
- package/dist/github/client.js.map +1 -1
- package/dist/github/context.d.ts.map +1 -1
- package/dist/github/context.js +5 -0
- package/dist/github/context.js.map +1 -1
- package/dist/github/pull-request-evidence.d.ts +7 -1
- package/dist/github/pull-request-evidence.d.ts.map +1 -1
- package/dist/github/pull-request-evidence.js +47 -8
- package/dist/github/pull-request-evidence.js.map +1 -1
- package/dist/http-server.d.ts +6 -4
- package/dist/http-server.d.ts.map +1 -1
- package/dist/http-server.js +174 -32
- package/dist/http-server.js.map +1 -1
- package/dist/index.d.ts +1 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -9
- package/dist/index.js.map +1 -1
- package/dist/operations/issue-creation.d.ts +44 -0
- package/dist/operations/issue-creation.d.ts.map +1 -0
- package/dist/operations/issue-creation.js +237 -0
- package/dist/operations/issue-creation.js.map +1 -0
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/review/pull-request-review.d.ts +3 -1
- package/dist/review/pull-request-review.d.ts.map +1 -1
- package/dist/review/pull-request-review.js +911 -108
- package/dist/review/pull-request-review.js.map +1 -1
- package/dist/security/prompt-injection-patterns.d.ts.map +1 -1
- package/dist/security/prompt-injection-patterns.js +54 -6
- package/dist/security/prompt-injection-patterns.js.map +1 -1
- package/dist/security/secret-scanner-evidence.d.ts +23 -1
- package/dist/security/secret-scanner-evidence.d.ts.map +1 -1
- package/dist/security/secret-scanner-evidence.js +380 -40
- package/dist/security/secret-scanner-evidence.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/stdio-server.d.ts +5 -0
- package/dist/stdio-server.d.ts.map +1 -0
- package/dist/stdio-server.js +7 -0
- package/dist/stdio-server.js.map +1 -0
- package/dist/tools/agent-handoff.d.ts +1 -1
- package/dist/tools/agent-handoff.d.ts.map +1 -1
- package/dist/tools/agent-handoff.js +1 -1
- package/dist/tools/agent-handoff.js.map +1 -1
- package/dist/tools/branch-protection-status.d.ts +1 -1
- package/dist/tools/branch-protection-status.d.ts.map +1 -1
- package/dist/tools/branch-protection-status.js +1 -1
- package/dist/tools/branch-protection-status.js.map +1 -1
- package/dist/tools/create-issue-set.d.ts +66 -3
- package/dist/tools/create-issue-set.d.ts.map +1 -1
- package/dist/tools/create-issue-set.js +75 -71
- package/dist/tools/create-issue-set.js.map +1 -1
- package/dist/tools/create-pr-summary.d.ts +2 -2
- package/dist/tools/create-pr-summary.d.ts.map +1 -1
- package/dist/tools/create-pr-summary.js +14 -5
- package/dist/tools/create-pr-summary.js.map +1 -1
- package/dist/tools/plan-from-context.d.ts +1 -1
- package/dist/tools/plan-from-context.d.ts.map +1 -1
- package/dist/tools/plan-from-context.js +1 -1
- package/dist/tools/plan-from-context.js.map +1 -1
- package/dist/tools/prepare-work-item.d.ts +1 -1
- package/dist/tools/prepare-work-item.d.ts.map +1 -1
- package/dist/tools/prepare-work-item.js +1 -1
- package/dist/tools/prepare-work-item.js.map +1 -1
- package/dist/tools/quality-gate-status.d.ts +1 -1
- package/dist/tools/quality-gate-status.d.ts.map +1 -1
- package/dist/tools/quality-gate-status.js +65 -5
- package/dist/tools/quality-gate-status.js.map +1 -1
- package/dist/tools/release-readiness.d.ts +1 -1
- package/dist/tools/release-readiness.d.ts.map +1 -1
- package/dist/tools/release-readiness.js +1 -1
- package/dist/tools/release-readiness.js.map +1 -1
- package/dist/tools/repo-context.d.ts +1 -1
- package/dist/tools/repo-context.d.ts.map +1 -1
- package/dist/tools/repo-context.js +1 -1
- package/dist/tools/repo-context.js.map +1 -1
- package/dist/tools/review-pr.d.ts +1 -1
- package/dist/tools/review-pr.d.ts.map +1 -1
- package/dist/tools/review-pr.js +5 -5
- package/dist/tools/review-pr.js.map +1 -1
- package/dist/tools/sdlc-evidence-packet.d.ts +1 -1
- package/dist/tools/sdlc-evidence-packet.d.ts.map +1 -1
- package/dist/tools/sdlc-evidence-packet.js +2 -2
- package/dist/tools/sdlc-evidence-packet.js.map +1 -1
- package/dist/tools/security-triage.d.ts +1 -1
- package/dist/tools/security-triage.d.ts.map +1 -1
- package/dist/tools/security-triage.js +27 -3
- package/dist/tools/security-triage.js.map +1 -1
- package/dist/tools/workflow-permissions-audit.d.ts +1 -1
- package/dist/tools/workflow-permissions-audit.d.ts.map +1 -1
- package/dist/tools/workflow-permissions-audit.js +1 -1
- package/dist/tools/workflow-permissions-audit.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/client-recipes.md +153 -0
- package/docs/evidence-continuity.md +102 -0
- package/docs/pr-workflows.md +136 -0
- package/docs/user-pilot.md +80 -0
- package/evaluation/schema.json +224 -0
- package/package.json +40 -8
- package/server.json +2 -2
- package/skills/pr-evidence-review/SKILL.md +26 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applySecretScannerPolicyChanges, secretScannerPolicyFinding, unverifiedSecretScannerEvidence, } from "../security/secret-scanner-evidence.js";
|
|
2
2
|
const SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
|
|
3
3
|
const LOCK_FILE_NAMES = new Set([
|
|
4
4
|
"bun.lock",
|
|
@@ -120,14 +120,51 @@ function normalizedLabels(labels) {
|
|
|
120
120
|
function hasLabel(labels, pattern) {
|
|
121
121
|
return labels.some((label) => pattern.test(label));
|
|
122
122
|
}
|
|
123
|
+
function stripUrlTargetsForClassification(value) {
|
|
124
|
+
const chunks = [];
|
|
125
|
+
let visibleStart = 0;
|
|
126
|
+
let cursor = 0;
|
|
127
|
+
while (cursor < value.length) {
|
|
128
|
+
const prefixLength = value.slice(cursor, cursor + 8).toLowerCase() === "https://"
|
|
129
|
+
? 8
|
|
130
|
+
: value.slice(cursor, cursor + 7).toLowerCase() === "http://"
|
|
131
|
+
? 7
|
|
132
|
+
: 0;
|
|
133
|
+
if (prefixLength === 0) {
|
|
134
|
+
cursor += 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
chunks.push(value.slice(visibleStart, cursor));
|
|
138
|
+
cursor += prefixLength;
|
|
139
|
+
let parenthesisDepth = 0;
|
|
140
|
+
while (cursor < value.length) {
|
|
141
|
+
const character = value[cursor] ?? "";
|
|
142
|
+
if (/\s/u.test(character) || /[}>"]/u.test(character))
|
|
143
|
+
break;
|
|
144
|
+
if (character === "(") {
|
|
145
|
+
parenthesisDepth += 1;
|
|
146
|
+
}
|
|
147
|
+
else if (character === ")") {
|
|
148
|
+
if (parenthesisDepth === 0)
|
|
149
|
+
break;
|
|
150
|
+
parenthesisDepth -= 1;
|
|
151
|
+
}
|
|
152
|
+
cursor += 1;
|
|
153
|
+
}
|
|
154
|
+
visibleStart = cursor;
|
|
155
|
+
}
|
|
156
|
+
chunks.push(value.slice(visibleStart));
|
|
157
|
+
return chunks.join("");
|
|
158
|
+
}
|
|
123
159
|
export function inferWorkType(pr, files) {
|
|
124
160
|
const classified = classifyPrFiles(files);
|
|
125
161
|
const labels = normalizedLabels(pr.labels);
|
|
126
162
|
const title = pr.title.trim();
|
|
127
163
|
const body = pr.body ?? "";
|
|
164
|
+
const semanticBody = stripUrlTargetsForClassification(body);
|
|
128
165
|
if (hasLabel(labels, /^(?:security|security-fix|vulnerability)$/) ||
|
|
129
166
|
/\b(?:security|vulnerability|cve-\d+|credential exposure)\b/i.test(title) ||
|
|
130
|
-
/\b(?:security(?: hardening| vulnerability)?|credential exposure|threat model|cve-\d+)\b/i.test(
|
|
167
|
+
/\b(?:security(?: hardening| vulnerability)?|credential exposure|threat model|cve-\d+)\b/i.test(semanticBody)) {
|
|
131
168
|
return {
|
|
132
169
|
workType: "security",
|
|
133
170
|
confidence: "high",
|
|
@@ -192,14 +229,54 @@ function hasDetailedPrefixedLine(body, prefixes) {
|
|
|
192
229
|
function hasNoTestReason(body) {
|
|
193
230
|
return hasDetailedPrefixedLine(body, /^\s*(?:[-*]\s*)?(?:no tests|testing not required)\s*:\s*(.+)$/i);
|
|
194
231
|
}
|
|
232
|
+
function markdownHiddenHeadingLines(lines) {
|
|
233
|
+
let openFence = null;
|
|
234
|
+
let inHtmlComment = false;
|
|
235
|
+
return lines.map((line) => {
|
|
236
|
+
if (openFence) {
|
|
237
|
+
const closing = line.match(/^ {0,3}(`{3,}|~{3,})\s*$/);
|
|
238
|
+
const marker = closing?.[1];
|
|
239
|
+
if (marker?.[0] === openFence.marker &&
|
|
240
|
+
marker.length >= openFence.length) {
|
|
241
|
+
openFence = null;
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
if (inHtmlComment) {
|
|
246
|
+
if (line.includes("-->"))
|
|
247
|
+
inHtmlComment = false;
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
const commentStart = line.indexOf("<!--");
|
|
251
|
+
if (commentStart >= 0) {
|
|
252
|
+
if (line.indexOf("-->", commentStart + 4) < 0)
|
|
253
|
+
inHtmlComment = true;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
const opening = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
257
|
+
const marker = opening?.[1];
|
|
258
|
+
const info = opening?.[2] ?? "";
|
|
259
|
+
if (marker && (marker[0] === "~" || !info.includes("`"))) {
|
|
260
|
+
openFence = {
|
|
261
|
+
marker: marker[0],
|
|
262
|
+
length: marker.length,
|
|
263
|
+
};
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
195
269
|
function sectionContents(body, names) {
|
|
196
270
|
const lines = body.split(/\r?\n/);
|
|
271
|
+
const hiddenHeading = markdownHiddenHeadingLines(lines);
|
|
197
272
|
const namePattern = new RegExp(`^(?:${names})\\s*:?$`, "i");
|
|
198
|
-
const inlinePattern = new RegExp(
|
|
273
|
+
const inlinePattern = new RegExp(`^ {0,3}(?:${names})\\s*:\\s*(.*)$`, "i");
|
|
199
274
|
const sections = [];
|
|
200
275
|
for (let index = 0; index < lines.length; index += 1) {
|
|
276
|
+
if (hiddenHeading[index])
|
|
277
|
+
continue;
|
|
201
278
|
const line = lines[index] ?? "";
|
|
202
|
-
const heading = line.match(
|
|
279
|
+
const heading = line.match(/^ {0,3}#{1,6}\s+(.+?)\s*#*\s*$/);
|
|
203
280
|
const inline = line.match(inlinePattern);
|
|
204
281
|
if (!heading && !inline)
|
|
205
282
|
continue;
|
|
@@ -210,7 +287,7 @@ function sectionContents(body, names) {
|
|
|
210
287
|
content.push(inline[1]);
|
|
211
288
|
for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
|
|
212
289
|
const next = lines[cursor] ?? "";
|
|
213
|
-
if (
|
|
290
|
+
if (!hiddenHeading[cursor] && /^ {0,3}#{1,6}\s+/.test(next))
|
|
214
291
|
break;
|
|
215
292
|
content.push(next);
|
|
216
293
|
}
|
|
@@ -221,17 +298,126 @@ function sectionContents(body, names) {
|
|
|
221
298
|
function hasDetailedSection(body, names) {
|
|
222
299
|
return sectionContents(body, names).some((content) => content.replace(/\s/g, "").length >= 10);
|
|
223
300
|
}
|
|
301
|
+
function hasMeaningfulProse(content) {
|
|
302
|
+
return (content.match(/\p{L}/gu) ?? []).length >= 8;
|
|
303
|
+
}
|
|
304
|
+
function removeAllMatches(content, pattern) {
|
|
305
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
306
|
+
return content.replace(new RegExp(pattern.source, flags), "");
|
|
307
|
+
}
|
|
308
|
+
const SECURITY_EVIDENCE_LABELS = /\b(?:access|attack|authorization|credential|key|permission|privilege|risk|secret|threat|token|vulnerability)\b|访问|攻击|授权|凭据|口令|密钥|权限|风险|特权|威胁|令牌|漏洞/gi;
|
|
309
|
+
function hasSubstantiveEvidence(body, sectionNames, mentionPattern, detailPattern) {
|
|
310
|
+
if (sectionContents(body, sectionNames).some((content) => hasMeaningfulProse(content) && detailPattern.test(content))) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
return body.split(/\r?\n/).some((line) => {
|
|
314
|
+
if (/^\s*#{1,6}\s+/.test(line) || !mentionPattern.test(line))
|
|
315
|
+
return false;
|
|
316
|
+
return (detailPattern.test(line) &&
|
|
317
|
+
hasMeaningfulProse(removeAllMatches(line, SECURITY_EVIDENCE_LABELS)));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
224
320
|
function hasConcreteVerificationMethod(content) {
|
|
225
|
-
return (
|
|
226
|
-
/\b(?:ran|run|executed|verified with|validated with)\s+`?(?:bun|cargo|dotnet|git|go|gradle|make|markdownlint|mvn|node|npm|npx|pnpm|python|pytest|yarn)\b/i.test(content) ||
|
|
321
|
+
return (hasReportedVerificationCommand(content) ||
|
|
227
322
|
/\brender(?:ed|ing)?\b[^.\n]*\b(?:doc(?:umentation)?|markdown|page|site)\b/i.test(content) ||
|
|
228
323
|
/\b(?:build|built)\b[^.\n]*\b(?:doc(?:umentation)?|example|page|site)\b/i.test(content) ||
|
|
229
324
|
/\b(?:checked|validated|verified)\b[^.\n]*\b(?:example|link|markdown|render(?:ed)?|output)\b/i.test(content));
|
|
230
325
|
}
|
|
326
|
+
const VERIFICATION_SUBCOMMANDS = {
|
|
327
|
+
bun: new Set(["build", "install", "run", "test"]),
|
|
328
|
+
cargo: new Set(["build", "check", "clippy", "fmt", "run", "test"]),
|
|
329
|
+
dotnet: new Set(["build", "format", "pack", "publish", "restore", "run", "test"]),
|
|
330
|
+
git: new Set([
|
|
331
|
+
"diff",
|
|
332
|
+
"log",
|
|
333
|
+
"ls-files",
|
|
334
|
+
"ls-remote",
|
|
335
|
+
"merge-base",
|
|
336
|
+
"rev-parse",
|
|
337
|
+
"show",
|
|
338
|
+
"status",
|
|
339
|
+
"worktree",
|
|
340
|
+
]),
|
|
341
|
+
go: new Set(["build", "fmt", "generate", "run", "test", "vet"]),
|
|
342
|
+
gradle: new Set(["assemble", "build", "check", "clean", "test"]),
|
|
343
|
+
make: new Set(["all", "build", "check", "clean", "lint", "test"]),
|
|
344
|
+
mvn: new Set(["clean", "install", "package", "test", "verify"]),
|
|
345
|
+
npm: new Set(["audit", "build", "ci", "exec", "install", "pack", "publish", "run", "start", "test"]),
|
|
346
|
+
pnpm: new Set(["audit", "build", "exec", "install", "run", "start", "test"]),
|
|
347
|
+
yarn: new Set(["audit", "build", "install", "run", "start", "test"]),
|
|
348
|
+
};
|
|
349
|
+
const VERIFICATION_TARGET_PROSE = new Set([
|
|
350
|
+
"a",
|
|
351
|
+
"an",
|
|
352
|
+
"available",
|
|
353
|
+
"correctly",
|
|
354
|
+
"is",
|
|
355
|
+
"the",
|
|
356
|
+
"works",
|
|
357
|
+
]);
|
|
358
|
+
function hasExecutableTarget(argumentsText) {
|
|
359
|
+
const target = argumentsText.match(/^`?([^\s`]+)/)?.[1]?.replace(/["',:;.]+$/g, "");
|
|
360
|
+
return Boolean(target &&
|
|
361
|
+
!target.startsWith("-") &&
|
|
362
|
+
/^[\w@./:-]+$/u.test(target) &&
|
|
363
|
+
/[\p{L}\p{N}]/u.test(target) &&
|
|
364
|
+
!VERIFICATION_TARGET_PROSE.has(target.toLowerCase()));
|
|
365
|
+
}
|
|
366
|
+
function isVerificationCommandArgument(cli, argument, remainingArguments = "") {
|
|
367
|
+
if (!/[\p{L}\p{N}]/u.test(argument))
|
|
368
|
+
return false;
|
|
369
|
+
const normalized = argument.replace(/^['"]|['",:;.]+$/g, "").toLowerCase();
|
|
370
|
+
const subcommands = VERIFICATION_SUBCOMMANDS[cli];
|
|
371
|
+
if (subcommands) {
|
|
372
|
+
if (!subcommands.has(normalized))
|
|
373
|
+
return false;
|
|
374
|
+
if (normalized === "run" || normalized === "exec") {
|
|
375
|
+
return hasExecutableTarget(remainingArguments);
|
|
376
|
+
}
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
if (cli === "node") {
|
|
380
|
+
return (normalized.startsWith("-") ||
|
|
381
|
+
/(?:^|[\\/])[^\\/]+\.(?:cjs|js|mjs|ts)$/.test(normalized));
|
|
382
|
+
}
|
|
383
|
+
if (cli === "python") {
|
|
384
|
+
return normalized.startsWith("-") || /(?:^|[\\/])[^\\/]+\.py$/.test(normalized);
|
|
385
|
+
}
|
|
386
|
+
if (cli === "pytest") {
|
|
387
|
+
return normalized.startsWith("-") || /(?:^|[\\/])(?:test[^\\/]*|tests?)(?:[\\/:]|$)/.test(normalized);
|
|
388
|
+
}
|
|
389
|
+
if (cli === "markdownlint") {
|
|
390
|
+
return normalized.startsWith("-") || /(?:\.md|[\\/*?])/i.test(normalized);
|
|
391
|
+
}
|
|
392
|
+
if (cli === "npx") {
|
|
393
|
+
return /^(?:eslint|jest|markdownlint|playwright|prettier|tsc|tsx|vitest)$/.test(normalized);
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
function hasNamedVerificationCommand(content) {
|
|
398
|
+
return content.split(/\r?\n/).some((line) => {
|
|
399
|
+
const match = line.match(/^\s*(?:[-*]\s*)?`?(bun|cargo|dotnet|git|go|gradle|make|markdownlint|mvn|node|npm|npx|pnpm|python|pytest|yarn)\s+([^\s`]+)(?:\s+(.+))?/i);
|
|
400
|
+
if (!match?.[1] || !match[2])
|
|
401
|
+
return false;
|
|
402
|
+
return isVerificationCommandArgument(match[1].toLowerCase(), match[2], match[3]);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function hasReportedVerificationCommand(content) {
|
|
406
|
+
return content.split(/\r?\n/).some((line) => {
|
|
407
|
+
const match = line.match(/\b(?:executed|ran|run|validated with|verified with)\s+`?(bun|cargo|dotnet|git|go|gradle|make|markdownlint|mvn|node|npm|npx|pnpm|python|pytest|yarn)\s+([^\s`]+)(?:\s+(.+))?/i);
|
|
408
|
+
if (!match?.[1] || !match[2])
|
|
409
|
+
return false;
|
|
410
|
+
const prefix = line.slice(0, match.index);
|
|
411
|
+
if (/\b(?:can(?:not|'t)|could(?:\s+not|n't)|did(?:\s+not|n't)|failed\s+to|never|not|unable\s+to|was(?:\s+not|n't)|were(?:\s+not|n't))\b/i.test(prefix)) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
return isVerificationCommandArgument(match[1].toLowerCase(), match[2], match[3]);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
231
417
|
function hasDocsVerification(body) {
|
|
232
418
|
const sections = sectionContents(body, "verification|validated");
|
|
233
419
|
return sections.length > 0
|
|
234
|
-
? sections.some(hasConcreteVerificationMethod)
|
|
420
|
+
? sections.some((content) => hasConcreteVerificationMethod(content) || hasNamedVerificationCommand(content))
|
|
235
421
|
: hasConcreteVerificationMethod(body);
|
|
236
422
|
}
|
|
237
423
|
function hasBugReproduction(body) {
|
|
@@ -241,8 +427,26 @@ function hasFallback(body) {
|
|
|
241
427
|
return hasDetailedSection(body, "rollback|fallback|revert");
|
|
242
428
|
}
|
|
243
429
|
function hasSecurityValidation(body) {
|
|
244
|
-
|
|
245
|
-
|
|
430
|
+
const methodPattern = /\b(?:abuse[ -]?case|codeql|dast|fail[ -]?closed|mcp (?:2\.0\.0 )?(?:client|integration)|npm audit|penetration test(?:ing)?|sast|security test(?:ing)?|threat model (?:validated|verified))\b|安全(?:回归|测试|扫描|审计)|攻击用例|真实 MCP|拒绝|阻断/i;
|
|
431
|
+
const outcomePattern = /\b(?:blocked?|covered?|failed?|findings?|passed?|rejected?|results?|verified)\b|告警|覆盖|拒绝|结果|失败|未发现|通过|阻断/i;
|
|
432
|
+
const sections = sectionContents(body, "security verification|security validation|security testing|安全验证|安全性验证|安全测试");
|
|
433
|
+
if (sections.some((content) => hasMeaningfulProse(content) &&
|
|
434
|
+
methodPattern.test(content) &&
|
|
435
|
+
outcomePattern.test(content))) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return body.split(/\r?\n/).some((line) => {
|
|
439
|
+
if (/^\s*#{1,6}\s+/.test(line) ||
|
|
440
|
+
!methodPattern.test(line) ||
|
|
441
|
+
!outcomePattern.test(line)) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
return (removeAllMatches(line, methodPattern).match(/\p{L}/gu) ?? []).length >= 2;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function hasAtomicScopeRationale(body) {
|
|
448
|
+
const rationalePattern = /\b(?:because|cannot be split|keep\w* .{2,30} (?:aligned|consistent)|must (?:remain|ship|land) together|otherwise)\b|因为|否则|不能拆|不可拆|必须.{0,20}(?:同批|一起|同时)|同批.{0,20}(?:保持|确保)|保持.{2,20}一致|确保.{2,20}一致|耦合.{0,20}(?:契约|接口|摘要|测试)/i;
|
|
449
|
+
return sectionContents(body, "change scope|scope rationale|atomic change|atomic scope|变更范围说明|范围说明|原子变更").some((content) => hasMeaningfulProse(content) && rationalePattern.test(content));
|
|
246
450
|
}
|
|
247
451
|
const SECRET_ASSIGNMENTS = [
|
|
248
452
|
{
|
|
@@ -279,6 +483,15 @@ function isHighConfidenceUnquotedSecret(value) {
|
|
|
279
483
|
const classes = [/[a-z]/, /[A-Z]/, /\d/, /[^A-Za-z0-9]/].filter((pattern) => pattern.test(normalized)).length;
|
|
280
484
|
return classes >= 3;
|
|
281
485
|
}
|
|
486
|
+
function knownCredentialLiteralName(value) {
|
|
487
|
+
if (/^AKIA[0-9A-Z]{16}$/u.test(value))
|
|
488
|
+
return "AWS access key assignment";
|
|
489
|
+
if (/^(?:ghp_|github_pat_|sk-|xox[a-z]-)[A-Za-z0-9._-]+$/u.test(value) ||
|
|
490
|
+
/^eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/u.test(value)) {
|
|
491
|
+
return "credential assignment";
|
|
492
|
+
}
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
282
495
|
function maskSecretCodeLine(line, state) {
|
|
283
496
|
if (state.mode === "code" && /^(?:\s*#|\s*\*)/.test(line))
|
|
284
497
|
return " ".repeat(line.length);
|
|
@@ -297,7 +510,7 @@ function maskSecretCodeLine(line, state) {
|
|
|
297
510
|
}
|
|
298
511
|
continue;
|
|
299
512
|
}
|
|
300
|
-
if (state.mode
|
|
513
|
+
if (state.mode === "single" || state.mode === "double") {
|
|
301
514
|
code += " ";
|
|
302
515
|
if (state.escaped) {
|
|
303
516
|
state.escaped = false;
|
|
@@ -306,9 +519,27 @@ function maskSecretCodeLine(line, state) {
|
|
|
306
519
|
state.escaped = true;
|
|
307
520
|
}
|
|
308
521
|
else if ((state.mode === "single" && character === "'") ||
|
|
309
|
-
(state.mode === "double" && character === '"')
|
|
310
|
-
|
|
522
|
+
(state.mode === "double" && character === '"')) {
|
|
523
|
+
state.mode = "code";
|
|
524
|
+
}
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (state.mode === "template") {
|
|
528
|
+
code += " ";
|
|
529
|
+
if (state.escaped) {
|
|
530
|
+
state.escaped = false;
|
|
531
|
+
}
|
|
532
|
+
else if (character === "\\") {
|
|
533
|
+
state.escaped = true;
|
|
534
|
+
}
|
|
535
|
+
else if (character === "`") {
|
|
536
|
+
state.mode = "code";
|
|
537
|
+
}
|
|
538
|
+
else if (character === "$" && next === "{") {
|
|
539
|
+
code += " ";
|
|
540
|
+
index += 1;
|
|
311
541
|
state.mode = "code";
|
|
542
|
+
state.templateExpressionDepths.push(0);
|
|
312
543
|
}
|
|
313
544
|
continue;
|
|
314
545
|
}
|
|
@@ -325,6 +556,25 @@ function maskSecretCodeLine(line, state) {
|
|
|
325
556
|
state.escaped = false;
|
|
326
557
|
code += " ";
|
|
327
558
|
}
|
|
559
|
+
else if (character === "{" && state.templateExpressionDepths.length > 0) {
|
|
560
|
+
const depthIndex = state.templateExpressionDepths.length - 1;
|
|
561
|
+
state.templateExpressionDepths[depthIndex] =
|
|
562
|
+
(state.templateExpressionDepths[depthIndex] ?? 0) + 1;
|
|
563
|
+
code += character;
|
|
564
|
+
}
|
|
565
|
+
else if (character === "}" && state.templateExpressionDepths.length > 0) {
|
|
566
|
+
const depthIndex = state.templateExpressionDepths.length - 1;
|
|
567
|
+
const depth = state.templateExpressionDepths[depthIndex] ?? 0;
|
|
568
|
+
if (depth === 0) {
|
|
569
|
+
state.templateExpressionDepths.pop();
|
|
570
|
+
state.mode = "template";
|
|
571
|
+
code += " ";
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
state.templateExpressionDepths[depthIndex] = depth - 1;
|
|
575
|
+
code += character;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
328
578
|
else {
|
|
329
579
|
code += character;
|
|
330
580
|
}
|
|
@@ -349,19 +599,34 @@ function maskSecretCommentsLine(line, state) {
|
|
|
349
599
|
}
|
|
350
600
|
continue;
|
|
351
601
|
}
|
|
352
|
-
if (state.mode
|
|
602
|
+
if (state.mode === "single" || state.mode === "double") {
|
|
353
603
|
content += character;
|
|
354
604
|
if (state.escaped)
|
|
355
605
|
state.escaped = false;
|
|
356
606
|
else if (character === "\\")
|
|
357
607
|
state.escaped = true;
|
|
358
608
|
else if ((state.mode === "single" && character === "'") ||
|
|
359
|
-
(state.mode === "double" && character === '"')
|
|
360
|
-
(state.mode === "template" && character === "`")) {
|
|
609
|
+
(state.mode === "double" && character === '"')) {
|
|
361
610
|
state.mode = "code";
|
|
362
611
|
}
|
|
363
612
|
continue;
|
|
364
613
|
}
|
|
614
|
+
if (state.mode === "template") {
|
|
615
|
+
content += character;
|
|
616
|
+
if (state.escaped)
|
|
617
|
+
state.escaped = false;
|
|
618
|
+
else if (character === "\\")
|
|
619
|
+
state.escaped = true;
|
|
620
|
+
else if (character === "`")
|
|
621
|
+
state.mode = "code";
|
|
622
|
+
else if (character === "$" && next === "{") {
|
|
623
|
+
content += next;
|
|
624
|
+
index += 1;
|
|
625
|
+
state.mode = "code";
|
|
626
|
+
state.templateExpressionDepths.push(0);
|
|
627
|
+
}
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
365
630
|
if (character === "/" && next === "/")
|
|
366
631
|
break;
|
|
367
632
|
if (character === "/" && next === "*") {
|
|
@@ -378,13 +643,76 @@ function maskSecretCommentsLine(line, state) {
|
|
|
378
643
|
state.mode = character === "'" ? "single" : character === '"' ? "double" : "template";
|
|
379
644
|
state.escaped = false;
|
|
380
645
|
}
|
|
646
|
+
else if (character === "{" && state.templateExpressionDepths.length > 0) {
|
|
647
|
+
const depthIndex = state.templateExpressionDepths.length - 1;
|
|
648
|
+
state.templateExpressionDepths[depthIndex] =
|
|
649
|
+
(state.templateExpressionDepths[depthIndex] ?? 0) + 1;
|
|
650
|
+
}
|
|
651
|
+
else if (character === "}" && state.templateExpressionDepths.length > 0) {
|
|
652
|
+
const depthIndex = state.templateExpressionDepths.length - 1;
|
|
653
|
+
const depth = state.templateExpressionDepths[depthIndex] ?? 0;
|
|
654
|
+
if (depth === 0) {
|
|
655
|
+
state.templateExpressionDepths.pop();
|
|
656
|
+
state.mode = "template";
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
state.templateExpressionDepths[depthIndex] = depth - 1;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
381
662
|
}
|
|
382
663
|
}
|
|
383
664
|
return content.padEnd(line.length, " ");
|
|
384
665
|
}
|
|
385
666
|
const MAX_SECRET_STATEMENT_LINES = 100;
|
|
386
667
|
const MAX_SECRET_STATEMENT_CHARS = 64_000;
|
|
668
|
+
const MAX_SECRET_STATEMENT_OPERATORS = 100;
|
|
669
|
+
const MAX_SECRET_OPERATOR_WORK = 256_000;
|
|
387
670
|
const MAX_SECRET_FINDING_GROUPS = 20;
|
|
671
|
+
function braceDelta(code) {
|
|
672
|
+
let delta = 0;
|
|
673
|
+
for (const character of code) {
|
|
674
|
+
if (character === "{")
|
|
675
|
+
delta += 1;
|
|
676
|
+
else if (character === "}")
|
|
677
|
+
delta -= 1;
|
|
678
|
+
}
|
|
679
|
+
return delta;
|
|
680
|
+
}
|
|
681
|
+
function markOldPackageLockMembers(lines, filename) {
|
|
682
|
+
if (!/(?:^|\/)(?:npm-shrinkwrap|package-lock)\.json$/iu.test(filename))
|
|
683
|
+
return;
|
|
684
|
+
let depth = 0;
|
|
685
|
+
let dependencyDepths = [];
|
|
686
|
+
let activeHunk = lines[0]?.hunk ?? 0;
|
|
687
|
+
for (const line of lines) {
|
|
688
|
+
if (line.hunk !== activeHunk) {
|
|
689
|
+
depth = 0;
|
|
690
|
+
dependencyDepths = [];
|
|
691
|
+
activeHunk = line.hunk;
|
|
692
|
+
}
|
|
693
|
+
const match = line.semantic.match(/^\s*[{,]?\s*("(?:\\.|[^"\\])*")\s*:\s*/u);
|
|
694
|
+
if (match?.[1]) {
|
|
695
|
+
const key = parseJsonString(match[1]);
|
|
696
|
+
const keyOffset = match[0].indexOf(match[1]);
|
|
697
|
+
const keyDepth = depth + braceDelta(line.code.slice(0, keyOffset));
|
|
698
|
+
const valueOffset = match[0].length;
|
|
699
|
+
const valueCode = line.code.slice(valueOffset).trimStart();
|
|
700
|
+
if (key !== null && valueCode.startsWith("{")) {
|
|
701
|
+
const explicitPackagePath = /^node_modules\//u.test(key) ||
|
|
702
|
+
/^@[a-z0-9._-]+\/[a-z0-9][a-z0-9._-]*$/u.test(key);
|
|
703
|
+
if (explicitPackagePath || dependencyDepths.includes(keyDepth)) {
|
|
704
|
+
line.packageLockPackageMemberKey = key;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (key === "dependencies" && valueCode.startsWith("{")) {
|
|
708
|
+
const valueDepth = depth + braceDelta(line.code.slice(0, valueOffset));
|
|
709
|
+
dependencyDepths.push(valueDepth + 1);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
depth = Math.max(0, depth + braceDelta(line.code));
|
|
713
|
+
dependencyDepths = dependencyDepths.filter((dependencyDepth) => depth >= dependencyDepth);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
388
716
|
function bracketDepth(code) {
|
|
389
717
|
let depth = 0;
|
|
390
718
|
for (const character of code) {
|
|
@@ -396,16 +724,142 @@ function bracketDepth(code) {
|
|
|
396
724
|
}
|
|
397
725
|
return depth;
|
|
398
726
|
}
|
|
399
|
-
function
|
|
727
|
+
function parseJsonString(value) {
|
|
728
|
+
try {
|
|
729
|
+
const parsed = JSON.parse(value.trim());
|
|
730
|
+
return typeof parsed === "string" ? parsed : null;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function isStandaloneJsonCredentialKey(value, filename) {
|
|
737
|
+
const parsed = parseJsonString(value);
|
|
738
|
+
return parsed !== null && isJsonCredentialTarget(filename, parsed);
|
|
739
|
+
}
|
|
740
|
+
function jsonStringValues(expression) {
|
|
741
|
+
const values = [];
|
|
742
|
+
for (let index = 0; index < expression.length; index += 1) {
|
|
743
|
+
if (expression[index] !== '"')
|
|
744
|
+
continue;
|
|
745
|
+
let escaped = false;
|
|
746
|
+
let end = -1;
|
|
747
|
+
for (let cursor = index + 1; cursor < expression.length; cursor += 1) {
|
|
748
|
+
const character = expression[cursor] ?? "";
|
|
749
|
+
if (escaped) {
|
|
750
|
+
escaped = false;
|
|
751
|
+
}
|
|
752
|
+
else if (character === "\\") {
|
|
753
|
+
escaped = true;
|
|
754
|
+
}
|
|
755
|
+
else if (character === '"') {
|
|
756
|
+
end = cursor + 1;
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (end < 0)
|
|
761
|
+
break;
|
|
762
|
+
const parsed = parseJsonString(expression.slice(index, end));
|
|
763
|
+
let next = end;
|
|
764
|
+
while (/\s/u.test(expression[next] ?? ""))
|
|
765
|
+
next += 1;
|
|
766
|
+
if (parsed !== null && expression[next] !== ":") {
|
|
767
|
+
values.push({ value: parsed, start: index, end });
|
|
768
|
+
}
|
|
769
|
+
index = end - 1;
|
|
770
|
+
}
|
|
771
|
+
return values;
|
|
772
|
+
}
|
|
773
|
+
function jsonCredentialMemberKeyExists(expression, filename, ignoredPackageMemberKey) {
|
|
774
|
+
for (let index = 0; index < expression.length; index += 1) {
|
|
775
|
+
if (expression[index] !== '"')
|
|
776
|
+
continue;
|
|
777
|
+
let escaped = false;
|
|
778
|
+
let end = -1;
|
|
779
|
+
for (let cursor = index + 1; cursor < expression.length; cursor += 1) {
|
|
780
|
+
const character = expression[cursor] ?? "";
|
|
781
|
+
if (escaped)
|
|
782
|
+
escaped = false;
|
|
783
|
+
else if (character === "\\")
|
|
784
|
+
escaped = true;
|
|
785
|
+
else if (character === '"') {
|
|
786
|
+
end = cursor + 1;
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (end < 0)
|
|
791
|
+
break;
|
|
792
|
+
const parsed = parseJsonString(expression.slice(index, end));
|
|
793
|
+
let next = end;
|
|
794
|
+
while (/\s/u.test(expression[next] ?? ""))
|
|
795
|
+
next += 1;
|
|
796
|
+
if (parsed !== null &&
|
|
797
|
+
expression[next] === ":" &&
|
|
798
|
+
parsed !== ignoredPackageMemberKey &&
|
|
799
|
+
isJsonCredentialTarget(filename, parsed)) {
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
index = end - 1;
|
|
803
|
+
}
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
function decodedJsonMemberKey(semantic, code, colonIndex) {
|
|
807
|
+
const targetStart = assignmentTargetStart(code, colonIndex);
|
|
808
|
+
return parseJsonString(semantic.slice(targetStart, colonIndex));
|
|
809
|
+
}
|
|
810
|
+
function secretOperatorAnalysisExceedsLimit(code, operatorIndexes) {
|
|
811
|
+
return (operatorIndexes.length > MAX_SECRET_STATEMENT_OPERATORS ||
|
|
812
|
+
code.length * operatorIndexes.length > MAX_SECRET_OPERATOR_WORK);
|
|
813
|
+
}
|
|
814
|
+
function jsonSecretStatementContinues(code, semantic, nextMeaningfulCode, colonIndexes, filename, ignoredPackageMemberKey) {
|
|
815
|
+
if (colonIndexes.length === 0) {
|
|
816
|
+
if (!/^\s*:/u.test(nextMeaningfulCode ?? ""))
|
|
817
|
+
return false;
|
|
818
|
+
const standaloneKey = parseJsonString(semantic);
|
|
819
|
+
return standaloneKey !== null && isJsonCredentialTarget(filename, standaloneKey);
|
|
820
|
+
}
|
|
821
|
+
for (const colonIndex of colonIndexes) {
|
|
822
|
+
const memberKey = decodedJsonMemberKey(semantic, code, colonIndex);
|
|
823
|
+
if (memberKey === null ||
|
|
824
|
+
memberKey === ignoredPackageMemberKey ||
|
|
825
|
+
!isJsonCredentialTarget(filename, memberKey)) {
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
const valueEnd = jsonMemberExpressionEnd(code, colonIndex + 1);
|
|
829
|
+
const semanticValue = semantic.slice(colonIndex + 1, valueEnd).trim();
|
|
830
|
+
if (semanticValue.length === 0)
|
|
831
|
+
return true;
|
|
832
|
+
if (bracketDepth(code.slice(colonIndex + 1, valueEnd)) > 0)
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
function buildSecretStatements(lines, jsonFilename, sourceFilename = jsonFilename ?? "") {
|
|
838
|
+
const lineDelimited = jsonFilename !== undefined;
|
|
400
839
|
const statements = [];
|
|
401
840
|
let raw = "";
|
|
402
841
|
let code = "";
|
|
403
842
|
let semantic = "";
|
|
404
843
|
let added = [];
|
|
405
844
|
let lineCount = 0;
|
|
406
|
-
let containsAddedLine = false;
|
|
407
845
|
let truncated = false;
|
|
846
|
+
let credentialRelevant = false;
|
|
847
|
+
let packageLockPackageMemberKey = null;
|
|
408
848
|
let activeHunk = lines[0]?.hunk ?? 0;
|
|
849
|
+
const nextMeaningfulByIndex = Array.from({
|
|
850
|
+
length: lines.length,
|
|
851
|
+
});
|
|
852
|
+
let nextMeaningfulLine;
|
|
853
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
854
|
+
const line = lines[index];
|
|
855
|
+
if (!line)
|
|
856
|
+
continue;
|
|
857
|
+
if (nextMeaningfulLine?.hunk !== line.hunk)
|
|
858
|
+
nextMeaningfulLine = undefined;
|
|
859
|
+
nextMeaningfulByIndex[index] = nextMeaningfulLine;
|
|
860
|
+
if (line.code.trim().length > 0)
|
|
861
|
+
nextMeaningfulLine = line;
|
|
862
|
+
}
|
|
409
863
|
const flush = () => {
|
|
410
864
|
if (semantic.trim().length > 0) {
|
|
411
865
|
statements.push({
|
|
@@ -414,8 +868,11 @@ function buildSecretStatements(lines) {
|
|
|
414
868
|
code,
|
|
415
869
|
semantic,
|
|
416
870
|
added,
|
|
417
|
-
containsAddedLine,
|
|
418
871
|
truncated,
|
|
872
|
+
credentialRelevant: credentialRelevant ||
|
|
873
|
+
(jsonFilename !== undefined &&
|
|
874
|
+
jsonCredentialMemberKeyExists(semantic, jsonFilename, packageLockPackageMemberKey)),
|
|
875
|
+
packageLockPackageMemberKey,
|
|
419
876
|
});
|
|
420
877
|
}
|
|
421
878
|
raw = "";
|
|
@@ -423,8 +880,9 @@ function buildSecretStatements(lines) {
|
|
|
423
880
|
semantic = "";
|
|
424
881
|
added = [];
|
|
425
882
|
lineCount = 0;
|
|
426
|
-
containsAddedLine = false;
|
|
427
883
|
truncated = false;
|
|
884
|
+
credentialRelevant = false;
|
|
885
|
+
packageLockPackageMemberKey = null;
|
|
428
886
|
};
|
|
429
887
|
for (let index = 0; index < lines.length; index += 1) {
|
|
430
888
|
const line = lines[index];
|
|
@@ -434,6 +892,11 @@ function buildSecretStatements(lines) {
|
|
|
434
892
|
flush();
|
|
435
893
|
activeHunk = line.hunk;
|
|
436
894
|
}
|
|
895
|
+
packageLockPackageMemberKey ??= line.packageLockPackageMemberKey ?? null;
|
|
896
|
+
if (jsonFilename !== undefined &&
|
|
897
|
+
jsonCredentialMemberKeyExists(line.semantic, jsonFilename, packageLockPackageMemberKey)) {
|
|
898
|
+
credentialRelevant = true;
|
|
899
|
+
}
|
|
437
900
|
const capacity = Math.max(0, MAX_SECRET_STATEMENT_CHARS - raw.length - 1);
|
|
438
901
|
const length = Math.min(line.text.length, capacity);
|
|
439
902
|
raw += `${line.text.slice(0, length)}\n`;
|
|
@@ -444,24 +907,35 @@ function buildSecretStatements(lines) {
|
|
|
444
907
|
added.push(false);
|
|
445
908
|
if (length < line.text.length)
|
|
446
909
|
truncated = true;
|
|
447
|
-
containsAddedLine ||= line.added;
|
|
448
910
|
lineCount += 1;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (candidate.code.trim().length > 0) {
|
|
455
|
-
nextMeaningful = candidate;
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
911
|
+
const nextMeaningful = nextMeaningfulByIndex[index];
|
|
912
|
+
if (lineDelimited &&
|
|
913
|
+
/^\s*:/u.test(nextMeaningful?.code ?? "") &&
|
|
914
|
+
isStandaloneJsonCredentialKey(semantic, jsonFilename ?? "")) {
|
|
915
|
+
credentialRelevant = true;
|
|
458
916
|
}
|
|
459
917
|
const trimmedCode = code.trimEnd();
|
|
460
|
-
const
|
|
918
|
+
const nextCode = nextMeaningful?.code ?? "";
|
|
919
|
+
const continues = line.lexicallyOpenAfter ||
|
|
461
920
|
bracketDepth(code) > 0 ||
|
|
462
921
|
/(?:[=+%.,?:|&\\]|\b(?:return|yield))\s*$/.test(trimmedCode) ||
|
|
463
|
-
/^\s*(?:[=+%]
|
|
464
|
-
|
|
922
|
+
/^\s*(?:[=+%]|\?|\.(?:append|concat|format|join)\b)/.test(nextCode) ||
|
|
923
|
+
(/^\s*:/.test(nextCode) &&
|
|
924
|
+
analyzeAssignmentOperators(code, sourceFilename).hasPendingTernary);
|
|
925
|
+
// JSON member values can start after a newline, and credential arrays or
|
|
926
|
+
// objects need bounded grouping. Neutral container members stay line-local
|
|
927
|
+
// so a whole lockfile is not misclassified as one unterminated statement.
|
|
928
|
+
const jsonColonIndexes = lineDelimited
|
|
929
|
+
? assignmentOperatorIndexes(code, sourceFilename).filter((operatorIndex) => code[operatorIndex] === ":")
|
|
930
|
+
: [];
|
|
931
|
+
const jsonContinues = lineDelimited
|
|
932
|
+
? secretOperatorAnalysisExceedsLimit(code, jsonColonIndexes)
|
|
933
|
+
? continues
|
|
934
|
+
: jsonSecretStatementContinues(code, semantic, nextMeaningful?.code, jsonColonIndexes, jsonFilename ?? "", packageLockPackageMemberKey)
|
|
935
|
+
: false;
|
|
936
|
+
const terminated = lineDelimited
|
|
937
|
+
? !jsonContinues
|
|
938
|
+
: /;\s*$/.test(line.code) || !continues;
|
|
465
939
|
const limitReached = lineCount >= MAX_SECRET_STATEMENT_LINES || raw.length >= MAX_SECRET_STATEMENT_CHARS;
|
|
466
940
|
if (!terminated && limitReached)
|
|
467
941
|
truncated = true;
|
|
@@ -473,35 +947,138 @@ function buildSecretStatements(lines) {
|
|
|
473
947
|
flush();
|
|
474
948
|
return statements;
|
|
475
949
|
}
|
|
476
|
-
function
|
|
950
|
+
function analyzeAssignmentOperators(code, filename = "") {
|
|
477
951
|
const indexes = [];
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
952
|
+
const syntaxCode = maskRegularExpressionLiterals(code);
|
|
953
|
+
const nextSignificantByIndex = nextSignificantCharacters(syntaxCode);
|
|
954
|
+
const ternaryCountsByDepth = new Map();
|
|
955
|
+
let depth = 0;
|
|
956
|
+
for (let index = 0; index < syntaxCode.length; index += 1) {
|
|
957
|
+
const character = syntaxCode[index] ?? "";
|
|
958
|
+
const previous = syntaxCode[index - 1] ?? "";
|
|
959
|
+
const next = syntaxCode[index + 1] ?? "";
|
|
960
|
+
if (character === "(" || character === "[" || character === "{") {
|
|
961
|
+
depth += 1;
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (character === ")" || character === "]" || character === "}") {
|
|
965
|
+
ternaryCountsByDepth.delete(depth);
|
|
966
|
+
depth = Math.max(0, depth - 1);
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
if (isTernaryQuestion(syntaxCode, index, nextSignificantByIndex[index] ?? "", filename)) {
|
|
970
|
+
ternaryCountsByDepth.set(depth, (ternaryCountsByDepth.get(depth) ?? 0) + 1);
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
if (character === ";") {
|
|
974
|
+
ternaryCountsByDepth.delete(depth);
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
482
977
|
if (character === "=") {
|
|
483
978
|
if (next === "=" || next === ">" || /[=!<>]/.test(previous))
|
|
484
979
|
continue;
|
|
485
980
|
indexes.push(index);
|
|
486
981
|
}
|
|
487
982
|
else if (character === ":") {
|
|
983
|
+
const ternaryCount = ternaryCountsByDepth.get(depth) ?? 0;
|
|
984
|
+
if (ternaryCount > 0) {
|
|
985
|
+
if (ternaryCount === 1)
|
|
986
|
+
ternaryCountsByDepth.delete(depth);
|
|
987
|
+
else
|
|
988
|
+
ternaryCountsByDepth.set(depth, ternaryCount - 1);
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
488
991
|
if (next === "=" || previous === ":" || previous === "?")
|
|
489
992
|
continue;
|
|
490
993
|
indexes.push(index);
|
|
491
994
|
}
|
|
492
995
|
}
|
|
493
|
-
return
|
|
996
|
+
return {
|
|
997
|
+
indexes,
|
|
998
|
+
hasPendingTernary: [...ternaryCountsByDepth.values()].some((count) => count > 0),
|
|
999
|
+
};
|
|
494
1000
|
}
|
|
495
|
-
function
|
|
496
|
-
|
|
497
|
-
|
|
1001
|
+
function assignmentOperatorIndexes(code, filename = "") {
|
|
1002
|
+
return analyzeAssignmentOperators(code, filename).indexes;
|
|
1003
|
+
}
|
|
1004
|
+
function nextSignificantCharacters(code) {
|
|
1005
|
+
const result = new Array(code.length).fill("");
|
|
1006
|
+
let nextSignificant = "";
|
|
1007
|
+
for (let index = code.length - 1; index >= 0; index -= 1) {
|
|
1008
|
+
result[index] = nextSignificant;
|
|
498
1009
|
const character = code[index] ?? "";
|
|
1010
|
+
if (!/\s/u.test(character))
|
|
1011
|
+
nextSignificant = character;
|
|
1012
|
+
}
|
|
1013
|
+
return result;
|
|
1014
|
+
}
|
|
1015
|
+
function isTernaryQuestion(code, index, nextSignificant, filename = "") {
|
|
1016
|
+
const previous = code[index - 1] ?? "";
|
|
1017
|
+
const next = code[index + 1] ?? "";
|
|
1018
|
+
const optionalChaining = next === "." && !/\d/u.test(code[index + 2] ?? "");
|
|
1019
|
+
const rustPostfix = /\.rs$/iu.test(filename);
|
|
1020
|
+
const rubyPredicate = isRubySourceFilename(filename) &&
|
|
1021
|
+
/[A-Za-z0-9_]/u.test(previous);
|
|
1022
|
+
const swiftOptionalOperator = /\.swift$/iu.test(filename) &&
|
|
1023
|
+
/(?:^|[^A-Za-z0-9_])(?:try|as)\s*$/u.test(code.slice(Math.max(0, index - 12), index));
|
|
1024
|
+
const phpNullsafeOperator = /\.php$/iu.test(filename) && /^\?\s*->/u.test(code.slice(index, index + 6));
|
|
1025
|
+
const elixirCharacterLiteral = /\.exs?$/iu.test(filename);
|
|
1026
|
+
return (code[index] === "?" &&
|
|
1027
|
+
!rustPostfix &&
|
|
1028
|
+
!rubyPredicate &&
|
|
1029
|
+
!swiftOptionalOperator &&
|
|
1030
|
+
!phpNullsafeOperator &&
|
|
1031
|
+
!elixirCharacterLiteral &&
|
|
1032
|
+
previous !== "?" &&
|
|
1033
|
+
next !== "?" &&
|
|
1034
|
+
!optionalChaining &&
|
|
1035
|
+
next !== ":" &&
|
|
1036
|
+
!/[?,:;)\]}]/u.test(nextSignificant));
|
|
1037
|
+
}
|
|
1038
|
+
function isRubySourceFilename(filename) {
|
|
1039
|
+
const basename = filename.split(/[/\\]/u).at(-1) ?? "";
|
|
1040
|
+
return (/\.(?:gemspec|rake|rb|ru)$/iu.test(basename) ||
|
|
1041
|
+
/^(?:Appraisals|Berksfile|Brewfile|Capfile|Dangerfile|Deliverfile|Fastfile|Gemfile|Guardfile|Podfile|Rakefile|Vagrantfile)$/iu.test(basename));
|
|
1042
|
+
}
|
|
1043
|
+
function assignmentExpressionEnd(code, start, filename = "") {
|
|
1044
|
+
const syntaxCode = maskRegularExpressionLiterals(code);
|
|
1045
|
+
const nextSignificantByIndex = nextSignificantCharacters(syntaxCode);
|
|
1046
|
+
let depth = 0;
|
|
1047
|
+
let pendingTernaryCount = 0;
|
|
1048
|
+
for (let index = start; index < syntaxCode.length; index += 1) {
|
|
1049
|
+
const character = syntaxCode[index] ?? "";
|
|
499
1050
|
if (character === "(" || character === "[" || character === "{")
|
|
500
1051
|
depth += 1;
|
|
501
1052
|
else if (character === ")" || character === "]" || character === "}") {
|
|
502
1053
|
depth = Math.max(0, depth - 1);
|
|
503
1054
|
}
|
|
504
|
-
else if (depth === 0 &&
|
|
1055
|
+
else if (depth === 0 &&
|
|
1056
|
+
isTernaryQuestion(syntaxCode, index, nextSignificantByIndex[index] ?? "", filename)) {
|
|
1057
|
+
pendingTernaryCount += 1;
|
|
1058
|
+
}
|
|
1059
|
+
else if (depth === 0 && character === ":" && pendingTernaryCount > 0) {
|
|
1060
|
+
pendingTernaryCount -= 1;
|
|
1061
|
+
}
|
|
1062
|
+
else if (depth === 0 &&
|
|
1063
|
+
(character === ";" || (character === "," && pendingTernaryCount === 0))) {
|
|
1064
|
+
return index;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
return code.length;
|
|
1068
|
+
}
|
|
1069
|
+
function jsonMemberExpressionEnd(code, start) {
|
|
1070
|
+
let depth = 0;
|
|
1071
|
+
for (let index = start; index < code.length; index += 1) {
|
|
1072
|
+
const character = code[index] ?? "";
|
|
1073
|
+
if (character === "(" || character === "[" || character === "{") {
|
|
1074
|
+
depth += 1;
|
|
1075
|
+
}
|
|
1076
|
+
else if (character === ")" || character === "]" || character === "}") {
|
|
1077
|
+
if (depth === 0)
|
|
1078
|
+
return index;
|
|
1079
|
+
depth -= 1;
|
|
1080
|
+
}
|
|
1081
|
+
else if (depth === 0 && character === ",") {
|
|
505
1082
|
return index;
|
|
506
1083
|
}
|
|
507
1084
|
}
|
|
@@ -514,14 +1091,51 @@ function assignmentTargetStart(code, operatorIndex) {
|
|
|
514
1091
|
}
|
|
515
1092
|
return start;
|
|
516
1093
|
}
|
|
517
|
-
function
|
|
518
|
-
|
|
1094
|
+
function terminalAssignmentTargetName(target) {
|
|
1095
|
+
const trimmed = target.trim();
|
|
1096
|
+
const bracketMember = trimmed.match(/\[\s*["']([^"']+)["']\s*\]\s*$/u);
|
|
1097
|
+
if (bracketMember?.[1])
|
|
1098
|
+
return bracketMember[1];
|
|
1099
|
+
const withoutType = trimmed.replace(/\s*:\s*[^:]+$/u, "");
|
|
1100
|
+
return withoutType.match(/([A-Za-z_$][\w$]*)\s*$/u)?.[1] ?? "";
|
|
1101
|
+
}
|
|
1102
|
+
function isCredentialMetadataTarget(target, normalizedTarget) {
|
|
1103
|
+
const terminalName = terminalAssignmentTargetName(target)
|
|
1104
|
+
.toLowerCase()
|
|
1105
|
+
.replace(/[^a-z0-9]/gu, "");
|
|
1106
|
+
return (/^(?:tokenbudget|tokenestimate|tokenestimation)$/u.test(terminalName) ||
|
|
1107
|
+
/(?:apikey|authorization(?:header)?|token|secret|password|credential)(?:bucket|cache|config|count|expir(?:y|es?)|factory|id|index|length|manager|metadata|names?|options|parser|policy|prefix|provider|scan(?:json|toml|ya?ml)?|scanner(?:evidence|provenance|report|result|status)?|service|status|store|strength|suffix|ttl|type|validation|validator|izer|ization)$/u.test(normalizedTarget));
|
|
519
1108
|
}
|
|
520
1109
|
function isCredentialTarget(target) {
|
|
521
1110
|
const normalized = target.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
522
|
-
if (!normalized ||
|
|
1111
|
+
if (!normalized ||
|
|
1112
|
+
isCredentialMetadataTarget(target, normalized)) {
|
|
523
1113
|
return false;
|
|
524
|
-
|
|
1114
|
+
}
|
|
1115
|
+
const words = target
|
|
1116
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
1117
|
+
.toLowerCase()
|
|
1118
|
+
.split(/[^a-z0-9]+/u)
|
|
1119
|
+
.filter(Boolean);
|
|
1120
|
+
const accessKeyTarget = /accesskeyid\d*$/u.test(normalized) ||
|
|
1121
|
+
/awsaccesskey\d*(?:budget|estimate|estimation)?$/u.test(normalized);
|
|
1122
|
+
const qualifiedTokenTarget = /(?:api|auth|access|bearer|client|github|jwt|oauth|refresh|session|slack)token\d*(?:budget|estimate|estimation)?$/u.test(normalized);
|
|
1123
|
+
const qualifiedCredentialMetadataTarget = /(?:authorizationheader|clientsecret|password)\d*(?:budget|estimate|estimation)$/u.test(normalized);
|
|
1124
|
+
const tokenTarget = /(?:^|[^A-Za-z0-9\/-])tokens?\d*(?=$|[^A-Za-z0-9])/iu.test(target) ||
|
|
1125
|
+
/(?:^|[^A-Za-z0-9])tokens?(?=[A-Z])/u.test(target) ||
|
|
1126
|
+
/[A-Za-z0-9](?:Token|Tokens)\d*(?=$|[^A-Za-z0-9])/u.test(target) ||
|
|
1127
|
+
/(?:api|auth|access|bearer|client|github|jwt|oauth|refresh|session|slack)[\/-]tokens?\d*(?=$|[^A-Za-z0-9])/iu.test(target);
|
|
1128
|
+
return (accessKeyTarget ||
|
|
1129
|
+
qualifiedTokenTarget ||
|
|
1130
|
+
qualifiedCredentialMetadataTarget ||
|
|
1131
|
+
tokenTarget ||
|
|
1132
|
+
words.some((word) => /^(?:apikey\d*|authorization(?:header|token)?\d*|clientsecret\d*|credentials?\d*|password\d*|privatekey\d*|secrets?\d*)$/u.test(word)) ||
|
|
1133
|
+
words.some((word, index) => word === "api" && /^(?:keys?|tokens?)\d*$/u.test(words[index + 1] ?? "")) ||
|
|
1134
|
+
words.some((word, index) => (word === "client" && /^secrets?\d*$/u.test(words[index + 1] ?? "")) ||
|
|
1135
|
+
(word === "private" && /^keys?\d*$/u.test(words[index + 1] ?? ""))));
|
|
1136
|
+
}
|
|
1137
|
+
function isJsonCredentialTarget(_filename, target) {
|
|
1138
|
+
return isCredentialTarget(target);
|
|
525
1139
|
}
|
|
526
1140
|
function assignedIdentifier(target) {
|
|
527
1141
|
const match = target
|
|
@@ -550,20 +1164,96 @@ function isTrustedRuntimeSecretExpression(value) {
|
|
|
550
1164
|
remainder = remainder.replace(/^(?:f|undefined|null)$/i, "");
|
|
551
1165
|
return remainder.length === 0;
|
|
552
1166
|
}
|
|
1167
|
+
function regexLiteralCanStart(code, index) {
|
|
1168
|
+
const prefix = code.slice(0, index).trimEnd();
|
|
1169
|
+
if (!prefix)
|
|
1170
|
+
return true;
|
|
1171
|
+
const previous = prefix.at(-1) ?? "";
|
|
1172
|
+
return (/[\[(=,:;!&|?{}]/.test(previous) ||
|
|
1173
|
+
/(?:=>|\b(?:case|return|throw|yield))$/.test(prefix));
|
|
1174
|
+
}
|
|
1175
|
+
function maskRegularExpressionLiterals(value) {
|
|
1176
|
+
const masked = [...value];
|
|
1177
|
+
let quote = null;
|
|
1178
|
+
let quotedEscape = false;
|
|
1179
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1180
|
+
const character = value[index] ?? "";
|
|
1181
|
+
if (quote) {
|
|
1182
|
+
if (quotedEscape) {
|
|
1183
|
+
quotedEscape = false;
|
|
1184
|
+
}
|
|
1185
|
+
else if (character === "\\") {
|
|
1186
|
+
quotedEscape = true;
|
|
1187
|
+
}
|
|
1188
|
+
else if (character === quote) {
|
|
1189
|
+
quote = null;
|
|
1190
|
+
}
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (character === "'" || character === '"' || character === "`") {
|
|
1194
|
+
quote = character;
|
|
1195
|
+
quotedEscape = false;
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
if (character !== "/" ||
|
|
1199
|
+
value[index + 1] === "/" ||
|
|
1200
|
+
value[index + 1] === "*" ||
|
|
1201
|
+
!regexLiteralCanStart(value, index)) {
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
let escaped = false;
|
|
1205
|
+
let inCharacterClass = false;
|
|
1206
|
+
let closingSlash = -1;
|
|
1207
|
+
for (let cursor = index + 1; cursor < value.length; cursor += 1) {
|
|
1208
|
+
const current = value[cursor] ?? "";
|
|
1209
|
+
if (current === "\n" || current === "\r")
|
|
1210
|
+
break;
|
|
1211
|
+
if (escaped) {
|
|
1212
|
+
escaped = false;
|
|
1213
|
+
}
|
|
1214
|
+
else if (current === "\\") {
|
|
1215
|
+
escaped = true;
|
|
1216
|
+
}
|
|
1217
|
+
else if (current === "[") {
|
|
1218
|
+
inCharacterClass = true;
|
|
1219
|
+
}
|
|
1220
|
+
else if (current === "]") {
|
|
1221
|
+
inCharacterClass = false;
|
|
1222
|
+
}
|
|
1223
|
+
else if (current === "/" && !inCharacterClass) {
|
|
1224
|
+
closingSlash = cursor;
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
if (closingSlash < 0)
|
|
1229
|
+
continue;
|
|
1230
|
+
let end = closingSlash + 1;
|
|
1231
|
+
while (/[A-Za-z]/.test(value[end] ?? ""))
|
|
1232
|
+
end += 1;
|
|
1233
|
+
for (let cursor = index; cursor < end; cursor += 1) {
|
|
1234
|
+
if (masked[cursor] !== "\n" && masked[cursor] !== "\r")
|
|
1235
|
+
masked[cursor] = " ";
|
|
1236
|
+
}
|
|
1237
|
+
index = end - 1;
|
|
1238
|
+
}
|
|
1239
|
+
return masked.join("");
|
|
1240
|
+
}
|
|
553
1241
|
function isDynamicSecretExpression(value, codeValue) {
|
|
554
1242
|
const normalized = value.trim();
|
|
555
1243
|
if (!normalized || isTrustedRuntimeSecretExpression(normalized))
|
|
556
1244
|
return false;
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
/\
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1245
|
+
const operatorCode = maskRegularExpressionLiterals(codeValue);
|
|
1246
|
+
const semanticValue = maskRegularExpressionLiterals(normalized);
|
|
1247
|
+
return (operatorCode.includes("+") ||
|
|
1248
|
+
operatorCode.includes("%") ||
|
|
1249
|
+
/\.(?:append|concat|format|join)\s*\(/i.test(operatorCode) ||
|
|
1250
|
+
/\b(?:String\.format|fmt\.Sprintf|format!|concat!)\s*\(/i.test(operatorCode) ||
|
|
1251
|
+
/\b(?:Buffer\.from|Convert\.FromBase64String|String\.fromCharCode|TextDecoder\s*\([^)]*\)\.decode|atob|base64\.(?:b64decode|urlsafe_b64decode)|btoa|decodeURIComponent)\s*\(/i.test(operatorCode) ||
|
|
1252
|
+
/`[^`]*\$\{[^}]+\}[^`]*`/s.test(semanticValue) ||
|
|
1253
|
+
/\bf["'][^"']*\{[^}]+\}[^"']*["']/is.test(semanticValue) ||
|
|
1254
|
+
/\$@?["'][^"']*\{[^}]+\}[^"']*["']/s.test(semanticValue) ||
|
|
1255
|
+
/#\{[^}]+\}|\{\$[A-Za-z_][\w]*\}|\\\([^)]+\)/s.test(semanticValue) ||
|
|
1256
|
+
/["'][^"']*\$[A-Za-z_][\w]*[^"']*["']/s.test(semanticValue));
|
|
567
1257
|
}
|
|
568
1258
|
function assignmentIsInCode(match, codeLine) {
|
|
569
1259
|
const value = match.slice(1).find((capture) => capture !== undefined);
|
|
@@ -577,6 +1267,45 @@ function assignmentIsInCode(match, codeLine) {
|
|
|
577
1267
|
const operatorIndex = match.index + operatorOffset;
|
|
578
1268
|
return (codeLine[operatorIndex] ?? " ").trim().length > 0;
|
|
579
1269
|
}
|
|
1270
|
+
function secretLiteralNamesInLine(text, codeLine, includeQuoted = true) {
|
|
1271
|
+
const names = [];
|
|
1272
|
+
const seenValueSpans = new Set();
|
|
1273
|
+
for (const { name, pattern } of SECRET_ASSIGNMENTS) {
|
|
1274
|
+
let offset = 0;
|
|
1275
|
+
while (offset < text.length) {
|
|
1276
|
+
const match = text.slice(offset).match(pattern);
|
|
1277
|
+
if (!match || match.index === undefined)
|
|
1278
|
+
break;
|
|
1279
|
+
const matchOffset = offset + match.index;
|
|
1280
|
+
if (assignmentIsInCode(match, codeLine.slice(offset))) {
|
|
1281
|
+
const quotedValue = match.slice(1, 4).find((capture) => capture !== undefined);
|
|
1282
|
+
const unquotedValue = match[4];
|
|
1283
|
+
const value = quotedValue ?? unquotedValue;
|
|
1284
|
+
const valueStart = value ? matchOffset + match[0].lastIndexOf(value) : -1;
|
|
1285
|
+
const valueSpan = value ? `${valueStart}:${valueStart + value.length}` : "";
|
|
1286
|
+
if (value &&
|
|
1287
|
+
!seenValueSpans.has(valueSpan) &&
|
|
1288
|
+
!isPlaceholderSecret(value) &&
|
|
1289
|
+
((includeQuoted && quotedValue !== undefined) ||
|
|
1290
|
+
(unquotedValue !== undefined && isHighConfidenceUnquotedSecret(value)))) {
|
|
1291
|
+
names.push(name);
|
|
1292
|
+
seenValueSpans.add(valueSpan);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
offset = matchOffset + Math.max(1, match[0].length);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return names;
|
|
1299
|
+
}
|
|
1300
|
+
function knownUnquotedSecretNamesInCode(codeLine) {
|
|
1301
|
+
const names = [];
|
|
1302
|
+
if (/\bAKIA[0-9A-Z]{16}\b/u.test(codeLine))
|
|
1303
|
+
names.push("AWS access key assignment");
|
|
1304
|
+
if (/\bghp_[A-Za-z0-9]{16,}\b/u.test(codeLine)) {
|
|
1305
|
+
names.push("credential assignment");
|
|
1306
|
+
}
|
|
1307
|
+
return names;
|
|
1308
|
+
}
|
|
580
1309
|
export function scanPatchForSecrets(filename, patch) {
|
|
581
1310
|
if (!patch)
|
|
582
1311
|
return [];
|
|
@@ -584,17 +1313,30 @@ export function scanPatchForSecrets(filename, patch) {
|
|
|
584
1313
|
const patchLines = newSidePatchLines(patch);
|
|
585
1314
|
const scannedLines = [];
|
|
586
1315
|
let activeHunk = -1;
|
|
587
|
-
let codeState = {
|
|
588
|
-
|
|
1316
|
+
let codeState = {
|
|
1317
|
+
mode: "code",
|
|
1318
|
+
escaped: false,
|
|
1319
|
+
templateExpressionDepths: [],
|
|
1320
|
+
};
|
|
1321
|
+
let semanticState = {
|
|
1322
|
+
mode: "code",
|
|
1323
|
+
escaped: false,
|
|
1324
|
+
templateExpressionDepths: [],
|
|
1325
|
+
};
|
|
589
1326
|
for (const line of patchLines) {
|
|
590
1327
|
if (line.hunk !== activeHunk) {
|
|
591
1328
|
activeHunk = line.hunk;
|
|
592
|
-
codeState = { mode: "code", escaped: false };
|
|
593
|
-
semanticState = { mode: "code", escaped: false };
|
|
1329
|
+
codeState = { mode: "code", escaped: false, templateExpressionDepths: [] };
|
|
1330
|
+
semanticState = { mode: "code", escaped: false, templateExpressionDepths: [] };
|
|
594
1331
|
}
|
|
595
1332
|
const code = maskSecretCodeLine(line.text, codeState);
|
|
596
1333
|
const semantic = maskSecretCommentsLine(line.text, semanticState);
|
|
597
|
-
scannedLines.push({
|
|
1334
|
+
scannedLines.push({
|
|
1335
|
+
...line,
|
|
1336
|
+
code,
|
|
1337
|
+
semantic,
|
|
1338
|
+
lexicallyOpenAfter: codeState.mode !== "code" || codeState.templateExpressionDepths.length > 0,
|
|
1339
|
+
});
|
|
598
1340
|
}
|
|
599
1341
|
const findingGroups = new Map();
|
|
600
1342
|
let suppressedGroups = 0;
|
|
@@ -611,22 +1353,49 @@ export function scanPatchForSecrets(filename, patch) {
|
|
|
611
1353
|
}
|
|
612
1354
|
findingGroups.set(key, { finding: item, count: 1 });
|
|
613
1355
|
};
|
|
614
|
-
const
|
|
1356
|
+
const isJsonDocument = /\.jsonc?$/iu.test(normalizedFilename);
|
|
1357
|
+
if (isJsonDocument)
|
|
1358
|
+
markOldPackageLockMembers(scannedLines, normalizedFilename);
|
|
1359
|
+
const statements = buildSecretStatements(scannedLines, isJsonDocument ? normalizedFilename : undefined, normalizedFilename);
|
|
1360
|
+
const hunksWithMeaningfulAdditions = new Set(scannedLines
|
|
1361
|
+
.filter((line) => line.added && line.semantic.trim().length > 0)
|
|
1362
|
+
.map((line) => line.hunk));
|
|
615
1363
|
const credentialAliasesByHunk = new Map();
|
|
616
1364
|
for (const statement of statements) {
|
|
617
1365
|
const aliases = credentialAliasesByHunk.get(statement.hunk) ?? new Set();
|
|
618
1366
|
credentialAliasesByHunk.set(statement.hunk, aliases);
|
|
619
|
-
|
|
620
|
-
|
|
1367
|
+
let dynamicConstructionRecorded = false;
|
|
1368
|
+
const recordedJsonLiteralSpans = new Set();
|
|
1369
|
+
const operatorIndexes = assignmentOperatorIndexes(statement.code, normalizedFilename);
|
|
1370
|
+
const operatorAnalysisLimited = secretOperatorAnalysisExceedsLimit(statement.code, operatorIndexes);
|
|
1371
|
+
const statementHasMeaningfulAddition = statement.added.some((isAdded, index) => isAdded && /\S/u.test(statement.semantic[index] ?? ""));
|
|
1372
|
+
if ((statement.truncated || operatorAnalysisLimited) &&
|
|
1373
|
+
(statementHasMeaningfulAddition ||
|
|
1374
|
+
(statement.credentialRelevant && hunksWithMeaningfulAdditions.has(statement.hunk)))) {
|
|
1375
|
+
recordFinding(finding("high", "SecretScanEvidenceIncomplete", "security", `An added statement in \`${normalizedFilename}\` exceeded the bounded secret heuristic.`, [normalizedFilename], operatorAnalysisLimited
|
|
1376
|
+
? `The statement exceeded the ${MAX_SECRET_STATEMENT_OPERATORS}-operator or ${MAX_SECRET_OPERATOR_WORK.toLocaleString("en-US")}-work-unit analysis limit, so the patch-local heuristic stopped before repeated member scans could become unbounded.`
|
|
1377
|
+
: `The statement exceeded the ${MAX_SECRET_STATEMENT_LINES}-line or ${MAX_SECRET_STATEMENT_CHARS.toLocaleString("en-US")}-character limit, so the patch-local heuristic cannot safely inspect all credential construction after the limit.`, "Split the statement into reviewable units and require trusted scanner or SAST evidence plus manual review before merging."));
|
|
621
1378
|
}
|
|
622
|
-
|
|
1379
|
+
if (operatorAnalysisLimited)
|
|
1380
|
+
continue;
|
|
1381
|
+
for (const operatorIndex of operatorIndexes) {
|
|
623
1382
|
const targetStart = assignmentTargetStart(statement.code, operatorIndex);
|
|
624
|
-
const expressionEnd =
|
|
1383
|
+
const expressionEnd = isJsonDocument
|
|
1384
|
+
? jsonMemberExpressionEnd(statement.code, operatorIndex + 1)
|
|
1385
|
+
: assignmentExpressionEnd(statement.code, operatorIndex + 1, normalizedFilename);
|
|
625
1386
|
const target = statement.raw.slice(targetStart, operatorIndex);
|
|
626
1387
|
const expression = statement.semantic.slice(operatorIndex + 1, expressionEnd);
|
|
627
1388
|
const codeExpression = statement.code.slice(operatorIndex + 1, expressionEnd);
|
|
628
1389
|
const codeTarget = statement.code.slice(targetStart, operatorIndex);
|
|
629
1390
|
const usesCredentialAlias = targetUsesCredentialAlias(target, aliases);
|
|
1391
|
+
const jsonMemberKey = isJsonDocument
|
|
1392
|
+
? decodedJsonMemberKey(statement.semantic, statement.code, operatorIndex)
|
|
1393
|
+
: null;
|
|
1394
|
+
const hasCredentialTarget = isJsonDocument
|
|
1395
|
+
? jsonMemberKey !== null &&
|
|
1396
|
+
jsonMemberKey !== statement.packageLockPackageMemberKey &&
|
|
1397
|
+
isJsonCredentialTarget(normalizedFilename, jsonMemberKey)
|
|
1398
|
+
: isCredentialTarget(target);
|
|
630
1399
|
const meaningfulAdded = statement.added
|
|
631
1400
|
.slice(targetStart, expressionEnd)
|
|
632
1401
|
.some((isAdded, offset) => {
|
|
@@ -635,12 +1404,48 @@ export function scanPatchForSecrets(filename, patch) {
|
|
|
635
1404
|
const absolute = targetStart + offset;
|
|
636
1405
|
return /\S/.test(statement.semantic[absolute] ?? "");
|
|
637
1406
|
});
|
|
1407
|
+
if (isJsonDocument && meaningfulAdded) {
|
|
1408
|
+
const targetMeaningfulAdded = statement.added
|
|
1409
|
+
.slice(targetStart, operatorIndex)
|
|
1410
|
+
.some((isAdded, offset) => {
|
|
1411
|
+
if (!isAdded)
|
|
1412
|
+
return false;
|
|
1413
|
+
return /\S/.test(statement.semantic[targetStart + offset] ?? "");
|
|
1414
|
+
});
|
|
1415
|
+
for (const literal of jsonStringValues(expression)) {
|
|
1416
|
+
const literalStart = operatorIndex + 1 + literal.start;
|
|
1417
|
+
const literalMeaningfulAdded = statement.added
|
|
1418
|
+
.slice(literalStart, operatorIndex + 1 + literal.end)
|
|
1419
|
+
.some((isAdded, offset) => {
|
|
1420
|
+
if (!isAdded)
|
|
1421
|
+
return false;
|
|
1422
|
+
return /\S/.test(statement.semantic[literalStart + offset] ?? "");
|
|
1423
|
+
});
|
|
1424
|
+
if (!targetMeaningfulAdded && !literalMeaningfulAdded)
|
|
1425
|
+
continue;
|
|
1426
|
+
if (isPlaceholderSecret(literal.value))
|
|
1427
|
+
continue;
|
|
1428
|
+
const literalName = hasCredentialTarget
|
|
1429
|
+
? "credential assignment"
|
|
1430
|
+
: knownCredentialLiteralName(literal.value);
|
|
1431
|
+
if (literalName !== null) {
|
|
1432
|
+
const literalSpan = `${literalStart}:${operatorIndex + 1 + literal.end}`;
|
|
1433
|
+
if (recordedJsonLiteralSpans.has(literalSpan))
|
|
1434
|
+
continue;
|
|
1435
|
+
recordedJsonLiteralSpans.add(literalSpan);
|
|
1436
|
+
recordFinding(finding("high", "SecretLikeAssignment", "security", `Possible ${literalName} added in \`${normalizedFilename}\`.`, [normalizedFilename], "The added JSON member assigns a non-placeholder literal to a credential-like name or known credential format.", "Confirm this is not a real credential; if it is, remove and rotate it, then load it from a secret store or environment variable."));
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
638
1440
|
if (meaningfulAdded &&
|
|
639
|
-
(usesCredentialAlias ||
|
|
1441
|
+
(usesCredentialAlias || hasCredentialTarget) &&
|
|
640
1442
|
(usesCredentialAlias ||
|
|
641
1443
|
isDynamicSecretExpression(expression, codeExpression) ||
|
|
642
1444
|
isDynamicSecretExpression(target, codeTarget))) {
|
|
643
|
-
|
|
1445
|
+
if (!dynamicConstructionRecorded) {
|
|
1446
|
+
recordFinding(finding("high", "DynamicSecretConstruction", "security", `Credential-like value is dynamically constructed in \`${normalizedFilename}\`.`, [normalizedFilename], "An added part of this assignment combines, interpolates, formats, joins, decodes, or indirectly assigns data into a credential-like target, so patch-local literal matching cannot establish whether the result is safe.", "Verify every input source, remove hardcoded fragments, prefer a secret manager or environment variable, and require trusted scanner or SAST evidence plus manual review."));
|
|
1447
|
+
dynamicConstructionRecorded = true;
|
|
1448
|
+
}
|
|
644
1449
|
}
|
|
645
1450
|
const identifier = assignedIdentifier(target);
|
|
646
1451
|
if (identifier &&
|
|
@@ -662,32 +1467,21 @@ export function scanPatchForSecrets(filename, patch) {
|
|
|
662
1467
|
.some((isAdded, offset) => isAdded ? /\S/.test(statement.semantic[match.index + offset] ?? "") : false);
|
|
663
1468
|
if (!meaningfulAdded || !isDynamicSecretExpression(expression, codeExpression))
|
|
664
1469
|
continue;
|
|
665
|
-
|
|
1470
|
+
if (!dynamicConstructionRecorded) {
|
|
1471
|
+
recordFinding(finding("high", "DynamicSecretConstruction", "security", `Credential-like value is dynamically constructed in \`${normalizedFilename}\`.`, [normalizedFilename], "An added API call constructs a credential-like header value dynamically, so patch-local literal matching cannot establish whether the result is safe.", "Verify every input source, remove hardcoded fragments, prefer a secret manager or environment variable, and require trusted scanner or SAST evidence plus manual review."));
|
|
1472
|
+
dynamicConstructionRecorded = true;
|
|
1473
|
+
}
|
|
666
1474
|
}
|
|
667
1475
|
}
|
|
668
1476
|
for (const line of scannedLines) {
|
|
669
|
-
const codeLine = line.code;
|
|
670
1477
|
if (!line.added)
|
|
671
1478
|
continue;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const matchOffset = offset + match.index;
|
|
679
|
-
if (assignmentIsInCode(match, codeLine.slice(offset))) {
|
|
680
|
-
const quotedValue = match.slice(1, 4).find((capture) => capture !== undefined);
|
|
681
|
-
const unquotedValue = match[4];
|
|
682
|
-
const value = quotedValue ?? unquotedValue;
|
|
683
|
-
if (value &&
|
|
684
|
-
!isPlaceholderSecret(value) &&
|
|
685
|
-
(quotedValue !== undefined || isHighConfidenceUnquotedSecret(value))) {
|
|
686
|
-
recordFinding(finding("high", "SecretLikeAssignment", "security", `Possible ${name} added in \`${normalizedFilename}\`.`, [normalizedFilename], "The added patch line assigns a non-placeholder literal to a credential-like name.", "Confirm this is not a real credential; if it is, remove and rotate it, then load it from a secret store or environment variable."));
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
offset = matchOffset + Math.max(1, match[0].length);
|
|
690
|
-
}
|
|
1479
|
+
const assignmentNames = secretLiteralNamesInLine(line.text, line.code, !isJsonDocument);
|
|
1480
|
+
const names = isJsonDocument && assignmentNames.length === 0
|
|
1481
|
+
? knownUnquotedSecretNamesInCode(line.code)
|
|
1482
|
+
: assignmentNames;
|
|
1483
|
+
for (const name of names) {
|
|
1484
|
+
recordFinding(finding("high", "SecretLikeAssignment", "security", `Possible ${name} added in \`${normalizedFilename}\`.`, [normalizedFilename], "The added patch line assigns a non-placeholder literal to a credential-like name.", "Confirm this is not a real credential; if it is, remove and rotate it, then load it from a secret store or environment variable."));
|
|
691
1485
|
}
|
|
692
1486
|
}
|
|
693
1487
|
const findings = [...findingGroups.values()].map(({ finding: item, count }) => count > 1
|
|
@@ -1062,12 +1856,30 @@ function addWorkTypeEvidenceFindings(workType, title, body, classified, findings
|
|
|
1062
1856
|
}
|
|
1063
1857
|
if (workType === "security") {
|
|
1064
1858
|
const requirements = [
|
|
1065
|
-
[
|
|
1066
|
-
|
|
1067
|
-
|
|
1859
|
+
[
|
|
1860
|
+
"threat|threats|threat model|threat analysis|threat and risk analysis|risk analysis|威胁|威胁模型|威胁与风险分析|风险分析",
|
|
1861
|
+
/\b(?:threat|attack|vulnerability|risk)\b|威胁|攻击|漏洞|风险/i,
|
|
1862
|
+
/\b(?:attacker|abuse|bypass|compromis(?:e|ed)|exploit|impact|may|mitigat(?:e|ion)|stolen|vector)\b|攻击者|缓解|可能|利用|影响|诱导|导致|绕过/i,
|
|
1863
|
+
"MissingThreatAnalysis",
|
|
1864
|
+
"threat or risk",
|
|
1865
|
+
],
|
|
1866
|
+
[
|
|
1867
|
+
"permission|permissions|permission impact|access impact|权限|权限影响|权限分析",
|
|
1868
|
+
/\b(?:access|authorization|permission|privilege)\b|访问|授权|权限|特权/i,
|
|
1869
|
+
/\b(?:deny|grant|least[ -]?privilege|no new|read[ -]?only|scope|unchanged)\b|不新增|不授予|只读|最小权限|禁止|保持不变|范围/i,
|
|
1870
|
+
"MissingPermissionAnalysis",
|
|
1871
|
+
"permission impact",
|
|
1872
|
+
],
|
|
1873
|
+
[
|
|
1874
|
+
"secret|secrets|credential and secret handling|secret handling|credential handling|密钥|密钥与凭据处理|凭据处理|密钥处理",
|
|
1875
|
+
/\b(?:credential|key|secret|token)\b|凭据|密钥|令牌|口令/i,
|
|
1876
|
+
/\b(?:existing (?:secret )?store|no real|placeholder|redact(?:ed|ion)|remain|vault)\b|不记录|不输出|不泄露|占位符|脱敏|保留|存储/i,
|
|
1877
|
+
"MissingSecretAnalysis",
|
|
1878
|
+
"credential and secret handling",
|
|
1879
|
+
],
|
|
1068
1880
|
];
|
|
1069
|
-
for (const [pattern, category, subject] of requirements) {
|
|
1070
|
-
if (
|
|
1881
|
+
for (const [sectionNames, pattern, detailPattern, category, subject] of requirements) {
|
|
1882
|
+
if (hasSubstantiveEvidence(body, sectionNames, pattern, detailPattern))
|
|
1071
1883
|
continue;
|
|
1072
1884
|
findings.push(finding("high", category, "security", `Security work does not document ${subject}.`, paths, `The approved security review standard requires an explicit ${subject} assessment.`, `Document the ${subject} and the evidence used to validate it.`));
|
|
1073
1885
|
}
|
|
@@ -1093,8 +1905,8 @@ function addSecretScannerEvidenceFinding(evidence, findings) {
|
|
|
1093
1905
|
return;
|
|
1094
1906
|
findings.push(finding(issue.severity, issue.category, "security", issue.description, [], issue.reason, issue.suggestion));
|
|
1095
1907
|
}
|
|
1096
|
-
function addStrictFindings(classified, totalChangedLines, findings) {
|
|
1097
|
-
if (totalChangedLines <= 800)
|
|
1908
|
+
function addStrictFindings(classified, totalChangedLines, body, findings) {
|
|
1909
|
+
if (totalChangedLines <= 800 || hasAtomicScopeRationale(body))
|
|
1098
1910
|
return;
|
|
1099
1911
|
findings.push(finding("medium", "LargeChangeScope", "scope", `The PR changes ${totalChangedLines} lines, which is difficult to review as one unit.`, classified.allFiles.map((file) => file.filename), "Large diffs increase the chance that intent, tests, or security-sensitive details are missed during review.", "Split independent concerns into smaller PRs, or document why this change must remain atomic."));
|
|
1100
1912
|
}
|
|
@@ -1136,16 +1948,7 @@ export function evaluatePullRequestReview(input) {
|
|
|
1136
1948
|
const standard = input.standard ?? "basic";
|
|
1137
1949
|
const suppliedSecretScannerEvidence = input.secretScannerEvidence ??
|
|
1138
1950
|
unverifiedSecretScannerEvidence("The security-focused review did not receive CI evidence from a mature secret scanner.");
|
|
1139
|
-
const
|
|
1140
|
-
(file.previousFilename !== undefined &&
|
|
1141
|
-
isSecretScannerPolicyPath(file.previousFilename)));
|
|
1142
|
-
const effectiveSecretScannerEvidence = suppliedSecretScannerEvidence.status === "passing" && scannerPolicyChanged
|
|
1143
|
-
? {
|
|
1144
|
-
...unverifiedSecretScannerEvidence("The PR changes secret-scanner workflow or configuration policy, so its supplied passing evidence is not trusted."),
|
|
1145
|
-
providers: suppliedSecretScannerEvidence.providers,
|
|
1146
|
-
signals: suppliedSecretScannerEvidence.signals,
|
|
1147
|
-
}
|
|
1148
|
-
: suppliedSecretScannerEvidence;
|
|
1951
|
+
const effectiveSecretScannerEvidence = applySecretScannerPolicyChanges(classified.allFiles, suppliedSecretScannerEvidence, input.secretScannerPolicyContext);
|
|
1149
1952
|
const totalChangedLines = classified.allFiles.reduce((total, file) => total + (file.changes ?? (file.additions ?? 0) + (file.deletions ?? 0)), 0);
|
|
1150
1953
|
if (input.pr.draft) {
|
|
1151
1954
|
findings.push(finding("info", "Status", "scope", "PR is still marked as a draft.", [], "Draft status indicates that the author has not yet declared the change ready for final review.", "Mark the PR as ready for review when the implementation and evidence are complete."));
|
|
@@ -1162,7 +1965,7 @@ export function evaluatePullRequestReview(input) {
|
|
|
1162
1965
|
findings.push(...scanPatchForSecrets(file.filename, file.patch));
|
|
1163
1966
|
}
|
|
1164
1967
|
if (standard === "strict" || standard === "security-focused") {
|
|
1165
|
-
addStrictFindings(classified, totalChangedLines, findings);
|
|
1968
|
+
addStrictFindings(classified, totalChangedLines, body, findings);
|
|
1166
1969
|
}
|
|
1167
1970
|
if (standard === "security-focused") {
|
|
1168
1971
|
addSecretScannerEvidenceFinding(effectiveSecretScannerEvidence, findings);
|