2026-02-24 23:44:07 -05:00
|
|
|
use crate::labels::{Cap, DataLabel, Kind, LabelRule, ParamConfig};
|
|
|
|
|
use phf::{Map, phf_map};
|
|
|
|
|
|
|
|
|
|
pub static RULES: &[LabelRule] = &[
|
|
|
|
|
// ─────────── Sources ───────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["os.Getenv"],
|
|
|
|
|
label: DataLabel::Source(Cap::all()),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
2026-02-25 21:16:36 -05:00
|
|
|
matchers: &[
|
|
|
|
|
"http.Request",
|
|
|
|
|
"r.FormValue",
|
|
|
|
|
"r.URL",
|
|
|
|
|
"r.Body",
|
|
|
|
|
"r.Header",
|
|
|
|
|
"r.URL.Query",
|
|
|
|
|
"r.URL.Query.Get",
|
|
|
|
|
"Request.FormValue",
|
|
|
|
|
"Request.URL",
|
|
|
|
|
],
|
2026-02-24 23:44:07 -05:00
|
|
|
label: DataLabel::Source(Cap::all()),
|
|
|
|
|
},
|
|
|
|
|
// ───────── Sanitizers ──────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["html.EscapeString", "template.HTMLEscapeString"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
2026-02-25 21:16:36 -05:00
|
|
|
matchers: &["url.QueryEscape", "url.PathEscape"],
|
2026-02-24 23:44:07 -05:00
|
|
|
label: DataLabel::Sanitizer(Cap::URL_ENCODE),
|
|
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["filepath.Clean", "filepath.Base"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::FILE_IO),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
// ─────────── Sinks ─────────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["exec.Command"],
|
|
|
|
|
label: DataLabel::Sink(Cap::SHELL_ESCAPE),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
2026-02-25 21:16:36 -05:00
|
|
|
matchers: &["db.Query", "db.Exec", "db.QueryRow", "db.Prepare"],
|
2026-02-24 23:44:07 -05:00
|
|
|
label: DataLabel::Sink(Cap::SHELL_ESCAPE),
|
|
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["fmt.Fprintf", "fmt.Sprintf", "fmt.Printf"],
|
|
|
|
|
label: DataLabel::Sink(Cap::FMT_STRING),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &[
|
|
|
|
|
"os.Open",
|
|
|
|
|
"os.OpenFile",
|
|
|
|
|
"os.Create",
|
|
|
|
|
"ioutil.ReadFile",
|
|
|
|
|
"os.ReadFile",
|
|
|
|
|
],
|
|
|
|
|
label: DataLabel::Sink(Cap::FILE_IO),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["template.HTML"],
|
|
|
|
|
label: DataLabel::Sink(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
pub static KINDS: Map<&'static str, Kind> = phf_map! {
|
|
|
|
|
// control-flow
|
|
|
|
|
"if_statement" => Kind::If,
|
|
|
|
|
"for_statement" => Kind::For,
|
|
|
|
|
|
|
|
|
|
"return_statement" => Kind::Return,
|
|
|
|
|
"break_statement" => Kind::Break,
|
|
|
|
|
"continue_statement" => Kind::Continue,
|
|
|
|
|
|
|
|
|
|
// structure
|
|
|
|
|
"source_file" => Kind::SourceFile,
|
|
|
|
|
"block" => Kind::Block,
|
|
|
|
|
"statement_list" => Kind::Block,
|
|
|
|
|
"function_declaration" => Kind::Function,
|
|
|
|
|
"method_declaration" => Kind::Function,
|
2026-02-25 21:16:36 -05:00
|
|
|
"func_literal" => Kind::Function,
|
|
|
|
|
"expression_switch_statement" => Kind::Block,
|
|
|
|
|
"type_switch_statement" => Kind::Block,
|
|
|
|
|
"expression_case" => Kind::Block,
|
|
|
|
|
"type_case" => Kind::Block,
|
|
|
|
|
"default_case" => Kind::Block,
|
|
|
|
|
"select_statement" => Kind::Block,
|
|
|
|
|
"communication_case" => Kind::Block,
|
|
|
|
|
"go_statement" => Kind::Block,
|
|
|
|
|
"defer_statement" => Kind::Block,
|
2026-02-24 23:44:07 -05:00
|
|
|
|
|
|
|
|
// data-flow
|
|
|
|
|
"call_expression" => Kind::CallFn,
|
|
|
|
|
"assignment_statement" => Kind::Assignment,
|
|
|
|
|
"short_var_declaration" => Kind::CallWrapper,
|
|
|
|
|
"expression_statement" => Kind::CallWrapper,
|
|
|
|
|
"var_declaration" => Kind::CallWrapper,
|
|
|
|
|
|
|
|
|
|
// trivia
|
|
|
|
|
"comment" => Kind::Trivia,
|
|
|
|
|
";" => Kind::Trivia, "," => Kind::Trivia,
|
|
|
|
|
"(" => Kind::Trivia, ")" => Kind::Trivia,
|
|
|
|
|
"{" => Kind::Trivia, "}" => Kind::Trivia,
|
|
|
|
|
"\n" => Kind::Trivia,
|
|
|
|
|
"import_declaration" => Kind::Trivia,
|
|
|
|
|
"package_clause" => Kind::Trivia,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub static PARAM_CONFIG: ParamConfig = ParamConfig {
|
|
|
|
|
params_field: "parameters",
|
|
|
|
|
param_node_kinds: &["parameter_declaration"],
|
|
|
|
|
self_param_kinds: &[],
|
|
|
|
|
ident_fields: &["name"],
|
|
|
|
|
};
|