@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aka-codex",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"description": "AI Traffic Control \u2014 inspect and govern AI prompts in Codex CLI. Detection runs locally; events are recorded to a local SQLite store on your machine.",
|
|
5
5
|
"hooks": "./hooks/hooks.json",
|
|
6
6
|
"skills": "./skills",
|
package/package.json
CHANGED
|
@@ -22172,6 +22172,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
22172
22172
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
22173
22173
|
);
|
|
22174
22174
|
}
|
|
22175
|
+
/**
|
|
22176
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
22177
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
22178
|
+
* every row.
|
|
22179
|
+
*
|
|
22180
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
22181
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
22182
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
22183
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
22184
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
22185
|
+
*
|
|
22186
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
22187
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
22188
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
22189
|
+
*
|
|
22190
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
22191
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
22192
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
22193
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
22194
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
22195
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
22196
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
22197
|
+
*/
|
|
22198
|
+
countFingerprintEpochs(currentVersion) {
|
|
22199
|
+
const row = getRow(
|
|
22200
|
+
this.db.prepare(
|
|
22201
|
+
`SELECT COUNT(*) AS total,
|
|
22202
|
+
COALESCE(
|
|
22203
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
22204
|
+
0
|
|
22205
|
+
) AS stale
|
|
22206
|
+
FROM secret_vault`
|
|
22207
|
+
),
|
|
22208
|
+
{ currentVersion }
|
|
22209
|
+
) ?? { stale: 0, total: 0 };
|
|
22210
|
+
return { stale: row.stale, total: row.total };
|
|
22211
|
+
}
|
|
22175
22212
|
};
|
|
22176
22213
|
|
|
22177
22214
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -24610,6 +24647,21 @@ function registerPack(pack) {
|
|
|
24610
24647
|
function getLoadedRules() {
|
|
24611
24648
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
24612
24649
|
}
|
|
24650
|
+
function outsideWrittenRegions(candidates, context) {
|
|
24651
|
+
const regions = context?.writtenRegions;
|
|
24652
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
24653
|
+
return candidates.filter((c) => {
|
|
24654
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
24655
|
+
const { start, end } = c.match.span;
|
|
24656
|
+
return !regions.some(
|
|
24657
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
24658
|
+
c.rule,
|
|
24659
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
24660
|
+
"code_change"
|
|
24661
|
+
)
|
|
24662
|
+
);
|
|
24663
|
+
});
|
|
24664
|
+
}
|
|
24613
24665
|
function spansOverlap(a, b) {
|
|
24614
24666
|
return a.start < b.end && a.end > b.start;
|
|
24615
24667
|
}
|
|
@@ -24797,17 +24849,20 @@ function scanEncoded(text, ruleset, context) {
|
|
|
24797
24849
|
function scanText(text, ruleset, context) {
|
|
24798
24850
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
24799
24851
|
const normalization = normalizeFormatChars(text);
|
|
24800
|
-
const originalCandidates =
|
|
24852
|
+
const originalCandidates = outsideWrittenRegions(
|
|
24853
|
+
buildCandidates(text, ruleset, extension, context?.eventKind),
|
|
24854
|
+
context
|
|
24855
|
+
);
|
|
24801
24856
|
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
24802
24857
|
const pooledOriginal = originalCandidates.map(
|
|
24803
24858
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
24804
24859
|
);
|
|
24805
|
-
const normalizedCandidates =
|
|
24806
|
-
normalization.normalized,
|
|
24807
|
-
|
|
24808
|
-
|
|
24809
|
-
context
|
|
24810
|
-
)
|
|
24860
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
24861
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
24862
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
24863
|
+
),
|
|
24864
|
+
context
|
|
24865
|
+
);
|
|
24811
24866
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
24812
24867
|
return mergeOverlappingSameRule(findings, text);
|
|
24813
24868
|
}
|
|
@@ -24868,6 +24923,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
|
|
|
24868
24923
|
"code-flaws/sql-inject-concat-dot",
|
|
24869
24924
|
"code-flaws/sql-inject-format",
|
|
24870
24925
|
"code-flaws/sql-inject-interp",
|
|
24926
|
+
"code-flaws/sql-inject-interp-multiline",
|
|
24871
24927
|
"code-flaws/ssrf-user-url",
|
|
24872
24928
|
"code-flaws/xss-dangerously-set",
|
|
24873
24929
|
"code-flaws/xss-inner-html",
|
|
@@ -25957,7 +26013,7 @@ var sql_inject_concat_dot_default = {
|
|
|
25957
26013
|
severity: "high",
|
|
25958
26014
|
matcher: {
|
|
25959
26015
|
type: "regex",
|
|
25960
|
-
pattern:
|
|
26016
|
+
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*\\.",
|
|
25961
26017
|
flags: "gi"
|
|
25962
26018
|
},
|
|
25963
26019
|
appliesTo: {
|
|
@@ -25975,7 +26031,7 @@ var sql_inject_concat_default = {
|
|
|
25975
26031
|
severity: "high",
|
|
25976
26032
|
matcher: {
|
|
25977
26033
|
type: "regex",
|
|
25978
|
-
pattern:
|
|
26034
|
+
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*\\+",
|
|
25979
26035
|
flags: "gi"
|
|
25980
26036
|
},
|
|
25981
26037
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -25990,7 +26046,7 @@ var sql_inject_format_default = {
|
|
|
25990
26046
|
severity: "high",
|
|
25991
26047
|
matcher: {
|
|
25992
26048
|
type: "regex",
|
|
25993
|
-
pattern:
|
|
26049
|
+
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]+\\})",
|
|
25994
26050
|
flags: "gi"
|
|
25995
26051
|
},
|
|
25996
26052
|
examples: [
|
|
@@ -25999,6 +26055,24 @@ var sql_inject_format_default = {
|
|
|
25999
26055
|
]
|
|
26000
26056
|
};
|
|
26001
26057
|
|
|
26058
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
26059
|
+
var sql_inject_interp_multiline_default = {
|
|
26060
|
+
specVersion: 1,
|
|
26061
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
26062
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
26063
|
+
category: "code_flaw",
|
|
26064
|
+
severity: "high",
|
|
26065
|
+
matcher: {
|
|
26066
|
+
type: "regex",
|
|
26067
|
+
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_])',
|
|
26068
|
+
flags: "gi"
|
|
26069
|
+
},
|
|
26070
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
26071
|
+
appliesTo: {
|
|
26072
|
+
extensions: [".rb", ".php"]
|
|
26073
|
+
}
|
|
26074
|
+
};
|
|
26075
|
+
|
|
26002
26076
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
26003
26077
|
var sql_inject_interp_default = {
|
|
26004
26078
|
specVersion: 1,
|
|
@@ -26008,7 +26082,7 @@ var sql_inject_interp_default = {
|
|
|
26008
26082
|
severity: "high",
|
|
26009
26083
|
matcher: {
|
|
26010
26084
|
type: "regex",
|
|
26011
|
-
pattern: "([\
|
|
26085
|
+
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_])',
|
|
26012
26086
|
flags: "gi"
|
|
26013
26087
|
},
|
|
26014
26088
|
examples: [
|
|
@@ -27736,12 +27810,13 @@ var BUNDLED_PACKS = [
|
|
|
27736
27810
|
{
|
|
27737
27811
|
packId: "code-flaws",
|
|
27738
27812
|
name: "Code Security Flaws",
|
|
27739
|
-
version: "0.1.
|
|
27813
|
+
version: "0.1.6",
|
|
27740
27814
|
rawRules: [
|
|
27741
27815
|
sql_inject_concat_default,
|
|
27742
27816
|
sql_inject_concat_dot_default,
|
|
27743
27817
|
sql_inject_format_default,
|
|
27744
27818
|
sql_inject_interp_default,
|
|
27819
|
+
sql_inject_interp_multiline_default,
|
|
27745
27820
|
cmd_inject_shell_default,
|
|
27746
27821
|
cmd_inject_exec_default,
|
|
27747
27822
|
cmd_inject_node_exec_default,
|
|
@@ -27773,6 +27848,7 @@ var BUNDLED_PACKS = [
|
|
|
27773
27848
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
27774
27849
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
27775
27850
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
27851
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
27776
27852
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
27777
27853
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
27778
27854
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
package/scripts/backfill.js
CHANGED
|
@@ -15120,6 +15120,21 @@ function registerPack(pack) {
|
|
|
15120
15120
|
function getLoadedRules() {
|
|
15121
15121
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
15122
15122
|
}
|
|
15123
|
+
function outsideWrittenRegions(candidates, context) {
|
|
15124
|
+
const regions = context?.writtenRegions;
|
|
15125
|
+
if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
|
|
15126
|
+
return candidates.filter((c) => {
|
|
15127
|
+
if (c.rule.category !== "code_flaw") return true;
|
|
15128
|
+
const { start, end } = c.match.span;
|
|
15129
|
+
return !regions.some(
|
|
15130
|
+
(r) => r.start <= start && end <= r.end && ruleApplies(
|
|
15131
|
+
c.rule,
|
|
15132
|
+
r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
|
|
15133
|
+
"code_change"
|
|
15134
|
+
)
|
|
15135
|
+
);
|
|
15136
|
+
});
|
|
15137
|
+
}
|
|
15123
15138
|
function spansOverlap(a, b) {
|
|
15124
15139
|
return a.start < b.end && a.end > b.start;
|
|
15125
15140
|
}
|
|
@@ -15307,17 +15322,20 @@ function scanEncoded(text, ruleset, context) {
|
|
|
15307
15322
|
function scanText(text, ruleset, context) {
|
|
15308
15323
|
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
15309
15324
|
const normalization = normalizeFormatChars(text);
|
|
15310
|
-
const originalCandidates =
|
|
15325
|
+
const originalCandidates = outsideWrittenRegions(
|
|
15326
|
+
buildCandidates(text, ruleset, extension, context?.eventKind),
|
|
15327
|
+
context
|
|
15328
|
+
);
|
|
15311
15329
|
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
15312
15330
|
const pooledOriginal = originalCandidates.map(
|
|
15313
15331
|
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
15314
15332
|
);
|
|
15315
|
-
const normalizedCandidates =
|
|
15316
|
-
normalization.normalized,
|
|
15317
|
-
|
|
15318
|
-
|
|
15319
|
-
context
|
|
15320
|
-
)
|
|
15333
|
+
const normalizedCandidates = outsideWrittenRegions(
|
|
15334
|
+
buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
|
|
15335
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
15336
|
+
),
|
|
15337
|
+
context
|
|
15338
|
+
);
|
|
15321
15339
|
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
15322
15340
|
return mergeOverlappingSameRule(findings, text);
|
|
15323
15341
|
}
|
|
@@ -15378,6 +15396,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
|
|
|
15378
15396
|
"code-flaws/sql-inject-concat-dot",
|
|
15379
15397
|
"code-flaws/sql-inject-format",
|
|
15380
15398
|
"code-flaws/sql-inject-interp",
|
|
15399
|
+
"code-flaws/sql-inject-interp-multiline",
|
|
15381
15400
|
"code-flaws/ssrf-user-url",
|
|
15382
15401
|
"code-flaws/xss-dangerously-set",
|
|
15383
15402
|
"code-flaws/xss-inner-html",
|
|
@@ -16616,7 +16635,7 @@ var sql_inject_concat_dot_default = {
|
|
|
16616
16635
|
severity: "high",
|
|
16617
16636
|
matcher: {
|
|
16618
16637
|
type: "regex",
|
|
16619
|
-
pattern:
|
|
16638
|
+
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*\\.",
|
|
16620
16639
|
flags: "gi"
|
|
16621
16640
|
},
|
|
16622
16641
|
appliesTo: {
|
|
@@ -16634,7 +16653,7 @@ var sql_inject_concat_default = {
|
|
|
16634
16653
|
severity: "high",
|
|
16635
16654
|
matcher: {
|
|
16636
16655
|
type: "regex",
|
|
16637
|
-
pattern:
|
|
16656
|
+
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*\\+",
|
|
16638
16657
|
flags: "gi"
|
|
16639
16658
|
},
|
|
16640
16659
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -16649,7 +16668,7 @@ var sql_inject_format_default = {
|
|
|
16649
16668
|
severity: "high",
|
|
16650
16669
|
matcher: {
|
|
16651
16670
|
type: "regex",
|
|
16652
|
-
pattern:
|
|
16671
|
+
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]+\\})",
|
|
16653
16672
|
flags: "gi"
|
|
16654
16673
|
},
|
|
16655
16674
|
examples: [
|
|
@@ -16658,6 +16677,24 @@ var sql_inject_format_default = {
|
|
|
16658
16677
|
]
|
|
16659
16678
|
};
|
|
16660
16679
|
|
|
16680
|
+
// ../../rules/code-flaws/sql-inject-interp-multiline.json
|
|
16681
|
+
var sql_inject_interp_multiline_default = {
|
|
16682
|
+
specVersion: 1,
|
|
16683
|
+
id: "code-flaws/sql-inject-interp-multiline",
|
|
16684
|
+
name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
|
|
16685
|
+
category: "code_flaw",
|
|
16686
|
+
severity: "high",
|
|
16687
|
+
matcher: {
|
|
16688
|
+
type: "regex",
|
|
16689
|
+
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_])',
|
|
16690
|
+
flags: "gi"
|
|
16691
|
+
},
|
|
16692
|
+
examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
|
|
16693
|
+
appliesTo: {
|
|
16694
|
+
extensions: [".rb", ".php"]
|
|
16695
|
+
}
|
|
16696
|
+
};
|
|
16697
|
+
|
|
16661
16698
|
// ../../rules/code-flaws/sql-inject-interp.json
|
|
16662
16699
|
var sql_inject_interp_default = {
|
|
16663
16700
|
specVersion: 1,
|
|
@@ -16667,7 +16704,7 @@ var sql_inject_interp_default = {
|
|
|
16667
16704
|
severity: "high",
|
|
16668
16705
|
matcher: {
|
|
16669
16706
|
type: "regex",
|
|
16670
|
-
pattern: "([\
|
|
16707
|
+
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_])',
|
|
16671
16708
|
flags: "gi"
|
|
16672
16709
|
},
|
|
16673
16710
|
examples: [
|
|
@@ -18395,12 +18432,13 @@ var BUNDLED_PACKS = [
|
|
|
18395
18432
|
{
|
|
18396
18433
|
packId: "code-flaws",
|
|
18397
18434
|
name: "Code Security Flaws",
|
|
18398
|
-
version: "0.1.
|
|
18435
|
+
version: "0.1.6",
|
|
18399
18436
|
rawRules: [
|
|
18400
18437
|
sql_inject_concat_default,
|
|
18401
18438
|
sql_inject_concat_dot_default,
|
|
18402
18439
|
sql_inject_format_default,
|
|
18403
18440
|
sql_inject_interp_default,
|
|
18441
|
+
sql_inject_interp_multiline_default,
|
|
18404
18442
|
cmd_inject_shell_default,
|
|
18405
18443
|
cmd_inject_exec_default,
|
|
18406
18444
|
cmd_inject_node_exec_default,
|
|
@@ -18432,6 +18470,7 @@ var BUNDLED_PACKS = [
|
|
|
18432
18470
|
"code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
|
|
18433
18471
|
"code-flaws/sql-inject-format": "SQL injection (format string)",
|
|
18434
18472
|
"code-flaws/sql-inject-interp": "SQL injection (interpolation)",
|
|
18473
|
+
"code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
|
|
18435
18474
|
"code-flaws/cmd-inject-shell": "Command injection (shell)",
|
|
18436
18475
|
"code-flaws/cmd-inject-exec": "Command injection (Java exec)",
|
|
18437
18476
|
"code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
|
|
@@ -28524,6 +28563,43 @@ var SqliteSecretVaultRepository = class {
|
|
|
28524
28563
|
`SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
|
|
28525
28564
|
);
|
|
28526
28565
|
}
|
|
28566
|
+
/**
|
|
28567
|
+
* Every entry held, and how many of them are NOT under `currentVersion` — the
|
|
28568
|
+
* standing record of a fingerprint-key rotation whose re-key did not reach
|
|
28569
|
+
* every row.
|
|
28570
|
+
*
|
|
28571
|
+
* This is the durable form of what `SecretVault.refreshFingerprints` reports
|
|
28572
|
+
* once. That count is an event, gone the moment it is printed; this is the
|
|
28573
|
+
* condition, and it stays true until some later rotation re-keys the rows. It
|
|
28574
|
+
* is therefore the one that can answer "is a shortfall still outstanding?" —
|
|
28575
|
+
* including for a rotation run from the CLI, which no dashboard render saw.
|
|
28576
|
+
*
|
|
28577
|
+
* `<>` rather than `<`: a row ahead of the current version is equally
|
|
28578
|
+
* unmatchable, and that is reachable — a key file restored from a backup, or
|
|
28579
|
+
* replaced after being lost, leaves rows stamped higher than the key is.
|
|
28580
|
+
*
|
|
28581
|
+
* Both numbers come from ONE statement, which is why this returns a pair
|
|
28582
|
+
* instead of offering two counts to call. Read separately, a purge landing
|
|
28583
|
+
* between them hands back a `stale` counted over rows the later `total` no
|
|
28584
|
+
* longer includes, and a disclosure built from that pair states a fraction
|
|
28585
|
+
* true of no state of the table — "1 of 0 stored values", or a negative
|
|
28586
|
+
* remainder. Same reasoning as `purgeVault`'s count, which comes from the
|
|
28587
|
+
* delete rather than from a `countEntries` standing beside it.
|
|
28588
|
+
*/
|
|
28589
|
+
countFingerprintEpochs(currentVersion) {
|
|
28590
|
+
const row = getRow(
|
|
28591
|
+
this.db.prepare(
|
|
28592
|
+
`SELECT COUNT(*) AS total,
|
|
28593
|
+
COALESCE(
|
|
28594
|
+
SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
|
|
28595
|
+
0
|
|
28596
|
+
) AS stale
|
|
28597
|
+
FROM secret_vault`
|
|
28598
|
+
),
|
|
28599
|
+
{ currentVersion }
|
|
28600
|
+
) ?? { stale: 0, total: 0 };
|
|
28601
|
+
return { stale: row.stale, total: row.total };
|
|
28602
|
+
}
|
|
28527
28603
|
};
|
|
28528
28604
|
|
|
28529
28605
|
// ../../packages/persistence/src/repositories/security.ts
|
|
@@ -30333,13 +30409,22 @@ var SecretVault = class {
|
|
|
30333
30409
|
* fingerprint collides with a row already refreshed, is skipped rather than
|
|
30334
30410
|
* aborting the pass — one damaged entry must not strand the re-key of every
|
|
30335
30411
|
* other. A skipped row keeps resolving under its old fingerprint epoch.
|
|
30412
|
+
*
|
|
30413
|
+
* Every skip is COUNTED, because best-effort and silent are different things:
|
|
30414
|
+
* the loss above is invisible at the moment it happens and only shows up later
|
|
30415
|
+
* as a duplicate pointer, so the pass owes its caller a denominator rather
|
|
30416
|
+
* than a bare success count.
|
|
30336
30417
|
*/
|
|
30337
30418
|
async refreshFingerprints(next) {
|
|
30338
30419
|
let refreshed = 0;
|
|
30420
|
+
let skipped = 0;
|
|
30339
30421
|
for (const row of this.#repo.listAll()) {
|
|
30340
30422
|
try {
|
|
30341
30423
|
const raw = await this.#openRow(row);
|
|
30342
|
-
if (raw === null)
|
|
30424
|
+
if (raw === null) {
|
|
30425
|
+
skipped += 1;
|
|
30426
|
+
continue;
|
|
30427
|
+
}
|
|
30343
30428
|
this.#repo.refreshFingerprint(row.pointerId, {
|
|
30344
30429
|
valueFingerprint: exactFingerprintValue(next, raw),
|
|
30345
30430
|
valueIdentityFingerprint: fingerprintValue(next, raw),
|
|
@@ -30347,10 +30432,10 @@ var SecretVault = class {
|
|
|
30347
30432
|
});
|
|
30348
30433
|
refreshed += 1;
|
|
30349
30434
|
} catch {
|
|
30350
|
-
|
|
30435
|
+
skipped += 1;
|
|
30351
30436
|
}
|
|
30352
30437
|
}
|
|
30353
|
-
return refreshed;
|
|
30438
|
+
return { refreshed, skipped };
|
|
30354
30439
|
}
|
|
30355
30440
|
/**
|
|
30356
30441
|
* Destroy every entry, making all outstanding pointers permanently
|
|
@@ -31357,6 +31442,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
31357
31442
|
text,
|
|
31358
31443
|
filePath: context?.filePath,
|
|
31359
31444
|
eventKind: context?.eventKind,
|
|
31445
|
+
writtenRegions: context?.writtenRegions,
|
|
31360
31446
|
attribute: scanOpts?.attribute === true
|
|
31361
31447
|
}),
|
|
31362
31448
|
reply: (message) => {
|
|
@@ -32130,7 +32216,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
32130
32216
|
input.text,
|
|
32131
32217
|
{
|
|
32132
32218
|
filePath: input.metadata?.filePath,
|
|
32133
|
-
eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
|
|
32219
|
+
eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
|
|
32220
|
+
writtenRegions: opts2.writtenRegions
|
|
32134
32221
|
},
|
|
32135
32222
|
{
|
|
32136
32223
|
sourceTool: input.sourceTool,
|
|
@@ -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
|