Repository navigation
Add server-to-server subscription status check (STATUS_KEY) - #3
Merged
Merged
Conversation
…t from form keys
POST /subscribe/status is for the web-app's own server. It authenticates with STATUS_KEY,
refuses form keys (they must not reveal who subscribes), and answers only { subscribed }
for one address and one configured list.
Co-authored-by: Nilsson <wachtelhund@users.noreply.github.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.
Fredrik approved a status lookup for the web-app (srcfl/web-app.sourceful.energy on Vercel) so
/api/newsletterGET can show whether the signed-in user is on a list such asapp-users. Two hard conditions are in the code:STATUS_KEY. A form key is refused (401 form_key_not_allowed), even ifSTATUS_KEYwas accidentally set to the same value. Form keys stay forPOST /subscribeandPOST /unsubscribeonly.{ "subscribed": true }or{ "subscribed": false }. No name, consent, source, or suppression reason.falsecovers never signed up, left, and bounced.Endpoint contract (for the web-app)
POST(GET is405: an address in the URL would land in access logs)https://news.sourceful.energy/subscribe/statusAuthorization: Bearer <STATUS_KEY>application/json(2 KB max){ "email": "<logged-in user only>", "list": "app-users" }200 { "subscribed": true | false }withCache-Control: no-storeErrors:
key_required,invalid_key,form_key_not_allowed,invalid_email,invalid_list,invalid_body,too_large,unsupported_media_type,rate_limited(Retry-After: 60),status_unavailable,method_not_allowed.Env var (Bitwarden)
Worker secret name:
STATUS_KEYGenerate with
openssl rand -hex 32(32+ characters). Store in Bitwarden asSTATUS_KEY, next toADMIN_TOKENandFORM_KEYS. It must be a different value from every form key.On Vercel, keep the same value under a name that cannot be mixed up with a form key, e.g.
UTSKICK_STATUS_KEY. Do not put it inFORM_KEYS.This PR does not create or print a real key. The next Worker deploy needs
STATUS_KEYin the secrets file (required binding, likeFORM_KEYS).config/sourceful.jsonalready namesstatus.lists: ["app-users"]andstatusLimiterNamespace: "7002". No deploy from this PR.Other design
status.listsin config is the allowlist (Sourceful:app-usersonly). Empty/absent →503 status_unavailable.STATUS_LIMITER, 120/min per calling server (CF-Connecting-IP).X-Client-IPis ignored so a stolen key cannot mint a new budget per guessed address. Failed auth does not count.{ event: "subscription_status", list, subscribed }on 200,{ event: "form_key_rejected", path: "/subscribe/status" }when a form key is used. No address, no key.test/status.test.ts(225 tests pass).Docs: docs/signup.md section 4, plus setup/README/SECURITY.