@akasecurity/ai-tc-codex 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/.codex-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/scripts/apply-suppressions.js +88 -12
- package/scripts/backfill.js +103 -16
- package/scripts/content-retention.js +37 -0
- package/scripts/filescan.js +148 -49
- package/scripts/firstrun.js +100 -15
- package/scripts/history-sync.js +100 -15
- package/scripts/onboard.js +62 -5
- package/scripts/post-tool-use.js +103 -16
- package/scripts/pre-tool-use.js +103 -16
- package/scripts/query.js +100 -15
- package/scripts/reconcile.js +101 -15
- package/scripts/remediate.js +110 -19
- package/scripts/scan-worker.js +42 -8
- package/scripts/session-start.js +146 -48
- package/scripts/stop.js +100 -15
- package/scripts/sync.js +148 -49
- package/scripts/user-prompt-submit.js +103 -16
package/scripts/session-start.js
CHANGED
|
@@ -32,9 +32,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
mod
|
|
33
33
|
));
|
|
34
34
|
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.
|
|
35
|
+
// ../../node_modules/.pnpm/ignore@7.0.14/node_modules/ignore/index.js
|
|
36
36
|
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.
|
|
37
|
+
"../../node_modules/.pnpm/ignore@7.0.14/node_modules/ignore/index.js"(exports, module) {
|
|
38
38
|
"use strict";
|
|
39
39
|
function makeArray(subject) {
|
|
40
40
|
return Array.isArray(subject) ? subject : [subject];
|
|
@@ -46,6 +46,7 @@ var require_ignore = __commonJS({
|
|
|
46
46
|
var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
47
47
|
var BOM = "\uFEFF";
|
|
48
48
|
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
49
|
+
var REGEX_ANCHORED_GLOBSTAR = /^\/\*{2,}$/;
|
|
49
50
|
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
50
51
|
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
51
52
|
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
@@ -227,6 +228,20 @@ var require_ignore = __commonJS({
|
|
|
227
228
|
(_, run, space) => space ? run.slice(0, run.length - run.length % 2) + SPACE : run,
|
|
228
229
|
ESCAPE + SPACE
|
|
229
230
|
],
|
|
231
|
+
// git's wildmatch() reads a run of two or more asterisks as one globstar
|
|
232
|
+
// whenever the run fills a path segment: it starts the pattern or follows
|
|
233
|
+
// a `/`, and it ends the pattern or comes before a `/`. A run of two is
|
|
234
|
+
// already `**`; a longer one is folded into `**` here, so the steps
|
|
235
|
+
// below only ever have to know `**`.
|
|
236
|
+
// `***/foo` -> `**/foo`, `a/***/b` -> `a/**/b`, `a/***` -> `a/**`
|
|
237
|
+
// git also takes a run beside a literal prefix (`a***/b`) or beside an
|
|
238
|
+
// escaped slash (`***\/b`) as a globstar, and this does not; the README
|
|
239
|
+
// lists both, under "A run of asterisks".
|
|
240
|
+
[
|
|
241
|
+
/(^|\/)\*{3,}(?=\/|$)/g,
|
|
242
|
+
(_, start) => `${start}**`,
|
|
243
|
+
"*"
|
|
244
|
+
],
|
|
230
245
|
// Escape metacharacters
|
|
231
246
|
// which is written down by users but means special for regular expressions.
|
|
232
247
|
// > There are 12 characters with special meanings:
|
|
@@ -488,6 +503,9 @@ var require_ignore = __commonJS({
|
|
|
488
503
|
return out;
|
|
489
504
|
};
|
|
490
505
|
var makeRegexPrefix = (pattern) => {
|
|
506
|
+
if (REGEX_ANCHORED_GLOBSTAR.test(pattern)) {
|
|
507
|
+
pattern = "**";
|
|
508
|
+
}
|
|
491
509
|
const { source, sources } = extractBrackets(pattern);
|
|
492
510
|
const replaced = REPLACERS.reduce(
|
|
493
511
|
// A pass whose matcher finds nothing hands back the very string it was
|
|
@@ -703,39 +721,33 @@ var require_ignore = __commonJS({
|
|
|
703
721
|
}
|
|
704
722
|
// Test one single path without recursively checking parent directories
|
|
705
723
|
//
|
|
706
|
-
// -
|
|
707
|
-
//
|
|
708
|
-
|
|
709
|
-
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
710
|
-
// @returns {TestResult} true if a file is ignored
|
|
711
|
-
test(path, checkUnignored, mode) {
|
|
712
|
-
let ignored = false;
|
|
713
|
-
let unignored = false;
|
|
714
|
-
let matchedRule;
|
|
724
|
+
// - mode `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
725
|
+
// @returns {TestResult}
|
|
726
|
+
test(path, mode) {
|
|
715
727
|
const rules = this._rules;
|
|
716
728
|
const { length } = rules;
|
|
717
729
|
const shortcut = this._basenameCount * 2 >= length;
|
|
718
730
|
const basename8 = shortcut ? basenameOf(path) : path;
|
|
719
|
-
for (let index =
|
|
731
|
+
for (let index = length - 1; index >= 0; index--) {
|
|
720
732
|
const rule = rules[index];
|
|
721
|
-
|
|
722
|
-
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
723
|
-
if (!skip && rule[mode].test(
|
|
733
|
+
if (rule[mode].test(
|
|
724
734
|
shortcut && rule._basenameOnly ? basename8 : path
|
|
725
735
|
)) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
736
|
+
const { negative } = rule;
|
|
737
|
+
const ret = {
|
|
738
|
+
ignored: !negative,
|
|
739
|
+
unignored: negative
|
|
740
|
+
};
|
|
741
|
+
if (!negative) {
|
|
742
|
+
ret.rule = rule;
|
|
743
|
+
}
|
|
744
|
+
return ret;
|
|
729
745
|
}
|
|
730
746
|
}
|
|
731
|
-
|
|
732
|
-
ignored,
|
|
733
|
-
unignored
|
|
747
|
+
return {
|
|
748
|
+
ignored: false,
|
|
749
|
+
unignored: false
|
|
734
750
|
};
|
|
735
|
-
if (matchedRule) {
|
|
736
|
-
ret.rule = matchedRule;
|
|
737
|
-
}
|
|
738
|
-
return ret;
|
|
739
751
|
}
|
|
740
752
|
};
|
|
741
753
|
var throwError = (message2, Ctor) => {
|
|
@@ -808,36 +820,36 @@ var require_ignore = __commonJS({
|
|
|
808
820
|
return this.add(pattern);
|
|
809
821
|
}
|
|
810
822
|
// @returns {TestResult}
|
|
811
|
-
_test(originalPath, cache
|
|
823
|
+
_test(originalPath, cache) {
|
|
812
824
|
const path = originalPath && checkPath.convert(originalPath);
|
|
813
825
|
checkPath(
|
|
814
826
|
path,
|
|
815
827
|
originalPath,
|
|
816
828
|
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
817
829
|
);
|
|
818
|
-
return this._t(path, cache
|
|
830
|
+
return this._t(path, cache);
|
|
819
831
|
}
|
|
820
832
|
checkIgnore(path) {
|
|
821
833
|
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) {
|
|
822
834
|
return this.test(path);
|
|
823
835
|
}
|
|
824
|
-
const dir = this._t(path, this._testCache
|
|
836
|
+
const dir = this._t(path, this._testCache);
|
|
825
837
|
if (dir.ignored) {
|
|
826
838
|
return dir;
|
|
827
839
|
}
|
|
828
840
|
const literal2 = this._rules.testLiteral(path);
|
|
829
841
|
return literal2.ignored || literal2.unignored ? literal2 : dir;
|
|
830
842
|
}
|
|
831
|
-
_t(path, cache
|
|
843
|
+
_t(path, cache) {
|
|
832
844
|
if (path in cache) {
|
|
833
845
|
return cache[path];
|
|
834
846
|
}
|
|
835
847
|
const parentPath = parentOf(path);
|
|
836
|
-
const parent = parentPath ? this._t(parentPath, cache
|
|
837
|
-
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path,
|
|
848
|
+
const parent = parentPath ? this._t(parentPath, cache) : UNDEFINED;
|
|
849
|
+
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, MODE_IGNORE);
|
|
838
850
|
}
|
|
839
851
|
ignores(path) {
|
|
840
|
-
return this._test(path, this._ignoreCache
|
|
852
|
+
return this._test(path, this._ignoreCache).ignored;
|
|
841
853
|
}
|
|
842
854
|
createFilter() {
|
|
843
855
|
return (path) => !this.ignores(path);
|
|
@@ -847,7 +859,7 @@ var require_ignore = __commonJS({
|
|
|
847
859
|
}
|
|
848
860
|
// @returns {TestResult}
|
|
849
861
|
test(path) {
|
|
850
|
-
return this._test(path, this._testCache
|
|
862
|
+
return this._test(path, this._testCache);
|
|
851
863
|
}
|
|
852
864
|
};
|
|
853
865
|
var factory = (options) => new Ignore(options);
|
|
@@ -24827,6 +24839,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
24827
24839
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
24828
24840
|
);
|
|
24829
24841
|
}
|
|
24842
|
+
/**
|
|
24843
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
24844
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
24845
|
+
* every row.
|
|
24846
|
+
*
|
|
24847
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
24848
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
24849
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
24850
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
24851
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
24852
|
+
*
|
|
24853
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
24854
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
24855
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
24856
|
+
*
|
|
24857
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
24858
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
24859
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
24860
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
24861
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
24862
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
24863
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
24864
|
+
*/
|
|
24865
|
+
countFingerprintEpochs(currentVersion) {
|
|
24866
|
+
const row = getRow(
|
|
24867
|
+
this.db.prepare(
|
|
24868
|
+
`SELECT COUNT(*) AS total,
|
|
24869
|
+
COALESCE(
|
|
24870
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
24871
|
+
0
|
|
24872
|
+
) AS stale
|
|
24873
|
+
FROM secret_vault`
|
|
24874
|
+
),
|
|
24875
|
+
{ currentVersion }
|
|
24876
|
+
) ?? { stale: 0, total: 0 };
|
|
24877
|
+
return { stale: row.stale, total: row.total };
|
|
24878
|
+
}
|
|
24830
24879
|
};
|
|
24831
24880
|
|
|
24832
24881
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -26625,13 +26674,22 @@ var SecretVault = class {
|
|
|
26625
26674
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
26626
26675
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
26627
26676
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
26677
|
+
*
|
|
26678
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
26679
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
26680
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
26681
|
+
* than a bare success count.
|
|
26628
26682
|
*/
|
|
26629
26683
|
async refreshFingerprints(next) {
|
|
26630
26684
|
let refreshed = 0;
|
|
26685
|
+
let skipped = 0;
|
|
26631
26686
|
for (const row of this.#repo.listAll()) {
|
|
26632
26687
|
try {
|
|
26633
26688
|
const raw = await this.#openRow(row);
|
|
26634
|
-
if (raw === null)
|
|
26689
|
+
if (raw === null) {
|
|
26690
|
+
skipped += 1;
|
|
26691
|
+
continue;
|
|
26692
|
+
}
|
|
26635
26693
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
26636
26694
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
26637
26695
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -26639,10 +26697,10 @@ var SecretVault = class {
|
|
|
26639
26697
|
});
|
|
26640
26698
|
refreshed += 1;
|
|
26641
26699
|
} catch {
|
|
26642
|
-
|
|
26700
|
+
skipped += 1;
|
|
26643
26701
|
}
|
|
26644
26702
|
}
|
|
26645
|
-
return refreshed;
|
|
26703
|
+
return { refreshed, skipped };
|
|
26646
26704
|
}
|
|
26647
26705
|
/**
|
|
26648
26706
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -27981,6 +28039,21 @@ function registerPack(pack) {
|
|
|
27981
28039
|
function getLoadedRules() {
|
|
27982
28040
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
27983
28041
|
}
|
|
28042
|
+
function outsideWrittenRegions(candidates, context) {
|
|
28043
|
+
const regions = context?.writtenRegions;
|
|
28044
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
28045
|
+
return candidates.filter((c) => {
|
|
28046
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
28047
|
+
const { start, end } = c.match.span;
|
|
28048
|
+
return !regions.some(
|
|
28049
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
28050
|
+
c.rule,
|
|
28051
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
28052
|
+
"code_change"
|
|
28053
|
+
)
|
|
28054
|
+
);
|
|
28055
|
+
});
|
|
28056
|
+
}
|
|
27984
28057
|
function spansOverlap(a, b) {
|
|
27985
28058
|
return a.start < b.end && a.end > b.start;
|
|
27986
28059
|
}
|
|
@@ -28168,17 +28241,20 @@ function scanEncoded(text2, ruleset, context) {
|
|
|
28168
28241
|
function scanText(text2, ruleset, context) {
|
|
28169
28242
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
28170
28243
|
const normalization = normalizeFormatChars(text2);
|
|
28171
|
-
const originalCandidates =
|
|
28244
|
+
const originalCandidates = outsideWrittenRegions(
|
|
28245
|
+
buildCandidates(text2, ruleset, extension, context?.eventKind),
|
|
28246
|
+
context
|
|
28247
|
+
);
|
|
28172
28248
|
if (!normalization) return gate(originalCandidates, text2, void 0);
|
|
28173
28249
|
const pooledOriginal = originalCandidates.map(
|
|
28174
28250
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
28175
28251
|
);
|
|
28176
|
-
const normalizedCandidates =
|
|
28177
|
-
normalization.normalized,
|
|
28178
|
-
|
|
28179
|
-
|
|
28180
|
-
context
|
|
28181
|
-
)
|
|
28252
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
28253
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
28254
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text2)
|
|
28255
|
+
),
|
|
28256
|
+
context
|
|
28257
|
+
);
|
|
28182
28258
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text2, normalization);
|
|
28183
28259
|
return mergeOverlappingSameRule(findings, text2);
|
|
28184
28260
|
}
|
|
@@ -28239,6 +28315,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
|
|
|
28239
28315
|
"code-flaws/sql-inject-concat-dot",
|
|
28240
28316
|
"code-flaws/sql-inject-format",
|
|
28241
28317
|
"code-flaws/sql-inject-interp",
|
|
28318
|
+
"code-flaws/sql-inject-interp-multiline",
|
|
28242
28319
|
"code-flaws/ssrf-user-url",
|
|
28243
28320
|
"code-flaws/xss-dangerously-set",
|
|
28244
28321
|
"code-flaws/xss-inner-html",
|
|
@@ -29531,7 +29608,7 @@ var sql_inject_concat_dot_default = {
|
|
|
29531
29608
|
severity: "high",
|
|
29532
29609
|
matcher: {
|
|
29533
29610
|
type: "regex",
|
|
29534
|
-
pattern:
|
|
29611
|
+
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*\\.",
|
|
29535
29612
|
flags: "gi"
|
|
29536
29613
|
},
|
|
29537
29614
|
appliesTo: {
|
|
@@ -29549,7 +29626,7 @@ var sql_inject_concat_default = {
|
|
|
29549
29626
|
severity: "high",
|
|
29550
29627
|
matcher: {
|
|
29551
29628
|
type: "regex",
|
|
29552
|
-
pattern:
|
|
29629
|
+
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*\\+",
|
|
29553
29630
|
flags: "gi"
|
|
29554
29631
|
},
|
|
29555
29632
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -29564,7 +29641,7 @@ var sql_inject_format_default = {
|
|
|
29564
29641
|
severity: "high",
|
|
29565
29642
|
matcher: {
|
|
29566
29643
|
type: "regex",
|
|
29567
|
-
pattern:
|
|
29644
|
+
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]+\\})",
|
|
29568
29645
|
flags: "gi"
|
|
29569
29646
|
},
|
|
29570
29647
|
examples: [
|
|
@@ -29573,6 +29650,24 @@ var sql_inject_format_default = {
|
|
|
29573
29650
|
]
|
|
29574
29651
|
};
|
|
29575
29652
|
|
|
29653
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
29654
|
+
var sql_inject_interp_multiline_default = {
|
|
29655
|
+
specVersion: 1,
|
|
29656
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
29657
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
29658
|
+
category: "code_flaw",
|
|
29659
|
+
severity: "high",
|
|
29660
|
+
matcher: {
|
|
29661
|
+
type: "regex",
|
|
29662
|
+
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_])',
|
|
29663
|
+
flags: "gi"
|
|
29664
|
+
},
|
|
29665
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
29666
|
+
appliesTo: {
|
|
29667
|
+
extensions: [".rb", ".php"]
|
|
29668
|
+
}
|
|
29669
|
+
};
|
|
29670
|
+
|
|
29576
29671
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
29577
29672
|
var sql_inject_interp_default = {
|
|
29578
29673
|
specVersion: 1,
|
|
@@ -29582,7 +29677,7 @@ var sql_inject_interp_default = {
|
|
|
29582
29677
|
severity: "high",
|
|
29583
29678
|
matcher: {
|
|
29584
29679
|
type: "regex",
|
|
29585
|
-
pattern: "([\
|
|
29680
|
+
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_])',
|
|
29586
29681
|
flags: "gi"
|
|
29587
29682
|
},
|
|
29588
29683
|
examples: [
|
|
@@ -31310,12 +31405,13 @@ var BUNDLED_PACKS = [
|
|
|
31310
31405
|
{
|
|
31311
31406
|
packId: "code-flaws",
|
|
31312
31407
|
name: "Code Security Flaws",
|
|
31313
|
-
version: "0.1.
|
|
31408
|
+
version: "0.1.6",
|
|
31314
31409
|
rawRules: [
|
|
31315
31410
|
sql_inject_concat_default,
|
|
31316
31411
|
sql_inject_concat_dot_default,
|
|
31317
31412
|
sql_inject_format_default,
|
|
31318
31413
|
sql_inject_interp_default,
|
|
31414
|
+
sql_inject_interp_multiline_default,
|
|
31319
31415
|
cmd_inject_shell_default,
|
|
31320
31416
|
cmd_inject_exec_default,
|
|
31321
31417
|
cmd_inject_node_exec_default,
|
|
@@ -31347,6 +31443,7 @@ var BUNDLED_PACKS = [
|
|
|
31347
31443
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
31348
31444
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
31349
31445
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
31446
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
31350
31447
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
31351
31448
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
31352
31449
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -33070,6 +33167,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
33070
33167
|
text: text2,
|
|
33071
33168
|
filePath: context?.filePath,
|
|
33072
33169
|
eventKind: context?.eventKind,
|
|
33170
|
+
writtenRegions: context?.writtenRegions,
|
|
33073
33171
|
attribute: scanOpts?.attribute === true
|
|
33074
33172
|
}),
|
|
33075
33173
|
reply: (message2) => {
|
package/scripts/stop.js
CHANGED
|
@@ -15104,6 +15104,21 @@ function passesPostValidators(rule, value) {
|
|
|
15104
15104
|
function getLoadedRules() {
|
|
15105
15105
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
15106
15106
|
}
|
|
15107
|
+
function outsideWrittenRegions(candidates, context) {
|
|
15108
|
+
const regions = context?.writtenRegions;
|
|
15109
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
15110
|
+
return candidates.filter((c) => {
|
|
15111
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
15112
|
+
const { start, end } = c.match.span;
|
|
15113
|
+
return !regions.some(
|
|
15114
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
15115
|
+
c.rule,
|
|
15116
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
15117
|
+
"code_change"
|
|
15118
|
+
)
|
|
15119
|
+
);
|
|
15120
|
+
});
|
|
15121
|
+
}
|
|
15107
15122
|
function spansOverlap(a, b) {
|
|
15108
15123
|
return a.start < b.end && a.end > b.start;
|
|
15109
15124
|
}
|
|
@@ -15291,17 +15306,20 @@ function scanEncoded(text2, ruleset, context) {
|
|
|
15291
15306
|
function scanText(text2, ruleset, context) {
|
|
15292
15307
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
15293
15308
|
const normalization = normalizeFormatChars(text2);
|
|
15294
|
-
const originalCandidates =
|
|
15309
|
+
const originalCandidates = outsideWrittenRegions(
|
|
15310
|
+
buildCandidates(text2, ruleset, extension, context?.eventKind),
|
|
15311
|
+
context
|
|
15312
|
+
);
|
|
15295
15313
|
if (!normalization) return gate(originalCandidates, text2, void 0);
|
|
15296
15314
|
const pooledOriginal = originalCandidates.map(
|
|
15297
15315
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
15298
15316
|
);
|
|
15299
|
-
const normalizedCandidates =
|
|
15300
|
-
normalization.normalized,
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
context
|
|
15304
|
-
)
|
|
15317
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
15318
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
15319
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text2)
|
|
15320
|
+
),
|
|
15321
|
+
context
|
|
15322
|
+
);
|
|
15305
15323
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text2, normalization);
|
|
15306
15324
|
return mergeOverlappingSameRule(findings, text2);
|
|
15307
15325
|
}
|
|
@@ -16192,7 +16210,7 @@ var sql_inject_concat_dot_default = {
|
|
|
16192
16210
|
severity: "high",
|
|
16193
16211
|
matcher: {
|
|
16194
16212
|
type: "regex",
|
|
16195
|
-
pattern:
|
|
16213
|
+
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*\\.",
|
|
16196
16214
|
flags: "gi"
|
|
16197
16215
|
},
|
|
16198
16216
|
appliesTo: {
|
|
@@ -16210,7 +16228,7 @@ var sql_inject_concat_default = {
|
|
|
16210
16228
|
severity: "high",
|
|
16211
16229
|
matcher: {
|
|
16212
16230
|
type: "regex",
|
|
16213
|
-
pattern:
|
|
16231
|
+
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*\\+",
|
|
16214
16232
|
flags: "gi"
|
|
16215
16233
|
},
|
|
16216
16234
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -16225,7 +16243,7 @@ var sql_inject_format_default = {
|
|
|
16225
16243
|
severity: "high",
|
|
16226
16244
|
matcher: {
|
|
16227
16245
|
type: "regex",
|
|
16228
|
-
pattern:
|
|
16246
|
+
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]+\\})",
|
|
16229
16247
|
flags: "gi"
|
|
16230
16248
|
},
|
|
16231
16249
|
examples: [
|
|
@@ -16234,6 +16252,24 @@ var sql_inject_format_default = {
|
|
|
16234
16252
|
]
|
|
16235
16253
|
};
|
|
16236
16254
|
|
|
16255
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
16256
|
+
var sql_inject_interp_multiline_default = {
|
|
16257
|
+
specVersion: 1,
|
|
16258
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
16259
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
16260
|
+
category: "code_flaw",
|
|
16261
|
+
severity: "high",
|
|
16262
|
+
matcher: {
|
|
16263
|
+
type: "regex",
|
|
16264
|
+
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_])',
|
|
16265
|
+
flags: "gi"
|
|
16266
|
+
},
|
|
16267
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
16268
|
+
appliesTo: {
|
|
16269
|
+
extensions: [".rb", ".php"]
|
|
16270
|
+
}
|
|
16271
|
+
};
|
|
16272
|
+
|
|
16237
16273
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
16238
16274
|
var sql_inject_interp_default = {
|
|
16239
16275
|
specVersion: 1,
|
|
@@ -16243,7 +16279,7 @@ var sql_inject_interp_default = {
|
|
|
16243
16279
|
severity: "high",
|
|
16244
16280
|
matcher: {
|
|
16245
16281
|
type: "regex",
|
|
16246
|
-
pattern: "([\
|
|
16282
|
+
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_])',
|
|
16247
16283
|
flags: "gi"
|
|
16248
16284
|
},
|
|
16249
16285
|
examples: [
|
|
@@ -17971,12 +18007,13 @@ var BUNDLED_PACKS = [
|
|
|
17971
18007
|
{
|
|
17972
18008
|
packId: "code-flaws",
|
|
17973
18009
|
name: "Code Security Flaws",
|
|
17974
|
-
version: "0.1.
|
|
18010
|
+
version: "0.1.6",
|
|
17975
18011
|
rawRules: [
|
|
17976
18012
|
sql_inject_concat_default,
|
|
17977
18013
|
sql_inject_concat_dot_default,
|
|
17978
18014
|
sql_inject_format_default,
|
|
17979
18015
|
sql_inject_interp_default,
|
|
18016
|
+
sql_inject_interp_multiline_default,
|
|
17980
18017
|
cmd_inject_shell_default,
|
|
17981
18018
|
cmd_inject_exec_default,
|
|
17982
18019
|
cmd_inject_node_exec_default,
|
|
@@ -18008,6 +18045,7 @@ var BUNDLED_PACKS = [
|
|
|
18008
18045
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
18009
18046
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
18010
18047
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
18048
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
18011
18049
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
18012
18050
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
18013
18051
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -28096,6 +28134,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
28096
28134
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
28097
28135
|
);
|
|
28098
28136
|
}
|
|
28137
|
+
/**
|
|
28138
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
28139
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
28140
|
+
* every row.
|
|
28141
|
+
*
|
|
28142
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
28143
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
28144
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
28145
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
28146
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
28147
|
+
*
|
|
28148
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
28149
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
28150
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
28151
|
+
*
|
|
28152
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
28153
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
28154
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
28155
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
28156
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
28157
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
28158
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
28159
|
+
*/
|
|
28160
|
+
countFingerprintEpochs(currentVersion) {
|
|
28161
|
+
const row = getRow(
|
|
28162
|
+
this.db.prepare(
|
|
28163
|
+
`SELECT COUNT(*) AS total,
|
|
28164
|
+
COALESCE(
|
|
28165
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
28166
|
+
0
|
|
28167
|
+
) AS stale
|
|
28168
|
+
FROM secret_vault`
|
|
28169
|
+
),
|
|
28170
|
+
{ currentVersion }
|
|
28171
|
+
) ?? { stale: 0, total: 0 };
|
|
28172
|
+
return { stale: row.stale, total: row.total };
|
|
28173
|
+
}
|
|
28099
28174
|
};
|
|
28100
28175
|
|
|
28101
28176
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -29865,13 +29940,22 @@ var SecretVault = class {
|
|
|
29865
29940
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
29866
29941
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
29867
29942
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
29943
|
+
*
|
|
29944
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
29945
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
29946
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
29947
|
+
* than a bare success count.
|
|
29868
29948
|
*/
|
|
29869
29949
|
async refreshFingerprints(next) {
|
|
29870
29950
|
let refreshed = 0;
|
|
29951
|
+
let skipped = 0;
|
|
29871
29952
|
for (const row of this.#repo.listAll()) {
|
|
29872
29953
|
try {
|
|
29873
29954
|
const raw = await this.#openRow(row);
|
|
29874
|
-
if (raw === null)
|
|
29955
|
+
if (raw === null) {
|
|
29956
|
+
skipped += 1;
|
|
29957
|
+
continue;
|
|
29958
|
+
}
|
|
29875
29959
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
29876
29960
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
29877
29961
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -29879,10 +29963,10 @@ var SecretVault = class {
|
|
|
29879
29963
|
});
|
|
29880
29964
|
refreshed += 1;
|
|
29881
29965
|
} catch {
|
|
29882
|
-
|
|
29966
|
+
skipped += 1;
|
|
29883
29967
|
}
|
|
29884
29968
|
}
|
|
29885
|
-
return refreshed;
|
|
29969
|
+
return { refreshed, skipped };
|
|
29886
29970
|
}
|
|
29887
29971
|
/**
|
|
29888
29972
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -30376,6 +30460,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
30376
30460
|
text: text2,
|
|
30377
30461
|
filePath: context?.filePath,
|
|
30378
30462
|
eventKind: context?.eventKind,
|
|
30463
|
+
writtenRegions: context?.writtenRegions,
|
|
30379
30464
|
attribute: scanOpts?.attribute === true
|
|
30380
30465
|
}),
|
|
30381
30466
|
reply: (message) => {
|