cognium-dev 3.124.0 → 3.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +250 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -22604,6 +22604,9 @@ class LanguageSourcesPass {
|
|
|
22604
22604
|
if (language === "python") {
|
|
22605
22605
|
additionalSanitizers.push(...findPythonNetlocAllowlistGuardSanitizers(code));
|
|
22606
22606
|
additionalSanitizers.push(...findPythonRangeCheckGuardSanitizers(code));
|
|
22607
|
+
additionalSanitizers.push(...findPythonRegexAllowlistWrapperSanitizers(code));
|
|
22608
|
+
additionalSanitizers.push(...findPythonSetMembershipXssGuardSanitizers(code));
|
|
22609
|
+
additionalSanitizers.push(...findPythonDefusedXmlSanitizers(code));
|
|
22607
22610
|
const pyMisconfigFindings = findPythonPatternFindings(code, graph.ir.meta.file);
|
|
22608
22611
|
for (const finding of pyMisconfigFindings) {
|
|
22609
22612
|
ctx.addFinding(finding);
|
|
@@ -24008,6 +24011,252 @@ function findPythonRangeCheckGuardSanitizers(code) {
|
|
|
24008
24011
|
}
|
|
24009
24012
|
return sanitizers;
|
|
24010
24013
|
}
|
|
24014
|
+
function findPythonRegexAllowlistWrapperSanitizers(code) {
|
|
24015
|
+
const sanitizers = [];
|
|
24016
|
+
const lines = code.split(`
|
|
24017
|
+
`);
|
|
24018
|
+
const defOpen = /^(\s*)def\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)\s*:\s*$/;
|
|
24019
|
+
const tightRegex = /r?["'](?:\^)?(?:\\w[+*]|\\d[+*]|\[[A-Za-z0-9_\\\-\.\s]+\][+*]|[A-Za-z0-9_\-\.]+)(?:\$)?["']/;
|
|
24020
|
+
const terminator = /\b(return\s+(?:None|"|'|\(|\[|\{|False|jsonify|make_response|redirect|abort)|raise\s+\w|abort\s*\(|sys\.exit\s*\()/;
|
|
24021
|
+
const wrappers = [];
|
|
24022
|
+
for (let i2 = 0;i2 < lines.length; i2++) {
|
|
24023
|
+
const m = defOpen.exec(lines[i2]);
|
|
24024
|
+
if (!m)
|
|
24025
|
+
continue;
|
|
24026
|
+
const defIndent = m[1].length;
|
|
24027
|
+
const wrapperName = m[2];
|
|
24028
|
+
const argName = m[3];
|
|
24029
|
+
let foundGuard = false;
|
|
24030
|
+
let returnsArg = false;
|
|
24031
|
+
let blockEnd = -1;
|
|
24032
|
+
const maxScan = Math.min(lines.length, i2 + 40);
|
|
24033
|
+
for (let j = i2 + 1;j < maxScan; j++) {
|
|
24034
|
+
const line = lines[j];
|
|
24035
|
+
if (line.trim() === "")
|
|
24036
|
+
continue;
|
|
24037
|
+
const indent = line.length - line.trimStart().length;
|
|
24038
|
+
if (indent <= defIndent) {
|
|
24039
|
+
blockEnd = j - 1;
|
|
24040
|
+
break;
|
|
24041
|
+
}
|
|
24042
|
+
if (!foundGuard) {
|
|
24043
|
+
const guard = new RegExp(`if\\s+not\\s+re\\.(?:fullmatch|match)\\s*\\(\\s*(${tightRegex.source})\\s*,\\s*${argName}\\s*\\)\\s*:`);
|
|
24044
|
+
if (guard.test(line)) {
|
|
24045
|
+
for (let k = j + 1;k < maxScan; k++) {
|
|
24046
|
+
const klin = lines[k];
|
|
24047
|
+
if (klin.trim() === "")
|
|
24048
|
+
continue;
|
|
24049
|
+
const kindent = klin.length - klin.trimStart().length;
|
|
24050
|
+
if (kindent <= indent)
|
|
24051
|
+
break;
|
|
24052
|
+
if (terminator.test(klin))
|
|
24053
|
+
foundGuard = true;
|
|
24054
|
+
break;
|
|
24055
|
+
}
|
|
24056
|
+
}
|
|
24057
|
+
}
|
|
24058
|
+
if (new RegExp(`^\\s*return\\s+${argName}\\s*$`).test(line)) {
|
|
24059
|
+
returnsArg = true;
|
|
24060
|
+
}
|
|
24061
|
+
}
|
|
24062
|
+
if (blockEnd === -1)
|
|
24063
|
+
blockEnd = Math.min(lines.length - 1, i2 + 39);
|
|
24064
|
+
if (!foundGuard || !returnsArg)
|
|
24065
|
+
continue;
|
|
24066
|
+
wrappers.push({ name: wrapperName, defLine: i2, defIndent });
|
|
24067
|
+
}
|
|
24068
|
+
if (wrappers.length === 0)
|
|
24069
|
+
return sanitizers;
|
|
24070
|
+
const wrapperKinds = [
|
|
24071
|
+
"ldap_injection",
|
|
24072
|
+
"xpath_injection",
|
|
24073
|
+
"sql_injection",
|
|
24074
|
+
"command_injection",
|
|
24075
|
+
"path_traversal",
|
|
24076
|
+
"xss",
|
|
24077
|
+
"external_taint_escape"
|
|
24078
|
+
];
|
|
24079
|
+
for (const w of wrappers) {
|
|
24080
|
+
const assignedCallRe = new RegExp(`^(\\s*)([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*${w.name}\\s*\\(`);
|
|
24081
|
+
const bareCallRe = new RegExp(`\\b${w.name}\\s*\\(`);
|
|
24082
|
+
for (let i2 = 0;i2 < lines.length; i2++) {
|
|
24083
|
+
if (i2 === w.defLine)
|
|
24084
|
+
continue;
|
|
24085
|
+
const line = lines[i2];
|
|
24086
|
+
if (!bareCallRe.test(line))
|
|
24087
|
+
continue;
|
|
24088
|
+
if (i2 > w.defLine) {
|
|
24089
|
+
const lineIndent = line.length - line.trimStart().length;
|
|
24090
|
+
if (lineIndent > w.defIndent) {
|
|
24091
|
+
let stillInside = true;
|
|
24092
|
+
for (let k = w.defLine + 1;k < i2; k++) {
|
|
24093
|
+
const kline = lines[k];
|
|
24094
|
+
if (kline.trim() === "")
|
|
24095
|
+
continue;
|
|
24096
|
+
const kindent = kline.length - kline.trimStart().length;
|
|
24097
|
+
if (kindent <= w.defIndent) {
|
|
24098
|
+
stillInside = false;
|
|
24099
|
+
break;
|
|
24100
|
+
}
|
|
24101
|
+
}
|
|
24102
|
+
if (stillInside)
|
|
24103
|
+
continue;
|
|
24104
|
+
}
|
|
24105
|
+
}
|
|
24106
|
+
sanitizers.push({
|
|
24107
|
+
type: "python_regex_allowlist_wrapper",
|
|
24108
|
+
method: w.name,
|
|
24109
|
+
line: i2 + 1,
|
|
24110
|
+
sanitizes: [...wrapperKinds]
|
|
24111
|
+
});
|
|
24112
|
+
const am = assignedCallRe.exec(line);
|
|
24113
|
+
if (!am)
|
|
24114
|
+
continue;
|
|
24115
|
+
const callIndent = am[1].length;
|
|
24116
|
+
const validated = am[2];
|
|
24117
|
+
const validatedRe = new RegExp(`\\b${validated}\\b`);
|
|
24118
|
+
for (let j = i2 + 1;j < lines.length; j++) {
|
|
24119
|
+
const jline = lines[j];
|
|
24120
|
+
if (jline.trim() === "")
|
|
24121
|
+
continue;
|
|
24122
|
+
const jindent = jline.length - jline.trimStart().length;
|
|
24123
|
+
if (jindent < callIndent)
|
|
24124
|
+
break;
|
|
24125
|
+
if (validatedRe.test(jline)) {
|
|
24126
|
+
sanitizers.push({
|
|
24127
|
+
type: "python_regex_allowlist_wrapper",
|
|
24128
|
+
method: w.name,
|
|
24129
|
+
line: j + 1,
|
|
24130
|
+
sanitizes: [...wrapperKinds]
|
|
24131
|
+
});
|
|
24132
|
+
}
|
|
24133
|
+
}
|
|
24134
|
+
}
|
|
24135
|
+
}
|
|
24136
|
+
return sanitizers;
|
|
24137
|
+
}
|
|
24138
|
+
function findPythonSetMembershipXssGuardSanitizers(code) {
|
|
24139
|
+
const sanitizers = [];
|
|
24140
|
+
const lines = code.split(`
|
|
24141
|
+
`);
|
|
24142
|
+
const guardOpen = /^(\s*)if\s+([A-Za-z_][A-Za-z0-9_]*)\s+not\s+in\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*$/;
|
|
24143
|
+
const allowlistName = /^(?:[A-Z][A-Z0-9_]+|.*?(allowed|accepted|whitelist|permitted|valid|approved).*)$/i;
|
|
24144
|
+
const terminator = /\b(return|raise|abort\s*\(|sys\.exit\s*\()/;
|
|
24145
|
+
for (let i2 = 0;i2 < lines.length; i2++) {
|
|
24146
|
+
const m = guardOpen.exec(lines[i2]);
|
|
24147
|
+
if (!m)
|
|
24148
|
+
continue;
|
|
24149
|
+
const guardIndent = m[1].length;
|
|
24150
|
+
const guardedVar = m[2];
|
|
24151
|
+
const allowName = m[3];
|
|
24152
|
+
if (!allowlistName.test(allowName))
|
|
24153
|
+
continue;
|
|
24154
|
+
let bodyHasTerminator = false;
|
|
24155
|
+
let blockEnd = -1;
|
|
24156
|
+
const maxScan = Math.min(lines.length, i2 + 26);
|
|
24157
|
+
for (let j = i2 + 1;j < maxScan; j++) {
|
|
24158
|
+
const line = lines[j];
|
|
24159
|
+
if (line.trim() === "")
|
|
24160
|
+
continue;
|
|
24161
|
+
const indent = line.length - line.trimStart().length;
|
|
24162
|
+
if (indent <= guardIndent) {
|
|
24163
|
+
blockEnd = j - 1;
|
|
24164
|
+
break;
|
|
24165
|
+
}
|
|
24166
|
+
if (terminator.test(line))
|
|
24167
|
+
bodyHasTerminator = true;
|
|
24168
|
+
}
|
|
24169
|
+
if (blockEnd === -1)
|
|
24170
|
+
blockEnd = Math.min(lines.length - 1, i2 + 25);
|
|
24171
|
+
if (!bodyHasTerminator)
|
|
24172
|
+
continue;
|
|
24173
|
+
const varRe = new RegExp(`\\b${guardedVar}\\b`);
|
|
24174
|
+
for (let l = blockEnd + 2;l <= lines.length; l++) {
|
|
24175
|
+
const lineText = lines[l - 1];
|
|
24176
|
+
if (!varRe.test(lineText))
|
|
24177
|
+
continue;
|
|
24178
|
+
sanitizers.push({
|
|
24179
|
+
type: "python_set_membership_xss_guard",
|
|
24180
|
+
method: "if",
|
|
24181
|
+
line: l,
|
|
24182
|
+
sanitizes: ["xss", "external_taint_escape"]
|
|
24183
|
+
});
|
|
24184
|
+
}
|
|
24185
|
+
}
|
|
24186
|
+
return sanitizers;
|
|
24187
|
+
}
|
|
24188
|
+
function findPythonDefusedXmlSanitizers(code) {
|
|
24189
|
+
const sanitizers = [];
|
|
24190
|
+
const lines = code.split(`
|
|
24191
|
+
`);
|
|
24192
|
+
const moduleAliases = new Set;
|
|
24193
|
+
const fromNames = new Set;
|
|
24194
|
+
const importAs = /^\s*import\s+defusedxml(?:\.[A-Za-z_][A-Za-z0-9_.]*)?\s+as\s+([A-Za-z_][A-Za-z0-9_]*)\s*$/;
|
|
24195
|
+
const importBare = /^\s*import\s+defusedxml(?:\.([A-Za-z_][A-Za-z0-9_.]*))?\s*$/;
|
|
24196
|
+
const fromImport = /^\s*from\s+defusedxml(?:\.[A-Za-z_][A-Za-z0-9_.]*)?\s+import\s+(.+)$/;
|
|
24197
|
+
for (const raw of lines) {
|
|
24198
|
+
const line = raw.replace(/#.*$/, "");
|
|
24199
|
+
let m;
|
|
24200
|
+
if (m = importAs.exec(line)) {
|
|
24201
|
+
moduleAliases.add(m[1]);
|
|
24202
|
+
continue;
|
|
24203
|
+
}
|
|
24204
|
+
if (m = importBare.exec(line)) {
|
|
24205
|
+
if (m[1]) {
|
|
24206
|
+
moduleAliases.add(m[1].split(".").pop());
|
|
24207
|
+
}
|
|
24208
|
+
moduleAliases.add("defusedxml");
|
|
24209
|
+
continue;
|
|
24210
|
+
}
|
|
24211
|
+
if (m = fromImport.exec(line)) {
|
|
24212
|
+
const items = m[1].split(",");
|
|
24213
|
+
for (const item of items) {
|
|
24214
|
+
const trimmed = item.trim().replace(/[()\\]/g, "");
|
|
24215
|
+
if (!trimmed)
|
|
24216
|
+
continue;
|
|
24217
|
+
const asMatch = /^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/.exec(trimmed);
|
|
24218
|
+
if (asMatch) {
|
|
24219
|
+
fromNames.add(asMatch[2]);
|
|
24220
|
+
} else if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed)) {
|
|
24221
|
+
fromNames.add(trimmed);
|
|
24222
|
+
}
|
|
24223
|
+
}
|
|
24224
|
+
}
|
|
24225
|
+
}
|
|
24226
|
+
if (moduleAliases.size === 0 && fromNames.size === 0)
|
|
24227
|
+
return sanitizers;
|
|
24228
|
+
for (let i2 = 0;i2 < lines.length; i2++) {
|
|
24229
|
+
const line = lines[i2];
|
|
24230
|
+
if (/^\s*(?:import|from)\s+/.test(line))
|
|
24231
|
+
continue;
|
|
24232
|
+
let matched = false;
|
|
24233
|
+
for (const alias of moduleAliases) {
|
|
24234
|
+
const re = new RegExp(`\\b${alias}\\s*\\.\\s*[A-Za-z_][A-Za-z0-9_]*\\s*\\(`);
|
|
24235
|
+
if (re.test(line)) {
|
|
24236
|
+
matched = true;
|
|
24237
|
+
break;
|
|
24238
|
+
}
|
|
24239
|
+
}
|
|
24240
|
+
if (!matched) {
|
|
24241
|
+
for (const name2 of fromNames) {
|
|
24242
|
+
const re = new RegExp(`\\b${name2}\\s*\\(`);
|
|
24243
|
+
if (re.test(line)) {
|
|
24244
|
+
matched = true;
|
|
24245
|
+
break;
|
|
24246
|
+
}
|
|
24247
|
+
}
|
|
24248
|
+
}
|
|
24249
|
+
if (!matched)
|
|
24250
|
+
continue;
|
|
24251
|
+
sanitizers.push({
|
|
24252
|
+
type: "python_defusedxml_import",
|
|
24253
|
+
method: "defusedxml",
|
|
24254
|
+
line: i2 + 1,
|
|
24255
|
+
sanitizes: ["xxe", "external_taint_escape"]
|
|
24256
|
+
});
|
|
24257
|
+
}
|
|
24258
|
+
return sanitizers;
|
|
24259
|
+
}
|
|
24011
24260
|
function findRustSetAllowlistGuardSanitizers(code) {
|
|
24012
24261
|
const sanitizers = [];
|
|
24013
24262
|
const lines = code.split(`
|
|
@@ -37779,7 +38028,7 @@ var colors = {
|
|
|
37779
38028
|
};
|
|
37780
38029
|
|
|
37781
38030
|
// src/version.ts
|
|
37782
|
-
var version = "3.
|
|
38031
|
+
var version = "3.125.0";
|
|
37783
38032
|
|
|
37784
38033
|
// src/formatters.ts
|
|
37785
38034
|
var LIBRARY_API_SURFACE_TAG2 = "library-api-surface:caller-responsibility";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cognium-dev",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.125.0",
|
|
4
4
|
"description": "Static Application Security Testing CLI for detecting security vulnerabilities via taint tracking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@cognium/project-profile-detect": "^1.1.0",
|
|
69
|
-
"circle-ir": "^3.
|
|
69
|
+
"circle-ir": "^3.125.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/node": "^25.5.0",
|