Static-streaming contract check — bound static-file RAM use (#178).
StaticFiles serves file bodies via FileResponse,
which streams from disk once a file reaches the configuredstream_threshold.
A threshold set to0or a negative value, or one set absurdly high, defeats
that protection: every static GET would read the whole file into memory, the
same unbounded-RAM DoS class as unbounded uploads.
Category:
static_streaming: aStaticFilesmiddleware is wired with a threshold that effectively disables chunked streaming.
This check is advisory and env-independent — it always emitsWARNING
(never ERROR), since a large threshold may be a deliberate choice for a
known-small asset directory.
Middleware presence is detected by class name (type(mw).__name__), not
isinstance, matching rules_security_stack— this avoids importing
StaticFilesinto the contracts layer and keeps the dependency direction
clean. The trade-off is that a user subclass is only recognised when it keeps
the same class name.
contracts.rules_static_streaming
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
check_static_streaming
function
def check_static_streaming(middleware_list: list[Any]) -> list[ContractIssue]
FlagStaticFilesmiddleware with a misconfigured stream threshold.
WARNING when the threshold is<= 0(chunked path unreachable; full file
always buffered) or>= 1 GiB(effectively unbounded). No issue when the
middleware is absent or configured with a sane threshold.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
middleware_list
|
list[Any]
|
— |
View source · /home/runner/work/chirp/chirp/site/../src/chirp/contracts/rules_static_streaming.py:1