Skip to content

Commit

Permalink
Allow suppressing preg_match_with_matches taints based on regex
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 25, 2024
1 parent f06eae7 commit 2a2bbea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/analyzer/expr/call/arguments_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use oxidized::ast_defs::ParamKind;
use oxidized::pos::Pos;
use oxidized::{aast, ast_defs};

use super::argument_analyzer;
use super::argument_analyzer::{self, get_removed_taints_in_comments};
use super::method_call_info::MethodCallInfo;

pub(crate) fn check_arguments_match(
Expand Down Expand Up @@ -1077,6 +1077,9 @@ fn handle_possibly_matching_inout_param(
)
) && argument_offset == 2
{
let removed_taints =
get_removed_taints_in_comments(statements_analyzer, all_args[0].1.pos());

let argument_node = DataFlowNode::get_for_method_argument(
functionlike_id.to_string(statements_analyzer.get_interner()),
0,
Expand Down Expand Up @@ -1112,7 +1115,7 @@ fn handle_possibly_matching_inout_param(
&out_node,
PathKind::Default,
vec![],
vec![],
removed_taints,
);
} else if matches!(
functionlike_id,
Expand Down
16 changes: 16 additions & 0 deletions tests/security/dontTaintThroughPregMatchWithIgnore/input.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function foo(): void {
$text = $_GET['bad'];
$matches = dict[];
if (
\preg_match_all_with_matches(
/* HAKANA_SECURITY_IGNORE[HtmlTag] */
'!<@([WU]+[0-9A-Z]+)!',
$text,
inout $matches,
)
) {
foreach ($matches[1] as $match) {
echo $match;
}
}
}

0 comments on commit 2a2bbea

Please sign in to comment.