fix(security): cap message body length (LC-153) #188
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/lc-153-message-length-cap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Closes the missing message-length bound from the LC-148 audit (finding S9).
Problem
post_message,patch_message, andpost_thread_replychecked only that the trimmed body was non-empty - never an upper bound. A body up to Axum's default request cap (~2 MiB) was stored and broadcast to every room subscriber: an amplification vector.Fix
MAX_MESSAGE_CHARS = 16_000+ acheck_message_lengthhelper returning 400 before any DB write or broadcast. Counted in characters (not bytes) so multibyte CJK / emoji text isn't unfairly penalized. Applied to all three write paths (new message, edit, thread reply). 16k chars is generous for chat while killing the 2 MiB case.Test
message_over_length_cap_returns_400(16_001 chars -> 400) andmessage_at_length_cap_is_accepted(16_000 chars -> 200).just check/just test/just test-saasgreen (theroutes_uploadsflake is pre-existing; no upload code touched).Part of the LC-159 post-audit story.
🤖 Generated with Claude Code
Review follow-up: the web composer paths got the 16k-char cap but the bearer-token API endpoint (POST /api/v1/rooms/{id}/messages) still inserted an unbounded body after only the empty check, leaving the same amplification vector open via the API. Make check_message_length pub(crate) and call it there after the empty check. New test: a 16_001-char API post returns 400. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>