haven icon indicating copy to clipboard operation
haven copied to clipboard

Blossom: BUD-11 Base64url authorization tokens are rejected (PUT /upload answers 404 for valid clients)

Open dadofsambonzuki opened this issue 1 month ago • 0 comments

Summary

Blossom uploads fail for any client that follows the BUD-11 token encoding. haven's Blossom endpoints come from github.com/fiatjaf/khatru/blossom, whose readAuthorization decodes the Authorization token with Go's standard base64 decoder:

eventj, err := base64.StdEncoding.DecodeString(token[6:])

BUD-11 requires the token to be Base64url without padding ("MUST be encoded as Base64 URL-safe without padding (Base64url, as used by JWTs)"), so StdEncoding rejects it, and handleUpload reports that as a 404:

HTTP/2 404
x-reason: invalid "Authorization": invalid base64 token

Because the padding mismatch depends on the event JSON length (tokens whose length is not a multiple of 4), roughly two uploads in three fail while the rest succeed — it looks intermittent rather than broken.

Measured (haven v1.2.2, khatru v0.19.1, live relay)

Same signed kind 24242 event, same key, PUT /upload:

token encoding result
standard base64, padded (nak blossom) 403 only media signed by whitelisted pubkeys are allowed — token accepted, only the whitelist stopped it
Base64url, no padding (BUD-11; Armada, which signs via nostrify's N64.encodeEventUrl) 404 invalid "Authorization": invalid base64 token

Client-side this surfaces as PUT relay.day.ag/upload 404 (Not Found) in the browser console, which reads as a missing route — the endpoint is present and healthy. Related: khatru used to handle this with base64x and dropped it in f47282c7 ("get rid of base64x temporarily since it doesn't work on arm64"), which left nothing compensating for the padding.

Fix filed upstream

khatru's live home is now khatru/ inside nostrlib (GitHub fiatjaf/khatru is archived):

  • PR: nostr:nevent1qqs04fpvd5fn87w5604c7pdfycmt7j0lckvm5f3kdlerlne5udyd9wqpz3mhxue69uhkyctnwdcxjum5dakzummjvuv2h3fu — https://gitworkshop.dev/fiatjaf.com/relay.ngit.dev/nostrlib
  • commit 1: accept Base64url and standard base64, padded or unpadded, plus whitespace
  • commit 2: answer 401 (not 404/400) for a token that is present but invalid, per the BUD-02 and BUD-06 status tables

What haven can do

  • Bump github.com/fiatjaf/khatru once a release carries the fix, or take it into whatever haven v2 is based on.
  • Until then there is no haven-side fix without a replace directive. For reference, my relay runs a build of this tag with replace github.com/fiatjaf/khatru => ./khatru-0.19.1 (tolerant decoder only), verified end to end: uploads that previously answered 404 now return a blob descriptor and the stored bytes round-trip with a matching sha256.

dadofsambonzuki avatar Oct 15 '26 11:10 dadofsambonzuki