Skip to content

Commit 390aa97

Browse files
fix: bound fallback response read in preset download
Replace unbounded response.read() fallback in presets/_commands.py with read_response_limited() to prevent DoS via oversized preset archive downloads.
1 parent 0117a7b commit 390aa97

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/specify_cli/presets/_commands.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
from .._console import console
1919
from .._download_security import (
20+
MAX_DOWNLOAD_BYTES,
2021
is_https_or_localhost_http,
2122
is_safe_download_redirect,
23+
read_response_limited,
2224
)
2325

2426
preset_app = typer.Typer(
@@ -169,7 +171,9 @@ def _validate_download_redirect(old_url, new_url):
169171
try:
170172
shutil.copyfileobj(response, output)
171173
except TypeError:
172-
output.write(response.read())
174+
output.write(
175+
read_response_limited(response, max_bytes=MAX_DOWNLOAD_BYTES)
176+
)
173177
except urllib.error.URLError as e:
174178
console.print(f"[red]Error:[/red] Failed to download: {_escape_markup(str(e))}")
175179
raise typer.Exit(1)

0 commit comments

Comments
 (0)