2026-02-24 23:44:07 -05:00
|
|
|
use crate::labels::{Cap, DataLabel, Kind, LabelRule, ParamConfig};
|
|
|
|
|
use phf::{Map, phf_map};
|
2025-06-28 17:36:14 +02:00
|
|
|
|
|
|
|
|
pub static RULES: &[LabelRule] = &[
|
2026-02-24 23:44:07 -05:00
|
|
|
// ─────────── Sources ───────────
|
2025-06-28 17:36:14 +02:00
|
|
|
LabelRule {
|
2026-02-24 23:44:07 -05:00
|
|
|
matchers: &[
|
|
|
|
|
"document.location",
|
|
|
|
|
"window.location",
|
|
|
|
|
"req.body",
|
|
|
|
|
"req.query",
|
|
|
|
|
"req.params",
|
|
|
|
|
"req.headers",
|
|
|
|
|
"req.cookies",
|
|
|
|
|
"process.env",
|
|
|
|
|
],
|
2025-06-28 17:36:14 +02:00
|
|
|
label: DataLabel::Source(Cap::all()),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
// ───────── Sanitizers ──────────
|
2025-06-28 17:36:14 +02:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["JSON.parse"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::JSON_PARSE),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["encodeURIComponent", "encodeURI"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::URL_ENCODE),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["DOMPurify.sanitize"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
|
|
|
|
// ─────────── Sinks ─────────────
|
2025-06-28 17:36:14 +02:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["eval"],
|
|
|
|
|
label: DataLabel::Sink(Cap::SHELL_ESCAPE),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["innerHTML"],
|
|
|
|
|
label: DataLabel::Sink(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
2026-02-25 04:02:11 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &[
|
|
|
|
|
"location.href",
|
|
|
|
|
"window.location.href",
|
|
|
|
|
"document.location.href",
|
|
|
|
|
],
|
|
|
|
|
label: DataLabel::Sink(Cap::URL_ENCODE),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &[
|
|
|
|
|
"child_process.exec",
|
|
|
|
|
"child_process.execSync",
|
|
|
|
|
"child_process.spawn",
|
|
|
|
|
],
|
|
|
|
|
label: DataLabel::Sink(Cap::SHELL_ESCAPE),
|
|
|
|
|
},
|
2025-06-28 17:36:14 +02:00
|
|
|
];
|
2026-02-24 23:44:07 -05:00
|
|
|
|
|
|
|
|
pub static KINDS: Map<&'static str, Kind> = phf_map! {
|
|
|
|
|
// control-flow
|
|
|
|
|
"if_statement" => Kind::If,
|
|
|
|
|
"while_statement" => Kind::While,
|
|
|
|
|
"for_statement" => Kind::For,
|
|
|
|
|
"for_in_statement" => Kind::For,
|
|
|
|
|
|
|
|
|
|
"return_statement" => Kind::Return,
|
2026-02-25 04:02:11 -05:00
|
|
|
"throw_statement" => Kind::Return,
|
2026-02-24 23:44:07 -05:00
|
|
|
"break_statement" => Kind::Break,
|
|
|
|
|
"continue_statement" => Kind::Continue,
|
|
|
|
|
|
|
|
|
|
// structure
|
|
|
|
|
"program" => Kind::SourceFile,
|
|
|
|
|
"statement_block" => Kind::Block,
|
|
|
|
|
"function_declaration" => Kind::Function,
|
|
|
|
|
"arrow_function" => Kind::Function,
|
|
|
|
|
"method_definition" => Kind::Function,
|
|
|
|
|
|
|
|
|
|
// data-flow
|
|
|
|
|
"call_expression" => Kind::CallFn,
|
|
|
|
|
"new_expression" => Kind::CallFn,
|
|
|
|
|
"assignment_expression" => Kind::Assignment,
|
|
|
|
|
"variable_declaration" => Kind::CallWrapper,
|
|
|
|
|
"lexical_declaration" => Kind::CallWrapper,
|
|
|
|
|
"expression_statement" => Kind::CallWrapper,
|
|
|
|
|
|
|
|
|
|
// trivia
|
|
|
|
|
"comment" => Kind::Trivia,
|
|
|
|
|
";" => Kind::Trivia, "," => Kind::Trivia,
|
|
|
|
|
"(" => Kind::Trivia, ")" => Kind::Trivia,
|
|
|
|
|
"{" => Kind::Trivia, "}" => Kind::Trivia,
|
|
|
|
|
"\n" => Kind::Trivia,
|
|
|
|
|
"import_statement" => Kind::Trivia,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub static PARAM_CONFIG: ParamConfig = ParamConfig {
|
|
|
|
|
params_field: "parameters",
|
|
|
|
|
param_node_kinds: &["identifier"],
|
|
|
|
|
self_param_kinds: &[],
|
|
|
|
|
ident_fields: &["name", "pattern"],
|
|
|
|
|
};
|