Skip to content

fix(udp-core): inject the UDP connection-cookie cipher #2458

Closed

Description

@josecelano

Goal

Replace the process-global, cfg(test)-switched UDP connection-cookie cipher with one cryptographically random key created at startup and injected into every cookie issuer and validator. The fixed all-zero test key must be unreachable from production builds.

Problem

BEP 15 connection IDs prevent clients from issuing announce or scrape requests for an address they do not control. The tracker protects its eight-byte cookie by encrypting it with Blowfish, so the confidentiality of that cipher key is essential.

Today, udp-core has independent static random seed and cipher values, plus an all-zero test cipher. Compile-time aliases select the zero cipher for unit tests and the random cipher for production. Startup calls check_seed() to detect an accidental production test configuration, but that function compares only the unused random seed, not the cipher that encrypts cookies. Production initialization also initializes the zero cipher.

The current production alias is correct, so no bad cookie behavior is currently observed. However, a one-line alias regression makes production encrypt with the public all-zero key while check_seed() still passes. An attacker can then forge valid cookies for a chosen fingerprint and issue time.

Reproduction

A reversible local production-mode alias mutation selected ZEROED_TEST_CIPHER_BLOWFISH. The tracker then started normally, including HTTP and management API listeners; check_seed() did not panic. An independent executable encrypted documented cookie plaintext with BlowfishLE::new_from_slice(&[0_u8; 32]), constructed a protocol connection ID, and production check accepted it:

forged cookie accepted for issue time 1728000000

The full commands, toolchain, tracker startup logs, and restoration details are in the issue-local manual-verification-evidence.md artifact that will accompany the specification.

Scope

  • Introduce a cookie-cipher key type with a cryptographically secure production constructor, an explicit test-only fixed-key constructor, and redacted Debug.
  • Pass that key explicitly to cookie make and check, and through udp-core, udp-server, and all remaining production callers.
  • Construct exactly one shared key at the composition root; no consumer may construct an independent key.
  • Exclude the key from tracing spans.
  • Remove the global key facades, cfg aliases, zero and random statics, startup seed check, and stale documentation unless a surviving consumer is justified.
  • Add an ADR documenting the dependency-injection decision and its alternatives.

The cookie format, Blowfish algorithm, fingerprint/time arithmetic, inter-process key sharing, rotation, and key zeroization are out of scope.

Acceptance Criteria

  • No production path can use a key other than the one cryptographically generated at startup; the test key cannot be referenced in a production build.
  • All cookie issuers and validators use one shared key instance.
  • Key material is absent from Debug output and tracing spans.
  • Existing cookie behavior and encoding remain unchanged for an explicit fixed test key.
  • Focused regression, collaboration, documentation, lint, and manual verification evidence pass.

Verification

The regression suite will prove the production constructor differs from the fixed key, a production build cannot access the test constructor, components in one container share a key, and debug output is redacted. Existing cookie round-trip and pinned-encoding tests will run with an explicit fixed key. The initial reproduction will be repeated after the change to show that all-zero-key production wiring is no longer expressible or accepted.

Activity

  1. added
    Bug
    on Oct 6, 2026
  2. 128 remaining items

  3. added 5 commits that reference this issue on Oct 7, 2026
  4. added 9 commits that reference this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions