1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Chained taint identifier collection.
use super::*;
/// Collect bare identifier references from a declarator initializer for the
/// #1146 taint chain step, recursing through the same conservative expression
/// shapes `collect_binding_source_path_candidates` admits (static TS wrappers,
/// await, template substitutions, `+` concat operands, object-literal property
/// values) plus the top-level bare-identifier alias (`const b = a`).
///
/// Deliberately NOT collected (each chained identifier becomes a fresh
/// source-backed binding that can chain further, so every arm here is a
/// false-positive amplifier):
/// - member-expression roots (`const b = a.id`): a property read off a tainted
/// local frequently strips taint in practice (`a.length`,
/// `a.startsWith("/")`); unlike the sink-side `collect_idents_into` member
/// rule (sound because the whole expression flows into a sink), re-tainting
/// the result here would propagate boolean/length/index reads
/// - call expressions (`const b = f(a)`): the call boundary is where
/// sanitizers live; #878 already covers proven helper-return shapes
/// - logical / conditional / sequence expressions (`a || "x"`, `c ? a : b`)
pub(super) fn collect_chained_taint_idents(expr: &Expression<'_>, out: &mut Vec<String>) {
match expr {
Expression::Identifier(ident) => push_ident(ident.name.as_str(), out),
Expression::ParenthesizedExpression(paren) => {
collect_chained_taint_idents(&paren.expression, out);
}
Expression::TSAsExpression(ts_as) => {
collect_chained_taint_idents(&ts_as.expression, out);
}
Expression::TSSatisfiesExpression(ts_sat) => {
collect_chained_taint_idents(&ts_sat.expression, out);
}
Expression::TSNonNullExpression(ts_non_null) => {
collect_chained_taint_idents(&ts_non_null.expression, out);
}
Expression::AwaitExpression(await_expr) => {
collect_chained_taint_idents(&await_expr.argument, out);
}
Expression::TemplateLiteral(template) => {
for expression in &template.expressions {
collect_chained_taint_idents(expression, out);
}
}
Expression::BinaryExpression(binary)
if binary.operator == oxc_ast::ast::BinaryOperator::Addition =>
{
collect_chained_taint_idents(&binary.left, out);
collect_chained_taint_idents(&binary.right, out);
}
Expression::ObjectExpression(object) => {
for property in &object.properties {
let ObjectPropertyKind::ObjectProperty(property) = property else {
continue;
};
collect_chained_taint_idents(&property.value, out);
}
}
_ => {}
}
}