Visitar URL original
Python: Aiohttp improvements by pwntester · Pull Request #13731 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20230714180701/https://github.com/github/codeql/pull/13731
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

Python: Aiohttp improvements #13731

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

pwntester
Copy link
Contributor

Few improvements for the aiohttp framework support:

  • New heuristic source for request handlers based on type hints
  • New Path Manipulation sink for FileResponse
  • New SSRF sink for ClientSession.ws_connect
  • Better recognition of the HTTP response's content type

Copy link
Member

@RasmusWL RasmusWL left a comment •

Choose a reason for hiding this comment

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

Overall looks good to me 👍

The one major thing about the addition of remote-flow-sources based off type-annotations is that we will introduce new shorter paths. In the example below, it's much more interesting to see the whole path starting at handler with a bad sanitizer, than seeing the path that only starts at the req parameter in foo. Would like to think a little about this aspect 🤔

@routes.post(...)
async def handler(request: aiotthp.web.Request):
    if request.host == "127.0.0.1":
        foo(request)

...

async def foo(req: aiohttp.web.Request):
    db.cursor().execute(await req.content.read())

Can you please add tests? I expect in these two files

  • python/ql/test/library-tests/frameworks/aiohttp/client_request.py
  • pyhton/ql/test/library-tests/frameworks/aiohttp/response_test.py
  • python/ql/test/library-tests/frameworks/aiohttp/taint_test.py (for the new remote-flow-source)

python/ql/lib/semmle/python/frameworks/Aiohttp.qll Outdated Show resolved Hide resolved
python/ql/lib/semmle/python/frameworks/Aiohttp.qll Outdated Show resolved Hide resolved
@RasmusWL RasmusWL changed the title [Python] Aiohttp improvements Python: Aiohttp improvements Jul 13, 2023
@RasmusWL
Copy link
Member

Actually, we should also add a test in python/ql/test/library-tests/frameworks/aiohttp/taint_test.py (for the new remote-flow-source)

pwntester and others added 2 commits July 13, 2023 12:23
Co-authored-by: Rasmus Wriedt Larsen <rasmuswriedtlarsen@gmail.com>
@pwntester pwntester requested a review from a team as a code owner July 13, 2023 10:24
@github-actions github-actions bot added the Go label Jul 13, 2023
@pwntester
Copy link
Contributor Author

Thanks @RasmusWL, I added the tests, but not sure how the inline tests expect. Can you please take a look?

@github-actions github-actions bot removed the Go label Jul 13, 2023
But notice that keyword argument is not handled yet
However, notice that the concepts tests use the HttpResponse location
for the `responseBody` tag, which seems a little odd in this situation,
where they are actually separate. Will fix in next commit.
RasmusWL
RasmusWL previously approved these changes Jul 13, 2023
Copy link
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

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

Great. I fixed up tests a bit (checking if we handle keyword arguments as well), and while I had the code checked out locally, I improved the modeling a little more as well.

Overall this LGTM, but let us just think a little more about the potential problem with what paths are shwon before merging. (will also run a performance test, just to be sure)

@pwntester
Copy link
Contributor Author

Thanks for fixing the tests @RasmusWL! As for the heuristic sources, in JS they have in a different file that you can enable to opt-in for more results. Perhaps thats a way to implement it until the subflow filtering is implemented

@RasmusWL
Copy link
Member

Thanks for fixing the tests @RasmusWL! As for the heuristic sources, in JS they have in a different file that you can enable to opt-in for more results. Perhaps thats a way to implement it until the subflow filtering is implemented

I think calling it a "heuristic sources" is not doing enough justice to what you're doing here. For me, a heuristic source would be something like: "we see that a parameter is called request, so it's probably an incoming HTTP request, and we'll model all attributes as tainted".

So I think 100% we should include the new sources, it's just a matter of question how to do it.

@RasmusWL
Copy link
Member

Evaluation was fine 👍

I've made a minor naming update to highlight that this is not a heuristic source, and changed the char-pred so it's not overlapping with AiohttpRequestHandlerRequestParam (makes reporting sources a little more accurate)

@RasmusWL RasmusWL removed the request for review from a team July 14, 2023 10:56
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.

None yet

2 participants