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

list is tainted by calling list.append(TAINT) #181

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

bcaller
Copy link
Collaborator

@bcaller bcaller commented Oct 31, 2018

Taint is propagated by:

list += [TAINT]
list = list + TAINT

but with lists we often use a function to mutate the list:

list = []
list.append(TAINT)
list.insert(0, TAINT)
list.extend(TAINT)

Previously this didn't taint list so we had FALSE NEGATIVES.

Now list.append(TAINT) is treated like augmented assignment, so list
will be tainted.

list += list.append(TAINT)

Of course this wouldn't work as real code since append returns None
but it is how you can think about this function which mutates list.

The same goes for set.add(), list.extend(), list.insert(),
dict.update(), although we aren't actually doing type checking, just
looking at the name of the method.

@KevinHock KevinHock self-requested a review October 31, 2018 18:19
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.

This is really great :D

@@ -578,6 +580,23 @@ def visit_Call(self, node):
else:
raise Exception('Definition was neither FunctionDef or ' +
'ClassDef, cannot add the function ')
elif (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lovely elif

pyt/vulnerability_definitions/blackbox_mapping.json Outdated Show resolved Hide resolved
Taint is propagated by:

```
list += [TAINT]
list = list + TAINT
```

but with lists we often use a function to mutate the list:

```
list = []
list.append(TAINT)
list.insert(0, TAINT)
list.extend(TAINT)
```

Previously this didn't taint `list` so we had FALSE NEGATIVES.

Now `list.append(TAINT)` is treated like augmented assignment, so list
will be tainted.

`list += list.append(TAINT)`

Of course this wouldn't work as real code since `append` returns `None`
but it is how you can think about this function which mutates `list`.

The same goes for `set.add()`, `list.extend()`, `list.insert()`,
`dict.update()`, although we aren't actually doing type checking, just
looking at the name of the method.
@bcaller bcaller force-pushed the appendaddextendinsert branch from 72682a0 to 7847d01 Compare November 1, 2018 14:57
@bcaller bcaller merged commit 79d39d8 into python-security:master Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants