Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better handling of IfExp (ternary) #179

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

Merged
bcaller merged 1 commit into python-security:master from bcaller:ifexp
Oct 30, 2018
Merged

Conversation

@bcaller
Copy link
Collaborator

@bcaller bcaller commented Oct 29, 2018

Reduces false positives.

As an example:

result = "a" if TAINT else "c"

In AST, the assignment value is IfExp(test=TAINT, body="a", orelse="c").

Even though TAINT is inside the assignment of result, it can't
actually taint result as it is part of the boolean test expression.

Previously, result would have been tainted, which was a false
positive.

We don't want to completely ignore the test though in case it contains a
sink function.

Therefore, if the test contains expressions we transform it as so:

result = "a" if b(c) + 2 else "d"

to the multi line:

__if_exp_0 = b(c) + 2
result = "a" if __if_exp_0 else "d"

This way if b is a sink and c is tainted we see a vulnerability, but
even if c is tainted we don't taint result.

KevinHock reacted with thumbs up emoji KevinHock reacted with hooray emoji KevinHock reacted with heart emoji
Reduces false positives.
As an example:
result = "a" if TAINT else "c"
In AST, the assignment value is `IfExp(test=TAINT, body="a", orelse="c")`.
Even though `TAINT` is inside the assignment of `result`, it can't
actually taint `result` as it is part of the boolean test expression.
Previously, `result` would have been tainted, which was a false
positive.
We don't want to completely ignore the test though in case it contains a
sink function.
Therefore, if the test contains expressions we transform it as so:
result = "a" if b(c) + 2 else "d"
to the multi line:
__if_exp_0 = b(c) + 2
result = "a" if __if_exp_0 else "d"
This way if `b` is a sink and `c` is tainted we see a vulnerability, but
even if `c` is tainted we don't taint `result`.
Copy link
Collaborator

@KevinHock KevinHock left a comment

Choose a reason for hiding this comment

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

Beautiful :D

@bcaller bcaller merged commit 0932cc9 into python-security:master Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@KevinHock KevinHock KevinHock approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /