circle-ir 4.21.0 → 4.21.1
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/analysis/passes/language-sources-pass.d.ts +21 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +264 -9
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/browser/circle-ir.js +177 -7
- package/package.json +1 -1
|
@@ -602,9 +602,29 @@ export declare function findGoXmlDecoderXxeFindings(code: string, file: string):
|
|
|
602
602
|
* Flask/FastAPI request extractor (request.args/form/values/json/data).
|
|
603
603
|
*/
|
|
604
604
|
export declare function findPythonJinjaTemplateSstiFindings(code: string, file: string): SastFinding[];
|
|
605
|
+
/**
|
|
606
|
+
* The text of the first argument of a call whose `(` ends just before
|
|
607
|
+
* `start` on `line`: up to the first top-level `,` or the closing `)`, or
|
|
608
|
+
* to the end of the line when the call continues on the next one.
|
|
609
|
+
*/
|
|
610
|
+
export declare function firstJsCallArg(line: string, start: number): string;
|
|
611
|
+
/**
|
|
612
|
+
* For `const { a, b: c, d = 1 } = <rhs>` whose `<rhs>` reads the request
|
|
613
|
+
* (`reqRe`), the bound names (`a`, `c`, `d`); otherwise null.
|
|
614
|
+
*/
|
|
615
|
+
export declare function jsDestructuredFromRequest(stmt: string, reqRe: RegExp): string[] | null;
|
|
616
|
+
/**
|
|
617
|
+
* `expr` with the text of its string literals blanked: quoted strings become
|
|
618
|
+
* `''`, a template literal keeps only its `${…}` substitutions. What remains
|
|
619
|
+
* is the code that can read a variable.
|
|
620
|
+
*/
|
|
621
|
+
export declare function blankJsStringText(expr: string): string;
|
|
605
622
|
/**
|
|
606
623
|
* Sprint 90 detector C (#189) — JS SSTI via `Handlebars.compile(<tainted>)`
|
|
607
|
-
* or `ejs.render(<tainted>, ...)` / `ejs.compile(<tainted>)
|
|
624
|
+
* or `ejs.render(<tainted>, ...)` / `ejs.compile(<tainted>)`; also
|
|
625
|
+
* `handlebars.compile`, `pug.render` / `pug.compile` and
|
|
626
|
+
* `nunjucks.renderString`. Only the code of the first argument counts: a
|
|
627
|
+
* fixed template literal that names a context variable is not tainted.
|
|
608
628
|
*
|
|
609
629
|
* Compiling an attacker-controlled template lets the attacker execute
|
|
610
630
|
* arbitrary code through helper-shadowing / prototype gadgets
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language-sources-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/language-sources-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAc,WAAW,EAAO,MAAM,sBAAsB,CAAC;AACjJ,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAgC9E,eAAO,MAAM,mBAAmB;;UACK,YAAY;;;UAEb,WAAW;;;UACR,aAAa;;;UACb,aAAa;;;UACjB,WAAW;;;UAGR,YAAY;;;UAQX,WAAW;;;UACV,UAAU;;;UAIC,WAAW;IA8D7D,CAAC;AAwDF,MAAM,WAAW,qBAAqB;IACpC,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACjC,eAAe,EAAE,SAAS,EAAE,CAAC;IAC7B;;;;OAIG;IACH,oBAAoB,EAAE,cAAc,EAAE,CAAC;IACvC;;;OAGG;IACH,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC;;;OAGG;IACH,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAMD,qBAAa,mBAAoB,YAAW,YAAY,CAAC,qBAAqB,CAAC;IAC7E,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,QAAQ,EAAG,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K,EAAE,aAAa,CAAC,QAAQ,CAAC,EAC9B,OAAO,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EACzE,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,GACvC,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAoIjD"}
|
|
@@ -498,6 +498,8 @@ export class LanguageSourcesPass {
|
|
|
498
498
|
additionalSanitizers.push(...findJsParameterizedSqlSanitizers(code));
|
|
499
499
|
// #223 REG-144-20: JS path.resolve/join + startsWith(root) guard.
|
|
500
500
|
additionalSanitizers.push(...findJsPathResolveStartsWithGuardSanitizers(code));
|
|
501
|
+
// JS/TS open_redirect: a same-site relative-path guard that rejects `//` AND `/\`.
|
|
502
|
+
additionalSanitizers.push(...findJsRelativeRedirectGuardSanitizers(code));
|
|
501
503
|
// cognium-dev#1146: same-file helper returns path.resolve after allow-list guard.
|
|
502
504
|
additionalSanitizers.push(...findJsPathAllowlistHelperSanitizers(code));
|
|
503
505
|
// #223 REG-144-17/18/19: JS/TS command allowlist guard
|
|
@@ -8004,7 +8006,8 @@ function findJsPathResolveStartsWithGuardSanitizers(code) {
|
|
|
8004
8006
|
line: c.line,
|
|
8005
8007
|
sanitizes: ['path_traversal', 'external_taint_escape'],
|
|
8006
8008
|
});
|
|
8007
|
-
|
|
8009
|
+
// only inside the function the guard is in, and only until `full` is reassigned (#1257 review B1)
|
|
8010
|
+
for (const l of jsGuardCreditLines(lines, c.line, c.fullVar)) {
|
|
8008
8011
|
if (!varRefRe.test(lines[l]))
|
|
8009
8012
|
continue;
|
|
8010
8013
|
sanitizers.push({
|
|
@@ -8017,6 +8020,126 @@ function findJsPathResolveStartsWithGuardSanitizers(code) {
|
|
|
8017
8020
|
}
|
|
8018
8021
|
return sanitizers;
|
|
8019
8022
|
}
|
|
8023
|
+
/**
|
|
8024
|
+
* JS/TS open_redirect: the same-site relative-path guard (CWE-601).
|
|
8025
|
+
*
|
|
8026
|
+
* if (!next.startsWith('/') || next.startsWith('//') || next.startsWith('/\\')) return res.redirect('/');
|
|
8027
|
+
* res.redirect(next);
|
|
8028
|
+
*
|
|
8029
|
+
* if (next.startsWith('/') && !next.startsWith('//') && !next.startsWith('/\\')) { res.redirect(next); }
|
|
8030
|
+
* if (/^\/(?![\/\\])/.test(next)) { res.redirect(next); }
|
|
8031
|
+
* res.redirect(next.startsWith('/') && !next.startsWith('//') && !next.startsWith('/\\') ? next : '/');
|
|
8032
|
+
*
|
|
8033
|
+
* A path that starts with one `/` and is not `//…` (protocol-relative) or `/\…` (which browsers read as
|
|
8034
|
+
* `//…`) stays on the same site, so the redirect cannot leave it. BOTH `//` and `/\` must be rejected: a guard
|
|
8035
|
+
* that only rejects `//` is still bypassable with `/\evil.example`, and is not credited. The reject form
|
|
8036
|
+
* (conditions joined by `||`, then a terminator) credits every later line that uses the variable; the accept
|
|
8037
|
+
* form (joined by `&&`, or one of the strict regex spellings) credits the lines of its block. Only
|
|
8038
|
+
* `open_redirect` is sanitized. Matching is by substring on the whitespace-free condition (no new regex).
|
|
8039
|
+
*/
|
|
8040
|
+
function findJsRelativeRedirectGuardSanitizers(code) {
|
|
8041
|
+
const sanitizers = [];
|
|
8042
|
+
if (!code.includes('startsWith') && !code.includes('.test('))
|
|
8043
|
+
return sanitizers;
|
|
8044
|
+
const lines = code.split('\n');
|
|
8045
|
+
const quotes = ["'", '"', '`'];
|
|
8046
|
+
const lit = (q, body) => `${q}${body}${q}`;
|
|
8047
|
+
const anyQ = (cond, f) => quotes.some((q) => cond.includes(f(q)));
|
|
8048
|
+
const strictRegexes = ['/^\\/(?![\\/\\\\])/.test(', '/^\\/(?!\\/|\\\\)/.test(', '/^\\/[^\\/\\\\]/.test('];
|
|
8049
|
+
const terminatorRe = /\b(?:throw|return|res\s*\.\s*status\s*\([^)]*\)\s*\.\s*(?:send|end|json))/;
|
|
8050
|
+
const varRefFor = (v) => new RegExp(`(?<![\\w$.])${v.replace(/[.$]/g, '\\$&')}(?![\\w$])`);
|
|
8051
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8052
|
+
const raw = lines[i];
|
|
8053
|
+
const cond = raw.replace(/\s+/g, '');
|
|
8054
|
+
const isIf = /\bif\s*\(/.test(raw);
|
|
8055
|
+
// the ternary form on the redirect line itself: `res.redirect(<guard> ? next : '/')`
|
|
8056
|
+
if (!isIf && !(cond.includes('?') && cond.includes(':')))
|
|
8057
|
+
continue;
|
|
8058
|
+
// the guarded variable: the receiver of `.startsWith('//')`, or the argument of a strict regex's `.test(`
|
|
8059
|
+
let v;
|
|
8060
|
+
for (const q of quotes) {
|
|
8061
|
+
const at = cond.indexOf(`.startsWith(${lit(q, '//')})`);
|
|
8062
|
+
if (at > 0) {
|
|
8063
|
+
let k = at;
|
|
8064
|
+
while (k > 0 && /[\w$.]/.test(cond[k - 1]))
|
|
8065
|
+
k--;
|
|
8066
|
+
v = cond.slice(k, at).replace(/^!+/, '');
|
|
8067
|
+
break;
|
|
8068
|
+
}
|
|
8069
|
+
}
|
|
8070
|
+
const regexAccept = strictRegexes.find((r) => cond.includes(r));
|
|
8071
|
+
if (!v && regexAccept) {
|
|
8072
|
+
const after = cond.slice(cond.indexOf(regexAccept) + regexAccept.length);
|
|
8073
|
+
const m = /^([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\)/.exec(after);
|
|
8074
|
+
v = m?.[1];
|
|
8075
|
+
}
|
|
8076
|
+
if (!v || !/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(v))
|
|
8077
|
+
continue;
|
|
8078
|
+
const slash = (q) => `${v}.startsWith(${lit(q, '/')})`;
|
|
8079
|
+
const dbl = (q) => `${v}.startsWith(${lit(q, '//')})`;
|
|
8080
|
+
const back = (q) => `${v}.startsWith(${lit(q, '/\\\\')})`;
|
|
8081
|
+
const reject = cond.includes('||') && !cond.includes('&&') &&
|
|
8082
|
+
anyQ(cond, (q) => `!${slash(q)}`) && anyQ(cond, dbl) && anyQ(cond, back) &&
|
|
8083
|
+
!anyQ(cond, (q) => `!${dbl(q)}`) && !anyQ(cond, (q) => `!${back(q)}`);
|
|
8084
|
+
const accept = (cond.includes('&&') && !cond.includes('||') &&
|
|
8085
|
+
anyQ(cond, slash) && !anyQ(cond, (q) => `!${slash(q)}`) &&
|
|
8086
|
+
anyQ(cond, (q) => `!${dbl(q)}`) && anyQ(cond, (q) => `!${back(q)}`)) ||
|
|
8087
|
+
(!!regexAccept && !cond.includes(`!${regexAccept}`) && !cond.includes('||'));
|
|
8088
|
+
const ref = varRefFor(v);
|
|
8089
|
+
if (!isIf) {
|
|
8090
|
+
// ternary: credited only when the guarded value is the consequent (`<guard> ? next : <fallback>`)
|
|
8091
|
+
if (accept && cond.includes(`?${v}:`))
|
|
8092
|
+
sanitizers.push({ type: 'js_relative_redirect_guard', method: 'startsWith', line: i + 1, sanitizes: ['open_redirect'] });
|
|
8093
|
+
continue;
|
|
8094
|
+
}
|
|
8095
|
+
if (reject && guardRejects(lines, i, terminatorRe, 2)) {
|
|
8096
|
+
// from the guard line itself, so a block-form guard's own `{ … }` is counted, not read as the function's end
|
|
8097
|
+
for (const l of jsGuardCreditLines(lines, i, v)) {
|
|
8098
|
+
if (ref.test(lines[l]))
|
|
8099
|
+
sanitizers.push({ type: 'js_relative_redirect_guard', method: 'startsWith', line: l + 1, sanitizes: ['open_redirect'] });
|
|
8100
|
+
}
|
|
8101
|
+
}
|
|
8102
|
+
else if (accept) {
|
|
8103
|
+
const block = jsBracedBlockLines(lines, i);
|
|
8104
|
+
const body = block ?? [raw];
|
|
8105
|
+
for (let k = 0; k < body.length; k++) {
|
|
8106
|
+
if (ref.test(k === 0 ? raw.slice(raw.indexOf(')', raw.indexOf('if')) + 1) : body[k])) {
|
|
8107
|
+
sanitizers.push({ type: 'js_relative_redirect_guard', method: 'startsWith', line: i + k + 1, sanitizes: ['open_redirect'] });
|
|
8108
|
+
}
|
|
8109
|
+
}
|
|
8110
|
+
}
|
|
8111
|
+
}
|
|
8112
|
+
return sanitizers;
|
|
8113
|
+
}
|
|
8114
|
+
/**
|
|
8115
|
+
* The lines a guard on `v` at line index `from` may credit: from `from` to the end of the block that encloses it
|
|
8116
|
+
* (the handler or function the guard is in: the first `}` that closes a brace opened before `from`), stopping
|
|
8117
|
+
* before any reassignment of `v` (`v = …`, `let|const|var v = …`). Another handler in the same file, or the
|
|
8118
|
+
* variable after it is reassigned, is never credited by this guard. Braces inside string literals and comments
|
|
8119
|
+
* are not counted apart (a guard line with unbalanced quoted braces credits less, never more).
|
|
8120
|
+
*/
|
|
8121
|
+
function jsGuardCreditLines(lines, from, v) {
|
|
8122
|
+
const esc = v.replace(/[.$]/g, '\\$&');
|
|
8123
|
+
const reassign = new RegExp(`(?:^|[^\\w$.])(?:(?:let|const|var)\\s+)?${esc}\\s*=(?!=)`);
|
|
8124
|
+
const out = [];
|
|
8125
|
+
let depth = 0;
|
|
8126
|
+
for (let l = from; l < lines.length; l++) {
|
|
8127
|
+
const line = lines[l];
|
|
8128
|
+
if (l > from && reassign.test(line))
|
|
8129
|
+
break;
|
|
8130
|
+
out.push(l);
|
|
8131
|
+
for (const c of line) {
|
|
8132
|
+
if (c === '{')
|
|
8133
|
+
depth++;
|
|
8134
|
+
else if (c === '}') {
|
|
8135
|
+
depth--;
|
|
8136
|
+
if (depth < 0)
|
|
8137
|
+
return out; // the enclosing block closed on this line
|
|
8138
|
+
}
|
|
8139
|
+
}
|
|
8140
|
+
}
|
|
8141
|
+
return out;
|
|
8142
|
+
}
|
|
8020
8143
|
/** Lines of one `{ ... }` block starting at `startLineIdx` (inclusive). */
|
|
8021
8144
|
function jsBracedBlockLines(lines, startLineIdx) {
|
|
8022
8145
|
let depth = 0;
|
|
@@ -13811,9 +13934,126 @@ export function findPythonJinjaTemplateSstiFindings(code, file) {
|
|
|
13811
13934
|
}
|
|
13812
13935
|
return findings;
|
|
13813
13936
|
}
|
|
13937
|
+
/**
|
|
13938
|
+
* The text of the first argument of a call whose `(` ends just before
|
|
13939
|
+
* `start` on `line`: up to the first top-level `,` or the closing `)`, or
|
|
13940
|
+
* to the end of the line when the call continues on the next one.
|
|
13941
|
+
*/
|
|
13942
|
+
export function firstJsCallArg(line, start) {
|
|
13943
|
+
let depth = 0;
|
|
13944
|
+
for (let k = start; k < line.length; k++) {
|
|
13945
|
+
const ch = line[k];
|
|
13946
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
13947
|
+
const end = line.indexOf(ch, k + 1);
|
|
13948
|
+
if (end < 0)
|
|
13949
|
+
return line.slice(start);
|
|
13950
|
+
// Skip escaped quotes.
|
|
13951
|
+
let e = end;
|
|
13952
|
+
while (e > 0 && line[e - 1] === '\\') {
|
|
13953
|
+
const next = line.indexOf(ch, e + 1);
|
|
13954
|
+
if (next < 0)
|
|
13955
|
+
return line.slice(start);
|
|
13956
|
+
e = next;
|
|
13957
|
+
}
|
|
13958
|
+
k = e;
|
|
13959
|
+
continue;
|
|
13960
|
+
}
|
|
13961
|
+
if (ch === '(' || ch === '[' || ch === '{')
|
|
13962
|
+
depth++;
|
|
13963
|
+
else if (ch === ')' || ch === ']' || ch === '}') {
|
|
13964
|
+
if (depth === 0)
|
|
13965
|
+
return line.slice(start, k);
|
|
13966
|
+
depth--;
|
|
13967
|
+
}
|
|
13968
|
+
else if (ch === ',' && depth === 0)
|
|
13969
|
+
return line.slice(start, k);
|
|
13970
|
+
}
|
|
13971
|
+
return line.slice(start);
|
|
13972
|
+
}
|
|
13973
|
+
/**
|
|
13974
|
+
* For `const { a, b: c, d = 1 } = <rhs>` whose `<rhs>` reads the request
|
|
13975
|
+
* (`reqRe`), the bound names (`a`, `c`, `d`); otherwise null.
|
|
13976
|
+
*/
|
|
13977
|
+
export function jsDestructuredFromRequest(stmt, reqRe) {
|
|
13978
|
+
const kw = ['const ', 'let ', 'var '].find(k => stmt.startsWith(k));
|
|
13979
|
+
if (!kw)
|
|
13980
|
+
return null;
|
|
13981
|
+
const t = stmt.slice(kw.length).trimStart();
|
|
13982
|
+
if (!t.startsWith('{'))
|
|
13983
|
+
return null;
|
|
13984
|
+
const close = t.indexOf('}');
|
|
13985
|
+
if (close < 0)
|
|
13986
|
+
return null;
|
|
13987
|
+
const rest = t.slice(close + 1).trimStart();
|
|
13988
|
+
if (!rest.startsWith('=') || !reqRe.test(blankJsStringText(rest.slice(1))))
|
|
13989
|
+
return null;
|
|
13990
|
+
const names = [];
|
|
13991
|
+
for (const raw of t.slice(1, close).split(',')) {
|
|
13992
|
+
let p = raw.trim();
|
|
13993
|
+
const eq = p.indexOf('=');
|
|
13994
|
+
if (eq >= 0)
|
|
13995
|
+
p = p.slice(0, eq).trim();
|
|
13996
|
+
const colon = p.indexOf(':');
|
|
13997
|
+
const bound = (colon >= 0 ? p.slice(colon + 1) : p).trim();
|
|
13998
|
+
if (/^[A-Za-z_$][\w$]*$/.test(bound))
|
|
13999
|
+
names.push(bound);
|
|
14000
|
+
}
|
|
14001
|
+
return names.length > 0 ? names : null;
|
|
14002
|
+
}
|
|
14003
|
+
/**
|
|
14004
|
+
* `expr` with the text of its string literals blanked: quoted strings become
|
|
14005
|
+
* `''`, a template literal keeps only its `${…}` substitutions. What remains
|
|
14006
|
+
* is the code that can read a variable.
|
|
14007
|
+
*/
|
|
14008
|
+
export function blankJsStringText(expr) {
|
|
14009
|
+
let out = '';
|
|
14010
|
+
let k = 0;
|
|
14011
|
+
while (k < expr.length) {
|
|
14012
|
+
const ch = expr[k];
|
|
14013
|
+
if (ch === "'" || ch === '"') {
|
|
14014
|
+
let e = k + 1;
|
|
14015
|
+
while (e < expr.length && expr[e] !== ch)
|
|
14016
|
+
e += expr[e] === '\\' ? 2 : 1;
|
|
14017
|
+
out += "''";
|
|
14018
|
+
k = e + 1;
|
|
14019
|
+
continue;
|
|
14020
|
+
}
|
|
14021
|
+
if (ch === '`') {
|
|
14022
|
+
let e = k + 1;
|
|
14023
|
+
let subs = '';
|
|
14024
|
+
while (e < expr.length && expr[e] !== '`') {
|
|
14025
|
+
if (expr[e] === '\\') {
|
|
14026
|
+
e += 2;
|
|
14027
|
+
continue;
|
|
14028
|
+
}
|
|
14029
|
+
if (expr[e] === '$' && expr[e + 1] === '{') {
|
|
14030
|
+
const close = expr.indexOf('}', e + 2);
|
|
14031
|
+
if (close < 0) {
|
|
14032
|
+
subs += ` ${expr.slice(e + 2)}`;
|
|
14033
|
+
e = expr.length;
|
|
14034
|
+
break;
|
|
14035
|
+
}
|
|
14036
|
+
subs += ` ${expr.slice(e + 2, close)}`;
|
|
14037
|
+
e = close + 1;
|
|
14038
|
+
continue;
|
|
14039
|
+
}
|
|
14040
|
+
e++;
|
|
14041
|
+
}
|
|
14042
|
+
out += `''${subs}`;
|
|
14043
|
+
k = e + 1;
|
|
14044
|
+
continue;
|
|
14045
|
+
}
|
|
14046
|
+
out += ch;
|
|
14047
|
+
k++;
|
|
14048
|
+
}
|
|
14049
|
+
return out;
|
|
14050
|
+
}
|
|
13814
14051
|
/**
|
|
13815
14052
|
* Sprint 90 detector C (#189) — JS SSTI via `Handlebars.compile(<tainted>)`
|
|
13816
|
-
* or `ejs.render(<tainted>, ...)` / `ejs.compile(<tainted>)
|
|
14053
|
+
* or `ejs.render(<tainted>, ...)` / `ejs.compile(<tainted>)`; also
|
|
14054
|
+
* `handlebars.compile`, `pug.render` / `pug.compile` and
|
|
14055
|
+
* `nunjucks.renderString`. Only the code of the first argument counts: a
|
|
14056
|
+
* fixed template literal that names a context variable is not tainted.
|
|
13817
14057
|
*
|
|
13818
14058
|
* Compiling an attacker-controlled template lets the attacker execute
|
|
13819
14059
|
* arbitrary code through helper-shadowing / prototype gadgets
|
|
@@ -13823,8 +14063,9 @@ export function findJsTemplateInjectionSstiFindings(code, file) {
|
|
|
13823
14063
|
const findings = [];
|
|
13824
14064
|
if (typeof code !== 'string' || code.length === 0)
|
|
13825
14065
|
return findings;
|
|
13826
|
-
if (!/\
|
|
13827
|
-
!/\
|
|
14066
|
+
if (!/\b[Hh]andlebars\s*\.\s*compile\s*\(/.test(code) &&
|
|
14067
|
+
!/\b(?:ejs|pug)\s*\.\s*(?:render|compile)\s*\(/.test(code) &&
|
|
14068
|
+
!/\bnunjucks\s*\.\s*renderString\s*\(/.test(code)) {
|
|
13828
14069
|
return findings;
|
|
13829
14070
|
}
|
|
13830
14071
|
if (!/\breq\s*\.\s*(?:query|body|params|headers|cookies)\b/.test(code)) {
|
|
@@ -13839,11 +14080,19 @@ export function findJsTemplateInjectionSstiFindings(code, file) {
|
|
|
13839
14080
|
const t = lines[i].trim();
|
|
13840
14081
|
if (t.startsWith('//'))
|
|
13841
14082
|
continue;
|
|
14083
|
+
// `const { a, b: c } = req.body;` binds every destructured name.
|
|
14084
|
+
const destructured = jsDestructuredFromRequest(t, reqExtractRe);
|
|
14085
|
+
if (destructured) {
|
|
14086
|
+
for (const name of destructured)
|
|
14087
|
+
taintedVars.add(name);
|
|
14088
|
+
continue;
|
|
14089
|
+
}
|
|
13842
14090
|
const m = t.match(/^(?:const|let|var)\s+(\w+)(?:\s*:\s*[^=]+)?\s*=\s*(.+?);?$/);
|
|
13843
14091
|
if (!m)
|
|
13844
14092
|
continue;
|
|
13845
14093
|
const lhs = m[1];
|
|
13846
|
-
|
|
14094
|
+
// A name inside a string literal is text, not a read (`'<p><%= name %></p>'`).
|
|
14095
|
+
const rhs = blankJsStringText(m[2]);
|
|
13847
14096
|
if (taintedVars.has(lhs))
|
|
13848
14097
|
continue;
|
|
13849
14098
|
if (reqExtractRe.test(rhs)) {
|
|
@@ -13862,16 +14111,21 @@ export function findJsTemplateInjectionSstiFindings(code, file) {
|
|
|
13862
14111
|
}
|
|
13863
14112
|
if (taintedVars.size === 0)
|
|
13864
14113
|
return findings;
|
|
13865
|
-
const callRe = /\b(
|
|
14114
|
+
const callRe = /\b([Hh]andlebars\s*\.\s*compile|(?:ejs|pug)\s*\.\s*(?:render|compile)|nunjucks\s*\.\s*renderString)\s*\(/;
|
|
13866
14115
|
const seen = new Set();
|
|
13867
14116
|
for (let i = 0; i < lines.length; i++) {
|
|
13868
14117
|
const line = lines[i];
|
|
13869
14118
|
if (line.trim().startsWith('//'))
|
|
13870
14119
|
continue;
|
|
13871
14120
|
const m = line.match(callRe);
|
|
13872
|
-
if (!m)
|
|
14121
|
+
if (!m || m.index === undefined)
|
|
14122
|
+
continue;
|
|
14123
|
+
// The template source is the first argument; only its code counts —
|
|
14124
|
+
// the text of a string literal (a fixed template that names a context
|
|
14125
|
+
// variable) and the context object after it do not.
|
|
14126
|
+
const arg = blankJsStringText(firstJsCallArg(line, m.index + m[0].length)).trim();
|
|
14127
|
+
if (arg === '')
|
|
13873
14128
|
continue;
|
|
13874
|
-
const arg = m[2].trim();
|
|
13875
14129
|
let tainted = reqExtractRe.test(arg);
|
|
13876
14130
|
if (!tainted) {
|
|
13877
14131
|
for (const v of taintedVars) {
|
|
@@ -13896,7 +14150,8 @@ export function findJsTemplateInjectionSstiFindings(code, file) {
|
|
|
13896
14150
|
level: 'error',
|
|
13897
14151
|
message: 'Server-side template injection: compiling/rendering a template ' +
|
|
13898
14152
|
'whose source is attacker-controlled (`Handlebars.compile(...)` / ' +
|
|
13899
|
-
'`ejs.render(...)`
|
|
14153
|
+
'`ejs.render(...)` / `pug.render(...)` / `nunjucks.renderString(...)`) ' +
|
|
14154
|
+
'opens helper-shadowing, prototype-gadget and template-code RCE ' +
|
|
13900
14155
|
'paths. Use a fixed template and pass user data as context.',
|
|
13901
14156
|
file,
|
|
13902
14157
|
line: i + 1,
|