SIGN IN SIGN UP

AUTH-9041 Generate ephemeral keypair for login token transfer

## Problem

`NewEncrypter` loaded the token transfer keypair from `cloudflared_priv.pem` and `cloudflared_pub.pem` in the current working directory, generating and persisting them only when absent. An attacker who could place those files in a directory a user later ran cloudflared from — a repository checkout, an extracted archive, a shared or world-writable directory — knew the resulting public key in advance.

That public key is sent to the edge as the token transfer capability, and the transfer service treats it as a bearer address with no identity binding. Knowing it ahead of time let an attacker poll for the victim's credential: the account-scoped API token written to `cert.pem` by `tunnel login`, or the application JWT from `access login`. The victim's login still succeeded, so the theft left no visible trace.

## Fix

Always derive the keypair from `box.GenerateKey` and never read or write it to disk. The on-disk path is removed entirely, along with the filesystem imports, so restoring it would require a visible import change in review. `NewEncrypter` no longer takes filename arguments — note this is a change to an exported signature, though the only in-tree caller is `RunTransfer`.

Also reject payloads shorter than the 24-byte nonce in `Decrypt`, which previously panicked on a slice out of range. The smallest valid payload is 40 bytes, so the guard cannot reject legitimate input.

Jira: AUTH-9041 VULN-141861
E
Eduardo Gomes committed
5dcadf1aeaf63877cdf152fbd521d2597b79db5d
Parent: 61a0b0b
Committed by João "Pisco" Fernandes <joaocarlos@cloudflare.com> on 8/12/2026, 10:56:02 AM