fix(auth): send explicit User-Agent from ResendClient so Cloudflare stops blocking magic-link emails#239
Merged
Conversation
api.resend.com sits behind Cloudflare, which blocks urllib's default
`Python-urllib/x.y` User-Agent with HTTP 403 ("error code: 1010")
before the request reaches Resend's API. Every magic-link sign-in
email was silently dropped in production as a result: Resend logged
zero send attempts and the API key showed zero uses, while wot-api
logged a bare `resend_send_exception: HTTP Error 403: Forbidden`.
Proven by two identical curl calls to api.resend.com differing only
in the User-Agent string: `Python-urllib/3.11` -> 403 "error code:
1010"; a normal UA -> 200 with a message id.
Changes:
- ResendClient sends an explicit `User-Agent: WorldOfTaxonomy/1.0`.
- HTTP 4xx/5xx is now caught as urllib.error.HTTPError and logged
with the response body, so an edge block ("error code: 1010") is
distinguishable from an API error (bad key / unverified domain).
- Adds TestResendClient: payload, User-Agent, and error-handling
regression coverage.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Magic-link sign-in emails have been silently dropped in production since the developer-auth feature shipped. The cause is not the email account, the API key, or DNS — it is the HTTP
User-Agent.api.resend.comsits behind Cloudflare.ResendClient.send()calls it with Python'surllib, which sends the defaultUser-Agent: Python-urllib/3.x. Cloudflare bot protection blocks that signature with HTTP 403 / "error code: 1010" before the request ever reaches Resend's API.Symptom
POST /api/v1/developers/signupreturns202and the UI shows "Check your inbox" (the endpoint deliberately never 500s on an email failure).resend_send_exception: HTTP Error 403: Forbidden— with no response body, so the real cause was invisible.Root cause — proven
Two identical
curlcalls toapi.resend.com/emails— same key, same IP, same TLS — differing only in theUser-Agent:Python-urllib/3.11HTTP 403—error code: 1010HTTP 200—{"id":"..."}(email delivered)The
200call delivered a real email to the account inbox, confirming the API key, the verifiedaixcelerator.aidomain, and thenoreply@aixcelerator.aisender all work. The block is entirelyUser-Agent-string based.Changes
world_of_taxonomy/auth/email.py—ResendClient:User-Agent: WorldOfTaxonomy/1.0header.urllib.error.HTTPErrorand logged with the response body (resend_send_failed: status=... body=...). The previous code logged a bareHTTP Error 403, hiding whether the cause was the API (bad key / unverified domain) or the Cloudflare edge. The oldif response.status >= 400branch was also dead code —urllibraisesHTTPErrorfor 4xx/5xx, it never returns them.tests/test_magic_link.py:TestResendClient— covers the request payload, theUser-Agentheader (regression guard: asserts it is set and is notpython-urllib), and the swallow-and-log behaviour on HTTP errors.Testing
TestResendClient(3 tests) — verified via a mockedurlopen, no network or key needed.curlsend with a normalUser-Agentdelivered to inbox — DKIM + SPF pass and align, clearing theaixcelerator.aip=rejectDMARC policy.Deployment context (already provisioned — no action in this PR)
On the
wot-apiCloud Run service:RESEND_API_KEY— GCP Secret ManagerRESEND_SENDER=noreply@aixcelerator.aiaixcelerator.aiverified in Resend (DKIM + SPF DNS records)Merging to
maintriggerswot-main-autodeploy, which builds and deploys wot-api. After deploy, a sign-in request on https://www.worldoftaxonomy.com/login should deliver the magic link.Risk
Low. Two-file change scoped to
ResendClient: one added request header plus improved error logging. No change to the sign-in flow, token handling, or any other code path.🤖 Generated with Claude Code