Skip to content

[Bug]: POST /p2p-draft-backup persists host_peer_id/snapshot_json unbounded (WS path bounds them) #2198

Description

@dearsishs

Description

The public POST /p2p-draft-backup HTTP endpoint validates only draft_code and then persists the client-supplied host_peer_id and snapshot_json to SQLite verbatim, echoing both back on GET /p2p-draft-backup/{code}. No size or shape bound is applied. The WebSocket lobby path already bounds the analogous host_peer_id to MAX_TOKEN_LEN (128 bytes, plus control-character rejection) via validate_token, so the same field is bounded on one transport and unbounded on the other.

Steps to reproduce

  1. Start a phase-server (or lobby-only) instance.
  2. POST /p2p-draft-backup with a valid 6-char draft_code, a host_peer_id longer than 128 bytes (and/or a multi-hundred-KB snapshot_json, and/or control characters).
  3. GET /p2p-draft-backup/{code}.

Expected behavior

The oversized/control-char host_peer_id is rejected with 400 Bad Request (matching the WS MAX_TOKEN_LEN bound), and snapshot_json is capped to a sane byte ceiling — before the DB write.

Actual behavior

The row is stored verbatim and echoed back to any caller; the only ceiling is axum's default ~2 MB body limit, and the same draft_code row can be overwritten repeatedly.

Impact

Untrusted client input is persisted and re-served without the size/shape bound its sibling WebSocket path already enforces — inconsistent validation across transports, control characters stored, and row-overwrite amplification.

Component

  • crates/phase-server/src/admin.rs (p2p_backup_store)
  • crates/phase-server/src/persistence.rs (save_p2p_backup)
  • crates/lobby-broker/src/validation.rs (validate_token / MAX_TOKEN_LEN — the WS bound this should match)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions