Skip to content

Python: Fix attribute taint #7873

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
merged 3 commits into from
Feb 25, 2022
Merged

Python: Fix attribute taint #7873

merged 3 commits into from
Feb 25, 2022

Conversation

RasmusWL
Copy link
Member

@RasmusWL RasmusWL commented Feb 7, 2022

Fixes #7786

Draft PR so we can gauge what the impact of this change is before merging it (and look for failing QL tests 😅)

In `x.arg = TAINTED_STRING` there is a store step to the attribute `arg`
of `x`. In our taint modeling, we allow _any_ store step with the code
below. This means that we also say there is a taint-step directly from
`TAINTED_STRING` to `x` :|

```codeql
  // construction by literal
  // TODO: Not limiting the content argument here feels like a BIG hack, but we currently get nothing for free :|
  DataFlowPrivate::storeStep(nodeFrom, _, nodeTo)
```
@github-actions github-actions bot added the Python label Feb 7, 2022
@RasmusWL
Copy link
Member Author

RasmusWL commented Feb 8, 2022

Judging from the results from the internal experiment, I think this looks good 👍

@RasmusWL RasmusWL marked this pull request as ready for review February 8, 2022 11:04
@RasmusWL RasmusWL requested a review from a team as a code owner February 8, 2022 11:04
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

Basically looks fine. Is this removed alert an FP in this context?

@@ -49,7 +49,7 @@ def __exit__(self, exc_type, exc, tb):
def test_with_arg():
ctx = Context_arg(TAINTED_STRING)
with ctx as tainted:
ensure_tainted(tainted) # $ tainted
ensure_tainted(tainted) # $ MISSING: tainted
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually expected, I think, until we model __enter__.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed 👍

@RasmusWL
Copy link
Member Author

Basically looks fine. Is this removed alert an FP in this context?

yes, that's a FP. The current path is:

1: ControlFlowNode for cert_file

image

2: [post store] ControlFlowNode for self

image

3: ControlFlowNode for Attribute()

image

4: ControlFlowNode for Fstring

image

This PR means that we no longer treat the connection as tainted with a certificate, which seems like a good improvement 👍

1 similar comment
@RasmusWL
Copy link
Member Author

Basically looks fine. Is this removed alert an FP in this context?

yes, that's a FP. The current path is:

1: ControlFlowNode for cert_file

image

2: [post store] ControlFlowNode for self

image

3: ControlFlowNode for Attribute()

image

4: ControlFlowNode for Fstring

image

This PR means that we no longer treat the connection as tainted with a certificate, which seems like a good improvement 👍

@yoff
Copy link
Contributor

yoff commented Feb 25, 2022

Cool, thanks for showing the path.

Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

LGTM, always nice to see fixes like these.

@yoff yoff merged commit 8b926f6 into github:main Feb 25, 2022
@RasmusWL RasmusWL deleted the fix-attribute-taint branch February 25, 2022 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FastAPI Request: possible false positive
2 participants