Finds patterns – syntactic constructs of interest (e.g., system(),
eval(parse()), an outbound HTTP call).
Arguments
- tree
The
xml_documentparse tree for one script (fromparse_code()).- pattern_rules
Data frame of pattern rules (
rules$patternsfromload_rules()), with columnsname,xpath,message, andattck.- file_context
Package-root-relative path of the script, carried through for joining to the file-contexts table.
Value
A list with two data frames:
- patterns
Data frame with columns
rule(the matching rule's name),file_context,line_number,column_number,message,attck. Carries a"nodes"attribute holding the matched nodes aligned to the rows. The phase columns are not set here;audit_package()attaches them from the code context each pattern is assigned.- errors
Data frame with columns
step,file_context,rule,message.
Details
Each rule's XPath is evaluated with .xml_find_all_safe(), so an invalid one
– including one libxml2 reports only as a warning – is recorded in errors
and the scan moves on.
The "nodes" attribute holds the matched XML nodes aligned row-for-row, so
determine_code_contexts() can test containment by node identity without
re-running the pattern XPaths.