fix: cap stdin read at 1 MiB to prevent DoS - #3857
Merged
mnriem merged 2 commits intoAug 3, 2026
Merged
Conversation
Unbounded sys.stdin.read() allowed a malicious caller to exhaust memory by sending a multi-gigabyte payload. Cap at 1 MiB and raise typer.Exit if truncated.
Contributor
There was a problem hiding this comment.
Pull request overview
Caps stdin payloads for event commands to mitigate memory-exhaustion attacks.
Changes:
- Adds a nominal 1 MiB stdin limit.
- Rejects oversized payloads.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/commands/event.py |
Adds bounded stdin handling. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Balanced
- Rename _MAX_PAYLOAD to MAX_STDIN_BYTES (clearer constant naming) - Improve error message to suggest truncation or smaller payload - Better code formatting for readability Assisted-by: GitHub Copilot (model: mimo-v2-free, supervised)
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (3)
src/specify_cli/commands/event.py:30
- The normal native-hook path bypasses this cap: integrations invoke the generated
.specify/events.py, whose template still performs an unboundedsys.stdin.read()atsrc/specify_cli/events.py:300. As a result, the DoS remains reachable through the event hooks this feature installs. Apply the bounded read to the dispatcher template as well (ideally via shared logic) so both entry points enforce the limit.
raw = sys.stdin.read(MAX_STDIN_BYTES)
src/specify_cli/commands/event.py:35
- This branch cannot work with standard stdin streams:
TextIOBasehas noeofattribute, so every piped payload raisesAttributeError; additionally,typer.Exitaccepts an exit code but nomessageargument. Read one sentinel byte, compare its length, emit the message separately to stderr, and then exit.
if not sys.stdin.eof:
raise typer.Exit(
code=1,
message="stdin payload exceeds 1 MiB limit; "
"truncate or pipe a smaller payload",
src/specify_cli/commands/event.py:29
- There are no command-level tests for this new input boundary, which allowed both invalid APIs in the overflow path to go unnoticed. Add cases for payloads below, exactly at, and one byte above the limit, asserting forwarding versus a clean exit with the expected stderr message.
if not sys.stdin.isatty():
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Unbounded sys.stdin.read() allowed a malicious caller to exhaust memory by sending a multi-gigabyte payload. Cap at 1 MiB and raise typer.Exit if truncated.