@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/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);
|
|
@@ -24770,6 +24782,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
24770
24782
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
24771
24783
|
);
|
|
24772
24784
|
}
|
|
24785
|
+
/**
|
|
24786
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
24787
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
24788
|
+
* every row.
|
|
24789
|
+
*
|
|
24790
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
24791
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
24792
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
24793
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
24794
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
24795
|
+
*
|
|
24796
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
24797
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
24798
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
24799
|
+
*
|
|
24800
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
24801
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
24802
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
24803
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
24804
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
24805
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
24806
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
24807
|
+
*/
|
|
24808
|
+
countFingerprintEpochs(currentVersion) {
|
|
24809
|
+
const row = getRow(
|
|
24810
|
+
this.db.prepare(
|
|
24811
|
+
`SELECT COUNT(*) AS total,
|
|
24812
|
+
COALESCE(
|
|
24813
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
24814
|
+
0
|
|
24815
|
+
) AS stale
|
|
24816
|
+
FROM secret_vault`
|
|
24817
|
+
),
|
|
24818
|
+
{ currentVersion }
|
|
24819
|
+
) ?? { stale: 0, total: 0 };
|
|
24820
|
+
return { stale: row.stale, total: row.total };
|
|
24821
|
+
}
|
|
24773
24822
|
};
|
|
24774
24823
|
|
|
24775
24824
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -26568,13 +26617,22 @@ var SecretVault = class {
|
|
|
26568
26617
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
26569
26618
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
26570
26619
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
26620
|
+
*
|
|
26621
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
26622
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
26623
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
26624
|
+
* than a bare success count.
|
|
26571
26625
|
*/
|
|
26572
26626
|
async refreshFingerprints(next) {
|
|
26573
26627
|
let refreshed = 0;
|
|
26628
|
+
let skipped = 0;
|
|
26574
26629
|
for (const row of this.#repo.listAll()) {
|
|
26575
26630
|
try {
|
|
26576
26631
|
const raw = await this.#openRow(row);
|
|
26577
|
-
if (raw === null)
|
|
26632
|
+
if (raw === null) {
|
|
26633
|
+
skipped += 1;
|
|
26634
|
+
continue;
|
|
26635
|
+
}
|
|
26578
26636
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
26579
26637
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
26580
26638
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -26582,10 +26640,10 @@ var SecretVault = class {
|
|
|
26582
26640
|
});
|
|
26583
26641
|
refreshed += 1;
|
|
26584
26642
|
} catch {
|
|
26585
|
-
|
|
26643
|
+
skipped += 1;
|
|
26586
26644
|
}
|
|
26587
26645
|
}
|
|
26588
|
-
return refreshed;
|
|
26646
|
+
return { refreshed, skipped };
|
|
26589
26647
|
}
|
|
26590
26648
|
/**
|
|
26591
26649
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -27924,6 +27982,21 @@ function registerPack(pack) {
|
|
|
27924
27982
|
function getLoadedRules() {
|
|
27925
27983
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
27926
27984
|
}
|
|
27985
|
+
function outsideWrittenRegions(candidates, context) {
|
|
27986
|
+
const regions = context?.writtenRegions;
|
|
27987
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
27988
|
+
return candidates.filter((c) => {
|
|
27989
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
27990
|
+
const { start, end } = c.match.span;
|
|
27991
|
+
return !regions.some(
|
|
27992
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
27993
|
+
c.rule,
|
|
27994
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
27995
|
+
"code_change"
|
|
27996
|
+
)
|
|
27997
|
+
);
|
|
27998
|
+
});
|
|
27999
|
+
}
|
|
27927
28000
|
function spansOverlap(a, b) {
|
|
27928
28001
|
return a.start < b.end && a.end > b.start;
|
|
27929
28002
|
}
|
|
@@ -28111,17 +28184,20 @@ function scanEncoded(text, ruleset, context) {
|
|
|
28111
28184
|
function scanText(text, ruleset, context) {
|
|
28112
28185
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
28113
28186
|
const normalization = normalizeFormatChars(text);
|
|
28114
|
-
const originalCandidates =
|
|
28187
|
+
const originalCandidates = outsideWrittenRegions(
|
|
28188
|
+
buildCandidates(text, ruleset, extension, context?.eventKind),
|
|
28189
|
+
context
|
|
28190
|
+
);
|
|
28115
28191
|
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
28116
28192
|
const pooledOriginal = originalCandidates.map(
|
|
28117
28193
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
28118
28194
|
);
|
|
28119
|
-
const normalizedCandidates =
|
|
28120
|
-
normalization.normalized,
|
|
28121
|
-
|
|
28122
|
-
|
|
28123
|
-
context
|
|
28124
|
-
)
|
|
28195
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
28196
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
28197
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
28198
|
+
),
|
|
28199
|
+
context
|
|
28200
|
+
);
|
|
28125
28201
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
28126
28202
|
return mergeOverlappingSameRule(findings, text);
|
|
28127
28203
|
}
|
|
@@ -28182,6 +28258,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
|
|
|
28182
28258
|
"code-flaws/sql-inject-concat-dot",
|
|
28183
28259
|
"code-flaws/sql-inject-format",
|
|
28184
28260
|
"code-flaws/sql-inject-interp",
|
|
28261
|
+
"code-flaws/sql-inject-interp-multiline",
|
|
28185
28262
|
"code-flaws/ssrf-user-url",
|
|
28186
28263
|
"code-flaws/xss-dangerously-set",
|
|
28187
28264
|
"code-flaws/xss-inner-html",
|
|
@@ -29474,7 +29551,7 @@ var sql_inject_concat_dot_default = {
|
|
|
29474
29551
|
severity: "high",
|
|
29475
29552
|
matcher: {
|
|
29476
29553
|
type: "regex",
|
|
29477
|
-
pattern:
|
|
29554
|
+
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*\\.",
|
|
29478
29555
|
flags: "gi"
|
|
29479
29556
|
},
|
|
29480
29557
|
appliesTo: {
|
|
@@ -29492,7 +29569,7 @@ var sql_inject_concat_default = {
|
|
|
29492
29569
|
severity: "high",
|
|
29493
29570
|
matcher: {
|
|
29494
29571
|
type: "regex",
|
|
29495
|
-
pattern:
|
|
29572
|
+
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*\\+",
|
|
29496
29573
|
flags: "gi"
|
|
29497
29574
|
},
|
|
29498
29575
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -29507,7 +29584,7 @@ var sql_inject_format_default = {
|
|
|
29507
29584
|
severity: "high",
|
|
29508
29585
|
matcher: {
|
|
29509
29586
|
type: "regex",
|
|
29510
|
-
pattern:
|
|
29587
|
+
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]+\\})",
|
|
29511
29588
|
flags: "gi"
|
|
29512
29589
|
},
|
|
29513
29590
|
examples: [
|
|
@@ -29516,6 +29593,24 @@ var sql_inject_format_default = {
|
|
|
29516
29593
|
]
|
|
29517
29594
|
};
|
|
29518
29595
|
|
|
29596
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
29597
|
+
var sql_inject_interp_multiline_default = {
|
|
29598
|
+
specVersion: 1,
|
|
29599
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
29600
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
29601
|
+
category: "code_flaw",
|
|
29602
|
+
severity: "high",
|
|
29603
|
+
matcher: {
|
|
29604
|
+
type: "regex",
|
|
29605
|
+
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_])',
|
|
29606
|
+
flags: "gi"
|
|
29607
|
+
},
|
|
29608
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
29609
|
+
appliesTo: {
|
|
29610
|
+
extensions: [".rb", ".php"]
|
|
29611
|
+
}
|
|
29612
|
+
};
|
|
29613
|
+
|
|
29519
29614
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
29520
29615
|
var sql_inject_interp_default = {
|
|
29521
29616
|
specVersion: 1,
|
|
@@ -29525,7 +29620,7 @@ var sql_inject_interp_default = {
|
|
|
29525
29620
|
severity: "high",
|
|
29526
29621
|
matcher: {
|
|
29527
29622
|
type: "regex",
|
|
29528
|
-
pattern: "([\
|
|
29623
|
+
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_])',
|
|
29529
29624
|
flags: "gi"
|
|
29530
29625
|
},
|
|
29531
29626
|
examples: [
|
|
@@ -31253,12 +31348,13 @@ var BUNDLED_PACKS = [
|
|
|
31253
31348
|
{
|
|
31254
31349
|
packId: "code-flaws",
|
|
31255
31350
|
name: "Code Security Flaws",
|
|
31256
|
-
version: "0.1.
|
|
31351
|
+
version: "0.1.6",
|
|
31257
31352
|
rawRules: [
|
|
31258
31353
|
sql_inject_concat_default,
|
|
31259
31354
|
sql_inject_concat_dot_default,
|
|
31260
31355
|
sql_inject_format_default,
|
|
31261
31356
|
sql_inject_interp_default,
|
|
31357
|
+
sql_inject_interp_multiline_default,
|
|
31262
31358
|
cmd_inject_shell_default,
|
|
31263
31359
|
cmd_inject_exec_default,
|
|
31264
31360
|
cmd_inject_node_exec_default,
|
|
@@ -31290,6 +31386,7 @@ var BUNDLED_PACKS = [
|
|
|
31290
31386
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
31291
31387
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
31292
31388
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
31389
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
31293
31390
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
31294
31391
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
31295
31392
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -33013,6 +33110,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
33013
33110
|
text,
|
|
33014
33111
|
filePath: context?.filePath,
|
|
33015
33112
|
eventKind: context?.eventKind,
|
|
33113
|
+
writtenRegions: context?.writtenRegions,
|
|
33016
33114
|
attribute: scanOpts?.attribute === true
|
|
33017
33115
|
}),
|
|
33018
33116
|
reply: (message2) => {
|