Harden bot submission: RESULT size cap, NSE_HASHES limits, atomic file write#154
Open
t0kubetsu wants to merge 1 commit into
Open
Harden bot submission: RESULT size cap, NSE_HASHES limits, atomic file write#154t0kubetsu wants to merge 1 commit into
t0kubetsu wants to merge 1 commit into
Conversation
…e write Fixes D4-project#141. Add validate.Length(max=50MB) to RESULT field and per-key/value length limits plus a 50-entry cap to NSE_HASHES in BotInfoSchema. Add MAX_CONTENT_LENGTH=64MB to config.py.template. Reorder sndjob so the result file is written before ORM state is mutated; wrap in try/except so a write failure returns 500 and does not permanently mark the job finished.
This was referenced Jun 2, 2026
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.
Summary
Fixes #141. Two critical issues in
/bot_api/sndjob.Changes
1. Unbounded RESULT payload (DoS/disk exhaustion)
RESULThad novalidate=Length(max=...). Flask had noMAX_CONTENT_LENGTH. A single authenticated agent could submit a multi-GB JSON string.validate.Length(max=50 * 1024 * 1024)toRESULTvalidate.Length(max=50)and per-key/value length limits toNSE_HASHESMAX_CONTENT_LENGTH = 64 * 1024 * 1024toconfig.py.template2. Job marked finished before file write (data loss)
job_bot.finished = Truewas set beforeopen(base, "w"). Any write failure (disk full, malformed JSON, OSError) left the job permanently marked finished with no data file. The idempotent resubmit guard then returned 200 on agent retry without re-writing — scan results permanently lost.Fix: write the file first; only mutate ORM state after the write succeeds. Wrap the write in
try/except (OSError, json.JSONDecodeError)withdb.session.rollback()on failure.Test plan