Skip to content

validate kv keys and handle request bodies after authentication - #329

Closed
LienThuan04 wants to merge 3 commits into
Phineas:mainfrom
LienThuan04:fix/kv-validation
Closed

LienThuan04 wants to merge 3 commits into
Phineas:mainfrom
LienThuan04:fix/kv-validation

Conversation

@LienThuan04

Copy link
Copy Markdown

Summary

Reject empty KV keys and authenticate PATCH/PUT KV writes before reading their bodies. Handle partial body reads without crashing, using an explicit 8,000,000-byte limit:

unauthorized request -> 401, without reading the body
authorized request  -> read body
  more than 8,000,000 bytes -> 413
  incomplete read / returned timeout -> 408
  other returned read error -> 400

Bandit's native transport exceptions keep their existing handling. Reading one byte beyond the limit distinguishes an oversized body from an incomplete read below the limit; Bandit can return :more for an HTTP/2 timeout as well as for size limits.

Evidence

  • Regression suite: mix test --no-start --warnings-as-errors — 29 tests pass. Before the final body-reader change, 8 cases failed, including small partial reads returning 413 instead of 408 and oversized complete reads reaching KV validation.
  • mix compile --warnings-as-errors passes in test and production environments with Elixir 1.19.
  • MIX_ENV=prod mix release passes in elixir:1.19-alpine.
  • mix format --check-formatted passes for the complete tree in a temporary LF-normalized copy, and directly for every changed Elixir file.
  • A real Bandit HTTP/2 connection with an unfinished 2-byte PATCH body returns 408 request_timeout.

Tests use production routing, KV validation and presence updates, with a test Redis process and controlled Plug body-read results. --no-start avoids starting the Discord bot or requiring external Redis credentials.

Merge Danger

Door: two-way

Blast Radius: KV

Previously accepted empty keys are rejected on writes. Existing stored data is preserved, and the existing KV validation response codes are retained.

@pxseu

pxseu commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Hi,
Thank you for your Pull Request.

Lanyard is designed to run behind a reverse proxy, so H2 will get terminated at the edge and Lanyard itself only does HTTP/1.1 that being said, we also do not support at this time any certs to be used by Lanyard so this would not work in the real word anyway.

@pxseu pxseu closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants