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

chore(deps): update dependency starlette to ^0.27.0 [security] #219

Merged
merged 1 commit into from Jun 18, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented May 17, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
starlette (changelog) ^0.26.1 -> ^0.27.0 age adoption passing confidence

GitHub Vulnerability Alerts

CVE-2023-29159

Summary

When using StaticFiles, if there's a file or directory that starts with the same name as the StaticFiles directory, that file or directory is also exposed via StaticFiles which is a path traversal vulnerability.

Details

The root cause of this issue is the usage of os.path.commonprefix():
https://github.com/encode/starlette/blob/4bab981d9e870f6cee1bd4cd59b87ddaf355b2dc/starlette/staticfiles.py#L172-L174

As stated in the Python documentation (https://docs.python.org/3/library/os.path.html#os.path.commonprefix) this function returns the longest prefix common to paths.

When passing a path like /static/../static1.txt, os.path.commonprefix([full_path, directory]) returns ./static which is the common part of ./static1.txt and ./static, It refers to /static/../static1.txt because it is considered in the staticfiles directory. As a result, it becomes possible to view files that should not be open to the public.

The solution is to use os.path.commonpath as the Python documentation explains that os.path.commonprefix works a character at a time, it does not treat the arguments as paths.

PoC

In order to reproduce the issue, you need to create the following structure:

├── static
│   ├── index.html
├── static_disallow
│   ├── index.html
└── static1.txt

And run the Starlette app with:

import uvicorn
from starlette.applications import Starlette
from starlette.routing import Mount
from starlette.staticfiles import StaticFiles

routes = [
    Mount("/static", app=StaticFiles(directory="static", html=True), name="static"),
]

app = Starlette(routes=routes)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

And running the commands:

curl --path-as-is 'localhost:8000/static/../static_disallow/'
curl --path-as-is 'localhost:8000/static/../static1.txt'

The static1.txt and the directory static_disallow are exposed.

Impact

Confidentiality is breached: An attacker may obtain files that should not be open to the public.

Credits

Security researcher Masashi Yamane of LAC Co., Ltd reported this vulnerability to JPCERT/CC Vulnerability Coordination Group and they contacted us to coordinate a patch for the security issue.


Release Notes

encode/starlette

v0.27.0: Version 0.27.0

Compare Source

This release fixes a path traversal vulnerability in StaticFiles. You can view the full security advisory:
GHSA-v5gw-mw7f-84px

Added
Fixed
  • Replace commonprefix by commonpath on StaticFiles 1797de4.
  • Convert ImportErrors into ModuleNotFoundError #​2135.
  • Correct the RuntimeError message content in websockets #​2141.

Full Changelog: encode/starlette@0.26.1...0.27.0


Configuration

📅 Schedule: Branch creation - "" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@ghost
Copy link

ghost commented May 17, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@renovate renovate bot changed the title chore(deps): update dependency starlette to ^0.27.0 [security] chore(deps): update dependency starlette to ^0.28.0 [security] Jun 18, 2023
@renovate renovate bot force-pushed the renovate/pypi-starlette-vulnerability branch from 511662d to 99c59a4 Compare June 18, 2023 09:53
@renovate renovate bot changed the title chore(deps): update dependency starlette to ^0.28.0 [security] chore(deps): update dependency starlette to ^0.27.0 [security] Jun 18, 2023
@renovate renovate bot force-pushed the renovate/pypi-starlette-vulnerability branch from 99c59a4 to 8d8bd41 Compare June 18, 2023 12:21
@codeclimate
Copy link

codeclimate bot commented Jun 18, 2023

Code Climate has analyzed commit 8d8bd41 and detected 0 issues on this pull request.

View more on Code Climate.

@miketheman miketheman merged commit d452623 into main Jun 18, 2023
18 checks passed
@miketheman miketheman deleted the renovate/pypi-starlette-vulnerability branch June 18, 2023 16:26
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.

None yet

1 participant