Repository navigation
fix(download): bound in-memory download registry and gate tokens when disabled - #122
Merged
Merged
Conversation
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.
Pull Request Template
Description
Bound the in-memory download registry so token storage can no longer grow without limit, stop loading export files into memory before their size is validated, and never issue download tokens while downloads are disabled.
download.max_tokens, default 100, anddownload.max_total_bytes, default 1 GiB) and committed only after the read succeeds; failures release the reservation. There is no eviction of live tokens — when a budget is exhausted the export still completes on disk, the response returns200withdownload_token: null, and the rejection is logged.stat().st_sizeis checked beforeread_bytes()(no more loading an oversized file to reject it afterwards), plus a defensive re-check after the read (TOCTOU).generate_download_tokenand the scrape batch helper short-circuit with no token whiledownload.enabled=false(log INFO / DEBUG respectively).docs/CONFIGURATION.md(JSON, reference table, new section) and.env.example(CIBERWEBSCAN_DOWNLOAD_MAX_TOKENS,CIBERWEBSCAN_DOWNLOAD_MAX_TOTAL_BYTES);download_token: nullresponses documented indocs/API.md(plus two obsolete env var names corrected there).Verification: 11 new regression tests (registry budget ×9, disabled helper, disabled batch); full suite 1896 passed / 3 skipped; end-to-end against the real API 21/21 checks across 3 scenarios (disabled, byte budget, token cap); Ruff, Pyright and all pre-commit hooks pass.
Related Issue
N/A (no public issue; tracked internally)
Type of Change
Checklist
Screenshots (if applicable)
N/A (backend/API changes)