@akasecurity/ai-tc-copilot 0.9.22 → 0.9.23
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/package.json +4 -4
- package/plugin.json +1 -1
- package/scripts/content-retention.js +37 -0
- package/scripts/history-sync.js +100 -15
- package/scripts/post-tool-use.js +103 -16
- package/scripts/pre-tool-use.js +103 -16
- package/scripts/scan-worker.js +42 -8
- package/scripts/session-start.js +146 -48
- package/scripts/sync.js +148 -49
- package/scripts/user-prompt-submit.js +103 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akasecurity/ai-tc-copilot",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"description": "AI Traffic Control — inspect and govern AI prompts in GitHub Copilot",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"typescript": "^5.8.0",
|
|
29
29
|
"vitest": "^4.1.12",
|
|
30
30
|
"@akasecurity/eslint-config": "0.8.0",
|
|
31
|
-
"@akasecurity/plugin-runtime": "0.8.0",
|
|
32
31
|
"@akasecurity/persistence": "0.8.0",
|
|
33
|
-
"@akasecurity/plugin-
|
|
32
|
+
"@akasecurity/plugin-runtime": "0.8.0",
|
|
34
33
|
"@akasecurity/scanner": "0.8.0",
|
|
35
34
|
"@akasecurity/schema": "0.8.0",
|
|
36
|
-
"@akasecurity/setup-wizard": "0.8.0"
|
|
35
|
+
"@akasecurity/setup-wizard": "0.8.0",
|
|
36
|
+
"@akasecurity/plugin-sdk": "0.8.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|
package/plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aka-copilot",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"description": "AI Traffic Control — inspect and govern AI prompts in GitHub Copilot. Detection runs locally; events are recorded to a local SQLite store on your machine.",
|
|
5
5
|
"hooks": "./hooks.json",
|
|
6
6
|
"skills": "./skills",
|
|
@@ -22379,6 +22379,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
22379
22379
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
22380
22380
|
);
|
|
22381
22381
|
}
|
|
22382
|
+
/**
|
|
22383
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
22384
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
22385
|
+
* every row.
|
|
22386
|
+
*
|
|
22387
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
22388
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
22389
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
22390
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
22391
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
22392
|
+
*
|
|
22393
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
22394
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
22395
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
22396
|
+
*
|
|
22397
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
22398
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
22399
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
22400
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
22401
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
22402
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
22403
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
22404
|
+
*/
|
|
22405
|
+
countFingerprintEpochs(currentVersion) {
|
|
22406
|
+
const row = getRow(
|
|
22407
|
+
this.db.prepare(
|
|
22408
|
+
`SELECT COUNT(*) AS total,
|
|
22409
|
+
COALESCE(
|
|
22410
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
22411
|
+
0
|
|
22412
|
+
) AS stale
|
|
22413
|
+
FROM secret_vault`
|
|
22414
|
+
),
|
|
22415
|
+
{ currentVersion }
|
|
22416
|
+
) ?? { stale: 0, total: 0 };
|
|
22417
|
+
return { stale: row.stale, total: row.total };
|
|
22418
|
+
}
|
|
22382
22419
|
};
|
|
22383
22420
|
|
|
22384
22421
|
// ../../packages/persistence/src/repositories/security.ts
|
package/scripts/history-sync.js
CHANGED
|
@@ -23167,6 +23167,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
23167
23167
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
23168
23168
|
);
|
|
23169
23169
|
}
|
|
23170
|
+
/**
|
|
23171
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
23172
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
23173
|
+
* every row.
|
|
23174
|
+
*
|
|
23175
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
23176
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
23177
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
23178
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
23179
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
23180
|
+
*
|
|
23181
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
23182
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
23183
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
23184
|
+
*
|
|
23185
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
23186
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
23187
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
23188
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
23189
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
23190
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
23191
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
23192
|
+
*/
|
|
23193
|
+
countFingerprintEpochs(currentVersion) {
|
|
23194
|
+
const row = getRow(
|
|
23195
|
+
this.db.prepare(
|
|
23196
|
+
`SELECT COUNT(*) AS total,
|
|
23197
|
+
COALESCE(
|
|
23198
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
23199
|
+
0
|
|
23200
|
+
) AS stale
|
|
23201
|
+
FROM secret_vault`
|
|
23202
|
+
),
|
|
23203
|
+
{ currentVersion }
|
|
23204
|
+
) ?? { stale: 0, total: 0 };
|
|
23205
|
+
return { stale: row.stale, total: row.total };
|
|
23206
|
+
}
|
|
23170
23207
|
};
|
|
23171
23208
|
|
|
23172
23209
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -24956,13 +24993,22 @@ var SecretVault = class {
|
|
|
24956
24993
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
24957
24994
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
24958
24995
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
24996
|
+
*
|
|
24997
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
24998
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
24999
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
25000
|
+
* than a bare success count.
|
|
24959
25001
|
*/
|
|
24960
25002
|
async refreshFingerprints(next) {
|
|
24961
25003
|
let refreshed = 0;
|
|
25004
|
+
let skipped = 0;
|
|
24962
25005
|
for (const row of this.#repo.listAll()) {
|
|
24963
25006
|
try {
|
|
24964
25007
|
const raw = await this.#openRow(row);
|
|
24965
|
-
if (raw === null)
|
|
25008
|
+
if (raw === null) {
|
|
25009
|
+
skipped += 1;
|
|
25010
|
+
continue;
|
|
25011
|
+
}
|
|
24966
25012
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
24967
25013
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
24968
25014
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -24970,10 +25016,10 @@ var SecretVault = class {
|
|
|
24970
25016
|
});
|
|
24971
25017
|
refreshed += 1;
|
|
24972
25018
|
} catch {
|
|
24973
|
-
|
|
25019
|
+
skipped += 1;
|
|
24974
25020
|
}
|
|
24975
25021
|
}
|
|
24976
|
-
return refreshed;
|
|
25022
|
+
return { refreshed, skipped };
|
|
24977
25023
|
}
|
|
24978
25024
|
/**
|
|
24979
25025
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -26292,6 +26338,21 @@ function passesPostValidators(rule, value) {
|
|
|
26292
26338
|
function getLoadedRules() {
|
|
26293
26339
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
26294
26340
|
}
|
|
26341
|
+
function outsideWrittenRegions(candidates, context) {
|
|
26342
|
+
const regions = context?.writtenRegions;
|
|
26343
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
26344
|
+
return candidates.filter((c) => {
|
|
26345
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
26346
|
+
const { start, end } = c.match.span;
|
|
26347
|
+
return !regions.some(
|
|
26348
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
26349
|
+
c.rule,
|
|
26350
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
26351
|
+
"code_change"
|
|
26352
|
+
)
|
|
26353
|
+
);
|
|
26354
|
+
});
|
|
26355
|
+
}
|
|
26295
26356
|
function spansOverlap(a, b) {
|
|
26296
26357
|
return a.start < b.end && a.end > b.start;
|
|
26297
26358
|
}
|
|
@@ -26479,17 +26540,20 @@ function scanEncoded(text, ruleset, context) {
|
|
|
26479
26540
|
function scanText(text, ruleset, context) {
|
|
26480
26541
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
26481
26542
|
const normalization = normalizeFormatChars(text);
|
|
26482
|
-
const originalCandidates =
|
|
26543
|
+
const originalCandidates = outsideWrittenRegions(
|
|
26544
|
+
buildCandidates(text, ruleset, extension, context?.eventKind),
|
|
26545
|
+
context
|
|
26546
|
+
);
|
|
26483
26547
|
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
26484
26548
|
const pooledOriginal = originalCandidates.map(
|
|
26485
26549
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
26486
26550
|
);
|
|
26487
|
-
const normalizedCandidates =
|
|
26488
|
-
normalization.normalized,
|
|
26489
|
-
|
|
26490
|
-
|
|
26491
|
-
context
|
|
26492
|
-
)
|
|
26551
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
26552
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
26553
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
26554
|
+
),
|
|
26555
|
+
context
|
|
26556
|
+
);
|
|
26493
26557
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
26494
26558
|
return mergeOverlappingSameRule(findings, text);
|
|
26495
26559
|
}
|
|
@@ -27380,7 +27444,7 @@ var sql_inject_concat_dot_default = {
|
|
|
27380
27444
|
severity: "high",
|
|
27381
27445
|
matcher: {
|
|
27382
27446
|
type: "regex",
|
|
27383
|
-
pattern:
|
|
27447
|
+
pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
|
|
27384
27448
|
flags: "gi"
|
|
27385
27449
|
},
|
|
27386
27450
|
appliesTo: {
|
|
@@ -27398,7 +27462,7 @@ var sql_inject_concat_default = {
|
|
|
27398
27462
|
severity: "high",
|
|
27399
27463
|
matcher: {
|
|
27400
27464
|
type: "regex",
|
|
27401
|
-
pattern:
|
|
27465
|
+
pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
|
|
27402
27466
|
flags: "gi"
|
|
27403
27467
|
},
|
|
27404
27468
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -27413,7 +27477,7 @@ var sql_inject_format_default = {
|
|
|
27413
27477
|
severity: "high",
|
|
27414
27478
|
matcher: {
|
|
27415
27479
|
type: "regex",
|
|
27416
|
-
pattern:
|
|
27480
|
+
pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
|
|
27417
27481
|
flags: "gi"
|
|
27418
27482
|
},
|
|
27419
27483
|
examples: [
|
|
@@ -27422,6 +27486,24 @@ var sql_inject_format_default = {
|
|
|
27422
27486
|
]
|
|
27423
27487
|
};
|
|
27424
27488
|
|
|
27489
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
27490
|
+
var sql_inject_interp_multiline_default = {
|
|
27491
|
+
specVersion: 1,
|
|
27492
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
27493
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
27494
|
+
category: "code_flaw",
|
|
27495
|
+
severity: "high",
|
|
27496
|
+
matcher: {
|
|
27497
|
+
type: "regex",
|
|
27498
|
+
pattern: '(?<=^|\\n)[ \\t]*(?=(?:select\\b(?:[^\\n]*\\n){0,3}?[^\\n]*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}into\\b|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])',
|
|
27499
|
+
flags: "gi"
|
|
27500
|
+
},
|
|
27501
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
27502
|
+
appliesTo: {
|
|
27503
|
+
extensions: [".rb", ".php"]
|
|
27504
|
+
}
|
|
27505
|
+
};
|
|
27506
|
+
|
|
27425
27507
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
27426
27508
|
var sql_inject_interp_default = {
|
|
27427
27509
|
specVersion: 1,
|
|
@@ -27431,7 +27513,7 @@ var sql_inject_interp_default = {
|
|
|
27431
27513
|
severity: "high",
|
|
27432
27514
|
matcher: {
|
|
27433
27515
|
type: "regex",
|
|
27434
|
-
pattern: "([\
|
|
27516
|
+
pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
|
|
27435
27517
|
flags: "gi"
|
|
27436
27518
|
},
|
|
27437
27519
|
examples: [
|
|
@@ -29159,12 +29241,13 @@ var BUNDLED_PACKS = [
|
|
|
29159
29241
|
{
|
|
29160
29242
|
packId: "code-flaws",
|
|
29161
29243
|
name: "Code Security Flaws",
|
|
29162
|
-
version: "0.1.
|
|
29244
|
+
version: "0.1.6",
|
|
29163
29245
|
rawRules: [
|
|
29164
29246
|
sql_inject_concat_default,
|
|
29165
29247
|
sql_inject_concat_dot_default,
|
|
29166
29248
|
sql_inject_format_default,
|
|
29167
29249
|
sql_inject_interp_default,
|
|
29250
|
+
sql_inject_interp_multiline_default,
|
|
29168
29251
|
cmd_inject_shell_default,
|
|
29169
29252
|
cmd_inject_exec_default,
|
|
29170
29253
|
cmd_inject_node_exec_default,
|
|
@@ -29196,6 +29279,7 @@ var BUNDLED_PACKS = [
|
|
|
29196
29279
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
29197
29280
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
29198
29281
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
29282
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
29199
29283
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
29200
29284
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
29201
29285
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -29737,6 +29821,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
29737
29821
|
text,
|
|
29738
29822
|
filePath: context?.filePath,
|
|
29739
29823
|
eventKind: context?.eventKind,
|
|
29824
|
+
writtenRegions: context?.writtenRegions,
|
|
29740
29825
|
attribute: scanOpts?.attribute === true
|
|
29741
29826
|
}),
|
|
29742
29827
|
reply: (message) => {
|
package/scripts/post-tool-use.js
CHANGED
|
@@ -15114,6 +15114,21 @@ function registerPack(pack) {
|
|
|
15114
15114
|
function getLoadedRules() {
|
|
15115
15115
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
15116
15116
|
}
|
|
15117
|
+
function outsideWrittenRegions(candidates, context) {
|
|
15118
|
+
const regions = context?.writtenRegions;
|
|
15119
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
15120
|
+
return candidates.filter((c) => {
|
|
15121
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
15122
|
+
const { start, end } = c.match.span;
|
|
15123
|
+
return !regions.some(
|
|
15124
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
15125
|
+
c.rule,
|
|
15126
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
15127
|
+
"code_change"
|
|
15128
|
+
)
|
|
15129
|
+
);
|
|
15130
|
+
});
|
|
15131
|
+
}
|
|
15117
15132
|
function spansOverlap(a, b) {
|
|
15118
15133
|
return a.start < b.end && a.end > b.start;
|
|
15119
15134
|
}
|
|
@@ -15301,17 +15316,20 @@ function scanEncoded(text, ruleset, context) {
|
|
|
15301
15316
|
function scanText(text, ruleset, context) {
|
|
15302
15317
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
15303
15318
|
const normalization = normalizeFormatChars(text);
|
|
15304
|
-
const originalCandidates =
|
|
15319
|
+
const originalCandidates = outsideWrittenRegions(
|
|
15320
|
+
buildCandidates(text, ruleset, extension, context?.eventKind),
|
|
15321
|
+
context
|
|
15322
|
+
);
|
|
15305
15323
|
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
15306
15324
|
const pooledOriginal = originalCandidates.map(
|
|
15307
15325
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
15308
15326
|
);
|
|
15309
|
-
const normalizedCandidates =
|
|
15310
|
-
normalization.normalized,
|
|
15311
|
-
|
|
15312
|
-
|
|
15313
|
-
context
|
|
15314
|
-
)
|
|
15327
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
15328
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
15329
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
15330
|
+
),
|
|
15331
|
+
context
|
|
15332
|
+
);
|
|
15315
15333
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
15316
15334
|
return mergeOverlappingSameRule(findings, text);
|
|
15317
15335
|
}
|
|
@@ -15372,6 +15390,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
|
|
|
15372
15390
|
"code-flaws/sql-inject-concat-dot",
|
|
15373
15391
|
"code-flaws/sql-inject-format",
|
|
15374
15392
|
"code-flaws/sql-inject-interp",
|
|
15393
|
+
"code-flaws/sql-inject-interp-multiline",
|
|
15375
15394
|
"code-flaws/ssrf-user-url",
|
|
15376
15395
|
"code-flaws/xss-dangerously-set",
|
|
15377
15396
|
"code-flaws/xss-inner-html",
|
|
@@ -16510,7 +16529,7 @@ var sql_inject_concat_dot_default = {
|
|
|
16510
16529
|
severity: "high",
|
|
16511
16530
|
matcher: {
|
|
16512
16531
|
type: "regex",
|
|
16513
|
-
pattern:
|
|
16532
|
+
pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
|
|
16514
16533
|
flags: "gi"
|
|
16515
16534
|
},
|
|
16516
16535
|
appliesTo: {
|
|
@@ -16528,7 +16547,7 @@ var sql_inject_concat_default = {
|
|
|
16528
16547
|
severity: "high",
|
|
16529
16548
|
matcher: {
|
|
16530
16549
|
type: "regex",
|
|
16531
|
-
pattern:
|
|
16550
|
+
pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
|
|
16532
16551
|
flags: "gi"
|
|
16533
16552
|
},
|
|
16534
16553
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -16543,7 +16562,7 @@ var sql_inject_format_default = {
|
|
|
16543
16562
|
severity: "high",
|
|
16544
16563
|
matcher: {
|
|
16545
16564
|
type: "regex",
|
|
16546
|
-
pattern:
|
|
16565
|
+
pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
|
|
16547
16566
|
flags: "gi"
|
|
16548
16567
|
},
|
|
16549
16568
|
examples: [
|
|
@@ -16552,6 +16571,24 @@ var sql_inject_format_default = {
|
|
|
16552
16571
|
]
|
|
16553
16572
|
};
|
|
16554
16573
|
|
|
16574
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
16575
|
+
var sql_inject_interp_multiline_default = {
|
|
16576
|
+
specVersion: 1,
|
|
16577
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
16578
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
16579
|
+
category: "code_flaw",
|
|
16580
|
+
severity: "high",
|
|
16581
|
+
matcher: {
|
|
16582
|
+
type: "regex",
|
|
16583
|
+
pattern: '(?<=^|\\n)[ \\t]*(?=(?:select\\b(?:[^\\n]*\\n){0,3}?[^\\n]*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}into\\b|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])',
|
|
16584
|
+
flags: "gi"
|
|
16585
|
+
},
|
|
16586
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
16587
|
+
appliesTo: {
|
|
16588
|
+
extensions: [".rb", ".php"]
|
|
16589
|
+
}
|
|
16590
|
+
};
|
|
16591
|
+
|
|
16555
16592
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
16556
16593
|
var sql_inject_interp_default = {
|
|
16557
16594
|
specVersion: 1,
|
|
@@ -16561,7 +16598,7 @@ var sql_inject_interp_default = {
|
|
|
16561
16598
|
severity: "high",
|
|
16562
16599
|
matcher: {
|
|
16563
16600
|
type: "regex",
|
|
16564
|
-
pattern: "([\
|
|
16601
|
+
pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
|
|
16565
16602
|
flags: "gi"
|
|
16566
16603
|
},
|
|
16567
16604
|
examples: [
|
|
@@ -18289,12 +18326,13 @@ var BUNDLED_PACKS = [
|
|
|
18289
18326
|
{
|
|
18290
18327
|
packId: "code-flaws",
|
|
18291
18328
|
name: "Code Security Flaws",
|
|
18292
|
-
version: "0.1.
|
|
18329
|
+
version: "0.1.6",
|
|
18293
18330
|
rawRules: [
|
|
18294
18331
|
sql_inject_concat_default,
|
|
18295
18332
|
sql_inject_concat_dot_default,
|
|
18296
18333
|
sql_inject_format_default,
|
|
18297
18334
|
sql_inject_interp_default,
|
|
18335
|
+
sql_inject_interp_multiline_default,
|
|
18298
18336
|
cmd_inject_shell_default,
|
|
18299
18337
|
cmd_inject_exec_default,
|
|
18300
18338
|
cmd_inject_node_exec_default,
|
|
@@ -18326,6 +18364,7 @@ var BUNDLED_PACKS = [
|
|
|
18326
18364
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
18327
18365
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
18328
18366
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
18367
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
18329
18368
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
18330
18369
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
18331
18370
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -28418,6 +28457,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
28418
28457
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
28419
28458
|
);
|
|
28420
28459
|
}
|
|
28460
|
+
/**
|
|
28461
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
28462
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
28463
|
+
* every row.
|
|
28464
|
+
*
|
|
28465
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
28466
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
28467
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
28468
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
28469
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
28470
|
+
*
|
|
28471
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
28472
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
28473
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
28474
|
+
*
|
|
28475
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
28476
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
28477
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
28478
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
28479
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
28480
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
28481
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
28482
|
+
*/
|
|
28483
|
+
countFingerprintEpochs(currentVersion) {
|
|
28484
|
+
const row = getRow(
|
|
28485
|
+
this.db.prepare(
|
|
28486
|
+
`SELECT COUNT(*) AS total,
|
|
28487
|
+
COALESCE(
|
|
28488
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
28489
|
+
0
|
|
28490
|
+
) AS stale
|
|
28491
|
+
FROM secret_vault`
|
|
28492
|
+
),
|
|
28493
|
+
{ currentVersion }
|
|
28494
|
+
) ?? { stale: 0, total: 0 };
|
|
28495
|
+
return { stale: row.stale, total: row.total };
|
|
28496
|
+
}
|
|
28421
28497
|
};
|
|
28422
28498
|
|
|
28423
28499
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -30274,13 +30350,22 @@ var SecretVault = class {
|
|
|
30274
30350
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
30275
30351
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
30276
30352
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
30353
|
+
*
|
|
30354
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
30355
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
30356
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
30357
|
+
* than a bare success count.
|
|
30277
30358
|
*/
|
|
30278
30359
|
async refreshFingerprints(next) {
|
|
30279
30360
|
let refreshed = 0;
|
|
30361
|
+
let skipped = 0;
|
|
30280
30362
|
for (const row of this.#repo.listAll()) {
|
|
30281
30363
|
try {
|
|
30282
30364
|
const raw = await this.#openRow(row);
|
|
30283
|
-
if (raw === null)
|
|
30365
|
+
if (raw === null) {
|
|
30366
|
+
skipped += 1;
|
|
30367
|
+
continue;
|
|
30368
|
+
}
|
|
30284
30369
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
30285
30370
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
30286
30371
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -30288,10 +30373,10 @@ var SecretVault = class {
|
|
|
30288
30373
|
});
|
|
30289
30374
|
refreshed += 1;
|
|
30290
30375
|
} catch {
|
|
30291
|
-
|
|
30376
|
+
skipped += 1;
|
|
30292
30377
|
}
|
|
30293
30378
|
}
|
|
30294
|
-
return refreshed;
|
|
30379
|
+
return { refreshed, skipped };
|
|
30295
30380
|
}
|
|
30296
30381
|
/**
|
|
30297
30382
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -31221,6 +31306,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
31221
31306
|
text,
|
|
31222
31307
|
filePath: context?.filePath,
|
|
31223
31308
|
eventKind: context?.eventKind,
|
|
31309
|
+
writtenRegions: context?.writtenRegions,
|
|
31224
31310
|
attribute: scanOpts?.attribute === true
|
|
31225
31311
|
}),
|
|
31226
31312
|
reply: (message) => {
|
|
@@ -31958,7 +32044,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
31958
32044
|
input.text,
|
|
31959
32045
|
{
|
|
31960
32046
|
filePath: input.metadata?.filePath,
|
|
31961
|
-
eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
|
|
32047
|
+
eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
|
|
32048
|
+
writtenRegions: opts2.writtenRegions
|
|
31962
32049
|
},
|
|
31963
32050
|
{
|
|
31964
32051
|
sourceTool: input.sourceTool,
|