chore(deps): update dependency starlette to v0.40.0 [security] #162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^0.22.0
->^0.40.0
==0.25.0
->==0.40.0
GitHub Vulnerability Alerts
CVE-2023-30798
Impact
The
MultipartParser
using the packagepython-multipart
accepts an unlimited number of multipart parts (form fields or files).Processing too many parts results in high CPU usage and high memory usage, eventually leading to an OOM process kill.
This can be triggered by sending too many small form fields with no content, or too many empty files.
For this to take effect application code has to:
python-multipart
installed andrequest.form()
UploadFile
parameters, which in turn callsrequest.form()
.Patches
The vulnerability is solved in Starlette 0.25.0 by making the maximum fields and files customizable and with a sensible default (1000).
Applications will be secure by just upgrading their Starlette version to 0.25.0 (or FastAPI to 0.92.0).
If application code needs to customize the new max field and file number, there are new
request.form()
parameters (with the default values):max_files=1000
max_fields=1000
Workarounds
Applications that don't install
python-multipart
or that don't use form fields are safe.In older versions, it's also possible to instead of calling
request.form()
callrequest.stream()
and parse the form data in internal code.In most cases, the best solution is to upgrade the Starlette version.
References
This was reported in private by @das7pad via internal email. He also coordinated the fix across multiple frameworks and parsers.
The details about how
multipart/form-data
is structured and parsed are in the RFC 7578.CVE-2023-29159
Summary
When using
StaticFiles
, if there's a file or directory that starts with the same name as theStaticFiles
directory, that file or directory is also exposed viaStaticFiles
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 thatos.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:
And run the
Starlette
app with:And running the commands:
The
static1.txt
and the directorystatic_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.
CVE-2024-47874
Summary
Starlette treats
multipart/form-data
parts without afilename
as text form fields and buffers those in byte strings with no size limit. This allows an attacker to upload arbitrary large form fields and cause Starlette to both slow down significantly due to excessive memory allocations and copy operations, and also consume more and more memory until the server starts swapping and grinds to a halt, or the OS terminates the server process with an OOM error. Uploading multiple such requests in parallel may be enough to render a service practically unusable, even if reasonable request size limits are enforced by a reverse proxy in front of Starlette.PoC
curl http://localhost:8000 -F 'big=</dev/urandom'
Impact
This Denial of service (DoS) vulnerability affects all applications built with Starlette (or FastAPI) accepting form requests.
Release Notes
encode/starlette (starlette)
v0.40.0
: Version 0.40.0Compare Source
This release fixes a Denial of service (DoS) via
multipart/form-data
requests.You can view the full security advisory:
GHSA-f96h-pmfr-66vw
Fixed
max_part_size
toMultiPartParser
to limit the size of parts inmultipart/form-data
requests fd038f3.
v0.39.2
: Version 0.39.2Compare Source
Fixed
request.url_for
when only "app" scope is available #2672.python-multipart==0.0.12
#2708.Full Changelog: encode/starlette@0.39.1...0.39.2
v0.39.1
: Version 0.39.1Compare Source
Fixed
responses.py
andschemas.py
#2700.get_route_path
by removing regular expression usage #2701.FileResponse.chunk_size
when handling multiple ranges #2703.token_hex
for generating multipart boundary strings #2702.Full Changelog: encode/starlette@0.39.0...0.39.1
v0.39.0
: Version 0.39.0Compare Source
Added
FileResponse
#2697Full Changelog: encode/starlette@0.38.6...0.39.0
v0.38.6
: Version 0.38.6Compare Source
Fixed
MemoryObjectReceiveStream
inTestClient
#2693.Full Changelog: encode/starlette@0.38.5...0.38.6
v0.38.5
: Version 0.38.5Compare Source
Fixed
BackgroundTasks
from withinBaseHTTPMiddleware
#2688.This behavior was removed in 0.38.3, and is now restored.
Full Changelog: encode/starlette@0.38.4...0.38.5
v0.38.4
: Version 0.38.4Compare Source
Fixed
root_path
removal inget_route_path
function #2600Full Changelog: encode/starlette@0.38.3...0.38.4
v0.38.3
: Version 0.38.3Compare Source
Added
Fixed
BaseHTTPMiddleware
viaStreamingResponse
#2620.Full Changelog: encode/starlette@0.38.2...0.38.3
v0.38.2
: Version 0.38.2Compare Source
Fixed
routing.get_name()
not to assume all routines have__name__
#2648Full Changelog: encode/starlette@0.38.1...0.38.2
v0.38.1
: Version 0.38.1Compare Source
Removed
Full Changelog: encode/starlette@0.38.0...0.38.1
v0.38.0
: Version 0.38.0Compare Source
Added
memoryview
inStreamingResponse
andResponse
#2576and #2577.
StaticFiles
#2583.Changed
Jinja2Template
instantiation parameters #2568.Fixed
WebSocketTestSession
#2597.Full Changelog: encode/starlette@0.37.2...0.38.0
v0.37.2
: Version 0.37.2Compare Source
Added
bytes
to_RequestData
type #2510.Fixed
scope["client"]
toNone
onTestClient
(#2377)" #2525.app
argument passed tohttpx.Client
on theTestClient
#2526.Full Changelog: encode/starlette@0.37.1...0.37.2
v0.37.1
: Version 0.37.1Compare Source
Fixed
Config
#2485.Full Changelog: encode/starlette@0.37.0...0.37.1
v0.37.0
: Version 0.37.0Compare Source
Added
Full Changelog: encode/starlette@0.36.3...0.37.0
v0.36.3
: Version 0.36.3Compare Source
Fixed
anyio.Event
on async context #2459.Full Changelog: encode/starlette@0.36.2...0.36.3
v0.36.2
: Version 0.36.2Compare Source
Fixed
python-multipart
to0.0.7
13e5c26.Content-Type
#2443.Full Changelog: encode/starlette@0.36.1...0.36.2
v0.36.1
: Version 0.36.1Compare Source
Fixed
Full Changelog: encode/starlette@0.36.0...0.36.1
v0.36.0
: Version 0.36.0Compare Source
Added
pathsend
extension #2435.WebSocketTestSession
on close #2427.WebSocketDisconnect
whenWebSocket.send()
exceptsIOError
#2425.FileNotFoundError
when theenv_file
parameter onConfig
is not valid #2422.Full Changelog: encode/starlette@0.35.1...0.36.0
v0.35.1
: Version 0.35.1Compare Source
Fixed
FileResponse
inside ofStaticFiles
#2406.typing-extensions
optional again #2409.Full Changelog: encode/starlette@0.35.0...0.35.1
v0.35.0
: Version 0.35.0Compare Source
Added
*args
toMiddleware
and improve its type hints #2381.Fixed
Iterable
insteadIterator
oniterate_in_threadpool
#2362.Changes
root_path
to keep compatibility with mounted ASGI applications and WSGI #2400.scope["client"]
toNone
onTestClient
#2377.Full Changelog: encode/starlette@0.34.0...0.35.0
v0.34.0
: Version 0.34.0Compare Source
Added
ParamSpec
forrun_in_threadpool
#2375.UploadFile.__repr__
#2360.Fixed
TestClient
#2376.StaticFiles
#2334.Deprecated
FileResponse(method=...)
parameter #2366.Full Changelog: encode/starlette@0.33.0...0.34.0
v0.33.0
: Version 0.33.0Compare Source
Added
middleware
perRoute
/WebSocketRoute
#2349.middleware
perRouter
#2351.Fixed
"path"
and"root_path"
scope keys #2352.ensure_ascii=False
onjson.dumps()
forWebSocket.send_json()
#2341.v0.32.0
: Version 0.32.0Compare Source
Added
reason
onWebSocketDisconnect
#2309.domain
parameter toSessionMiddleware
#2280.Changed
HTMLResponse
instead ofResponse
on_TemplateResponse
#2274.Response.render
type annotation to its pre-0.31.0 state #2264.Full Changelog: encode/starlette@0.31.1...0.32.0
v0.31.1
: Version 0.31.1Compare Source
Fixed
exceptiongroup
isn't available #2231.url_for
global for custom Jinja environments #2230.Full Changelog: encode/starlette@0.31.0...0.31.1
v0.31.0
: Version 0.31.0Compare Source
Added
Fixed
TestClient
#2219.Full Changelog: encode/starlette@0.30.0...0.31.0
v0.30.0
: Version 0.30.0Compare Source
Removed
v0.29.0
: Version 0.29.0Compare Source
Added
follow_redirects
parameter toTestClient
#2207.__str__
toHTTPException
andWebSocketException
#2181.lifespan
together withon_startup
/on_shutdown
#2193.Host
to generate the OpenAPI schema #2183.request
argument toTemplateResponse
#2191.Fixed
body_stream
in casemore_body=False
onBaseHTTPMiddleware
#2194.Full Changelog: encode/starlette@0.28.0...0.29.0
v0.28.0
: Version 0.28.0Compare Source
Changed
Request
's body buffer for call_next inBaseHTTPMiddleware
#1692.Route
#2026.Added
env
parameter toJinja2Templates
, and deprecate**env_options
#2159.httpx
is not installed #2177.Fixed
templates url_for()
#2127.Full Changelog: encode/starlette@0.27.0...0.28.0
v0.27.0
: Version 0.27.0Compare Source
This release fixes a path traversal vulnerability in
StaticFiles
. You can view the full security advisory:GHSA-v5gw-mw7f-84px
Added
send_json
https://github.com/encode/starlette/pull/2128Fixed
commonprefix
bycommonpath
onStaticFiles
1797de4.Full Changelog: encode/starlette@0.26.1...0.27.0
v0.26.1
: Version 0.26.1Compare Source
Fixed
v0.26.0
: Version 0.26.0Compare Source
Added
Changed
url_for
signature to return aURL
instance #1385.Fixed
url_for()
andurl_path_for()
#2050.Deprecated
on_startup
andon_shutdown
events #2070.Full Changelog: encode/starlette@0.25.0...0.26.0
v0.25.0
: Version 0.25.0Compare Source
Fixed
multipart/form-data
on theMultipartParser
8c74c2c and #2036.v0.24.0
: Version 0.24.0Compare Source
Added
StaticFiles
to follow symlinks #1683.Request.form()
as a context manager #1903.size
attribute toUploadFile
#1405.env_prefix
argument toConfig
#1990.str
anddatetime
onexpires
parameter on theResponse.set_cookie
method #1908.Changed
file
argument required onUploadFile
#1413.Fixed
URL.replace
#1965.v0.23.1
: Version 0.23.1Compare Source
Fixed
body_stream
if body is empty on theBaseHTTPMiddleware
#1940.v0.23.0
: Version 0.23.0Compare Source
Added
headers
parameter to theTestClient
#1966.Deprecated
Starlette
andRouter
decorators #1897.Fixed
FloatConvertor
regex #1973.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 these updates again.
This PR was generated by Mend Renovate. View the repository job log.