Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't register taints for numeric variables #6813

Merged
merged 1 commit into from
Nov 4, 2021
Merged

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented Nov 3, 2021

this fixes #4872

I was pretty confused for a moment, I expected two fixes: get rid of the taint when passing through params, and when passing through a return type

However, as soon as I fixed the params one, both disappeared. I then realised that echo was treated as a function and it stopped registering taint given they were ints. I searched for sinks that are not functions (or treated as such by psalm) and couldn't find some. Maybe I'm mistaken on this.

Note also that this PR represent a subtle change in behaviour: declaring that a function takes an int as a param or gives int as a return type in phpdoc will now remove possible taints. It may be possible to do so only if the type does not come from docblock but it seemed more aligned with Psalm's policy to trust types even in docblock

@@ -38,7 +38,7 @@ public static function analyze(
$expr_type = $statements_analyzer->node_data->getType($expr);

if ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph) {
if ($expr_type) {
if ($expr_type && $expr_type->hasObjectType()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this was done to fix #3709 originally but this had the side-effect of turning any int into a numeric-string. I was not comfortable skipping taint analysis for a possible string, so I reduced the scope of this fix in order to retrieve the real int type later.

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 3, 2021
@orklah orklah merged commit cd74f66 into vimeo:master Nov 4, 2021
// numeric types can't be tainted
if ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
&& $input_type->isSingle()
&& ($input_type->isInt() || $input_type->isFloat())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for bool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, and there's surely more! We'll gladly accepts PRs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

taint analysis: auto escape for int type hints
3 participants