Skip to content

Add signed URLs - #23

Merged
FlorianKoerner merged 3 commits into
4.xfrom
feat/signed-urls
Nov 21, 2026
Merged

FlorianKoerner merged 3 commits into
4.xfrom
feat/signed-urls

Conversation

@FlorianKoerner

@FlorianKoerner FlorianKoerner commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #22.

Self-hosted instances are usually public, so anyone who finds the URL can render avatars on them. With SIGNING_SECRETS set, the avatar endpoints only answer URLs that the operator's own backend signed. Without the variable nothing changes.

How it works:

  • sig is the HMAC-SHA256 of the path and options, hex encoded, and always the last parameter. Unsigned or wrongly signed requests get a 403 with Cache-Control: no-store.
  • With options in the query string, the URL is checked exactly as it arrives, so every signed URL has one valid spelling.
  • With options in the path, as Gravatar needs them, sig and exp live in that path segment and the signature covers the decoded segment. It does not matter how a client encodes it.
  • exp is optional, a Unix timestamp in seconds. Expired URLs get a 403, and max-age is capped at the time that remains. A malformed or repeated exp gets Invalid expiry.
  • SIGNING_SECRETS accepts several comma-separated secrets for key rotation. Each one needs at least 32 characters, or the API refuses to start.
  • The health check, the style listing and the metadata endpoints stay open.

The docs are in dicebear/dicebear#574.

With SIGNING_SECRETS set, the avatar endpoints only answer URLs that end in a
valid sig parameter, the HMAC-SHA256 of the path and options in front of it.
URLs that carry their options in the path keep sig and exp in that segment, so
signed URLs also work as a Gravatar default image. An optional exp parameter
sets an expiry and caps Cache-Control at it. Every secret needs at least 32
characters.

Closes #22
- Refuse a URL with a raw `#`. The router ends the URL there, so it read
  fewer options than the signature covered.
- Refuse to start when SIGNING_SECRETS is set but holds no secret, instead
  of running without signatures.
- Answer a query string next to path options with its own message instead
  of "Invalid signature."
- Document that a secret cannot contain a comma or surrounding whitespace.
- Clear SIGNING_SECRETS for the whole test run, so a value exported in the
  shell does not fail the other suites.
Refusing to start was too strict for setups that pass the variable
through empty, such as a compose file with a default.
@FlorianKoerner
FlorianKoerner merged commit b2eb9e5 into 4.x Nov 21, 2026
3 checks passed
@FlorianKoerner
FlorianKoerner deleted the feat/signed-urls branch November 21, 2026 10:09
FlorianKoerner added a commit to dicebear/dicebear that referenced this pull request Nov 21, 2026
Adds a section on signed URLs to the self-hosting page: SIGNING_SECRETS, signing examples in seven languages, the path variant for Gravatar, exp and key rotation. The feature was added in dicebear/api#23.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Signed URL support

1 participant