Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
taint-mode: Check variables as if they were subexpressions (#4323)
If the LHS of `->foo` was a sink, and we encountered `x->foo` where `x` was a variable, we did not report a finding even if `x` was tainted. We were not checking whether `x` was in a sink position. Although they are not represented as such in the IL, variables are themselves subexpressions, so we must check whether they are sinks or sanitized. Closes #4320 test plan: make test # test included
- Loading branch information
Showing
4 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
// https://github.com/returntocorp/semgrep/issues/4320 | ||
$doc = new DOMDocument(); | ||
// We did not catch the error when the sink was the variable in an l-value, | ||
// because we assumed that only expressions or instructions could be sinks. | ||
//ERROR: | ||
$doc->load('file.xml'); | ||
//ERROR: | ||
$doc->load($doc); | ||
//OK: | ||
$something->load($doc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
rules: | ||
- id: domdocument-load | ||
severity: INFO | ||
message: DOMDocument::load | ||
languages: | ||
- php | ||
mode: taint | ||
pattern-sources: | ||
- patterns: | ||
- pattern: new DOMDocument(...) | ||
pattern-sinks: | ||
- patterns: | ||
- pattern-inside: $DOMDOCUMENT->load($FILENAME, ...) | ||
- pattern: $DOMDOCUMENT | ||
|