sculk.network
Nightly Stable docs
OAuthMCnightly · 39a95aaView in Stable docs

Security model

This document explains the threats OAuthMC defends against, the responsibilities of the calling platform, and the trade-offs baked into the protocol.

Why join alone never verifies an account#

Joining a Minecraft server in online mode proves which Mojang account connected. It does not prove which account on the platform started the verification. Because anyone can open a ticket for any Minecraft username, OAuthMC never marks a player verified on join alone.

A naive "auto-verify on join" design fails in three ways:

  1. Ticket hijacking: an attacker opens a ticket for victim V and waits until V joins to verify their own account. Both open tickets observe V's join.
  2. Phishing: even with exclusive: true or per-ticket hostnames, an attacker can trick V into joining a server address ("join verify.example.com for an event"). Joining a server does not look like handing over a credential.
  3. Username squatting: with exclusive: true, an attacker can keep opening tickets for V to block V from verifying their own account.

In both code mode and link mode, OAuthMC generates an 8-character secret (XXXX-XXXX, drawn from an unambiguous 30-character alphabet, ~39.2 bits of entropy) using rejection sampling over OS randomness. OAuthMC sends the secret over the AES-128-CFB8 encrypted Minecraft connection after Mojang hasJoined succeeds. Only the player who owns the Minecraft account receives it, and verification completes only when the platform redeems that code through POST /v1/tickets/{id}/redeem.

  • exclusive defaults to false so attackers cannot block other players from starting verification.
  • On join, OAuthMC hashes the fresh code with SHA-256 and stores the hash on every open ticket for that username (only when Mojang's canonical username matches the login username ASCII case-insensitively). Rejoining replaces the hash without resetting attempts.
  • GET /v1/tickets/{id} never returns the Mojang UUID, the code, or a filled link_url. The UUID is returned once, on a successful redeem.
  • Redeeming consumes the ticket (status: "redeemed"). Wrong codes decrement attempts_left and lock the ticket at 0.

In link mode, OAuthMC substitutes {ticket} and {code} into link_url and displays an Open link button in Minecraft's Configuration dialog. When the player clicks it, Minecraft shows its built-in confirmation prompt and opens the URL in the player's browser.

Link mode is safe only if the platform enforces all three rules on the verification page:

  1. Check session ownership before redeeming. Verify that the authenticated browser session belongs to the user who created {ticket}. If an attacker A creates a link-mode ticket for victim V and tricks V into joining and clicking Open link, V's browser carries V's session (or no session), not A's. Reject the request and never call /redeem on A's ticket.
  2. Never redeem on GET. Render a confirmation page that shows which Minecraft username is being linked to which platform account, and redeem only on an explicit POST action protected by the platform's normal session and CSRF checks.
  3. Keep {ticket} and {code} out of server logs and Referer headers. Put both placeholders in the URL fragment (https://example.com/verify#ticket={ticket}&code={code}), strip the fragment with history.replaceState after reading it in JavaScript, and send Referrer-Policy: no-referrer on the page. Always use https:// in production (OAUTHMC_ALLOW_HTTP_LINKS defaults to false).

See Integrating OAuthMC for the full pattern.

Multi-tenant mode and message isolation#

Each key in OAUTHMC_API_KEYS is an isolated tenant. API reads, redeems, and deletes are strictly scoped to the owning key.

On the Minecraft port, a username may have open tickets from more than one tenant at the same time. OAuthMC applies link mode and per-ticket messages overrides only when every open ticket for the joining username belongs to the same tenant (and, for link mode, the newest open ticket uses link mode). If two tenants both have open tickets for the same username, OAuthMC ignores per-ticket overrides and forces code mode with server templates. One tenant cannot inject clickable URLs or phishing text into another tenant's verification flow, while every tenant's open ticket can still redeem the code.

Pre-encryption rejection trade-off#

When a client sends Login Start for a username with no open ticket, OAuthMC sends Login Disconnect immediately before Encryption Request.

  • Benefit: port scanners and unsolicited connections cost zero RSA decryptions and zero Mojang hasJoined requests.
  • Trade-off: anyone can probe whether a specific Minecraft username has an open ticket right now.

If your platform treats an in-flight verification attempt as sensitive, account for this disclosure in your own ticket-creation rate limits and UX.

Rate limiting and why there is no per-name limit#

After confirming an open ticket exists and before sending Encryption Request, OAuthMC checks a per-IP token bucket (OAUTHMC_AUTH_RATE_PER_MINUTE, default 6; OAUTHMC_AUTH_BURST, default 3). IPv4 peers are bucketed by /32 and IPv6 peers by /64, with IPv4-mapped IPv6 addresses (::ffff:a.b.c.d) folded back to IPv4 /32. Requests over the limit are kicked before encryption with the rate_limited message.

Outgoing Mojang hasJoined calls are also capped globally (OAUTHMC_MAX_SESSION_CALLS, default 32). Excess logins are kicked with rate_limited.

OAuthMC does not enforce a per-username login rate limit. A per-name limit would let an unauthenticated attacker flood Login Start packets for a victim's username and block the victim from verifying. Bounding abuse per source IP bucket and capping global hasJoined concurrency protects CPU and Mojang quota without creating a per-player denial-of-service vector.

Cryptography and protocol hardening#

  • RSA-1024 PKCS#1 v1.5: generated fresh at startup from OS randomness (getrandom). OAuthMC pins rsa = 0.10.0, which uses constant-time implicit rejection for PKCS#1 v1.5 decryption (mitigating Marvin / RUSTSEC-2023-0071). Any decryption or framing error closes the connection identically with no error oracle and zero Mojang calls.
  • Verify token: 4 random bytes per Encryption Request, compared in constant time on Encryption Response.
  • Minecraft 1.19 and 1.19.2 (hasToken = false): protocols 759 and 760 allow clients with a Mojang profile public key to send a salt and signature instead of the encrypted verify token. OAuthMC accepts hasToken = false without verifying the signature. This remains safe because:
    1. The decrypted 16-byte shared secret is hashed with the server's RSA public key into Mojang's hasJoined serverId, so only a client holding the account's Mojang session token makes hasJoined return 200.
    2. The code is sent in the encrypted Login Disconnect packet under that shared secret, so replaying an encrypted secret only produces ciphertext an attacker cannot decrypt.
  • Mojang hasJoined over TLS: uses rustls with ring and embedded webpki-roots (no host CA bundle needed in distroless/static). Responses are capped at 64 KiB with a 5-second default timeout and zero redirects. Mojang's returned canonical username must match the login username (ASCII case-insensitively), or OAuthMC kicks with unverified and mutates no ticket. Plain http:// is used only when OAUTHMC_SESSION_URL is explicitly overridden for local tests.
  • No secrets in logs: OAuthMC never logs verification codes, filled verification links, API keys, RSA private keys, or shared secrets.

API and resource protection#

  • Bearer keys must be at least 32 characters and are checked across every configured key in constant time.
  • HTTP request bodies are capped at 16 KiB (413 body_too_large), metadata at 1024 bytes, and link_url at 512 bytes. link_url is validated after substituting {ticket} and {code} to enforce https:// (unless OAUTHMC_ALLOW_HTTP_LINKS=1), a valid host without userinfo, and RFC 3986 URI characters only.
  • HTTP connections enforce header timeout (OAUTHMC_API_HEADER_TIMEOUT_SECONDS, default 10 s), body timeout (OAUTHMC_API_BODY_TIMEOUT_SECONDS, default 10 s), and concurrency cap (OAUTHMC_MAX_API_CONNECTIONS, default 256) to mitigate slowloris attacks.
  • Ticket storage is capped globally (OAUTHMC_MAX_TICKETS, default 10000) and per key (OAUTHMC_MAX_TICKETS_PER_KEY, default 1000), counting expired tickets still inside their grace period. At capacity, POST /v1/tickets returns 503 ticket_limit.
  • Minecraft connections enforce OAUTHMC_MAX_PACKET_LEN (4096 bytes during Handshake/Login; Configuration streams and discards non-Keep-Alive packets up to 1 MiB without buffering), OAUTHMC_MAX_HANDSHAKE_ADDR_LEN (255 bytes), OAUTHMC_LOGIN_TIMEOUT_SECONDS (10 s), OAUTHMC_MAX_CONNECTIONS (256), and OAUTHMC_MAX_CONNECTIONS_PER_IP (16).
  • Held link-mode DoS controls: held sessions stay open for up to OAUTHMC_LINK_HOLD_SECONDS (default 600 s, capped by ticket TTL). Four controls keep them from starving code-mode logins or status pings:
    1. OAUTHMC_MAX_HELD defaults to half of OAUTHMC_MAX_CONNECTIONS (128), and startup rejects any value >= OAUTHMC_MAX_CONNECTIONS. Excess link-mode joins fall back to a code-mode disconnect.
    2. OAUTHMC_MAX_HELD_PER_IP (default 2 per /32 or /64) caps held connections per IP bucket and falls back to code mode above the cap.
    3. At most one held connection is kept per ticket. Rejoining disconnects the older held connection immediately with replaced (omitting {code} and {link}).
    4. Redeeming (verified), locking (locked, omitting {code} and {link}), expiring or deleting (expired), or missing a Configuration Keep Alive for 30 seconds disconnects immediately and releases all slots.

Always bind OAUTHMC_API_ADDR to loopback or a private container network. Never expose the HTTP API to the public internet.