fix(fb,ff): harden form service security and proxy user-service token server-side - #113
Merged
Conversation
…d requests for admin reads
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
What does this PR do?
Fixes multiple security vulnerabilities in the form service (backend + frontend):
Protects submission read endpoints —
GET /submissions/{id}andGET /submissions/by-form/{form_id}now requireX-API-Tokenauthentication. Previously anyone could enumerate and read all submission data (PII: emails, names, answers) without any auth.Moves user-service token server-side — The frontend was embedding
VITE_USER_SERVICE_TOKENin the JS bundle, making it extractable by anyone. A new proxy router (/users/*) on the form backend forwards these requests to the user service with the token held server-side only. Frontend no longer ships any service token.Protects form list endpoint —
GET /forms/(list all) now requires admin auth.GET /forms/{id}remains public for respondents.Disables OpenAPI docs in production —
/docs,/redoc,/openapi.jsonare nowNonewhenENV != "development".Hardens token comparison — Switched to
hmac.compare_digestto prevent timing side-channel attacks.Tightens CORS — Restricted
allow_methodsandallow_headersfrom["*"]to only the methods/headers actually used.Sanitizes error messages —
detail=str(e)replaced with generic messages to avoid leaking internal state.Form submission UX Improvements : after successfull submition, show full success screeen rather than a alert
New files
services/form/app/clients/__init__.pyservices/form/app/clients/user_client.py— lazy-initialized httpx async client for user-service proxyservices/form/app/routers/users.py— proxy router forwarding/users/*to user serviceModified files
services/form/app/routers/submissions.py— auth on GETs, sanitized errorservices/form/app/routers/forms.py— auth on list, sanitized errorservices/form/app/main.py— register user router, disable prod docs, tighten CORSservices/form/app/config.py— addedUSER_SERVICE_URL,USER_SERVICE_TOKENservices/form/app/auth/api_key.py—hmac.compare_digestservices/form/pyproject.toml— addedhttpxruntime dependencyservices/form/.env.example— documented new env varsservices/form/.env.prod.example— documented new env vars + missingADMIN_API_TOKENfrontend/form/src/services/formService.ts—listForms,getSubmissionsByFormuseauthenticatedRequestfrontend/form/src/services/userService.ts— points to form service proxy, no tokenfrontend/form/.env.example— removedVITE_USER_SERVICE_*frontend/form/.env.prod.example— removedVITE_USER_SERVICE_*Deployment checklist
USER_SERVICE_URLenv var on form service production instanceUSER_SERVICE_TOKENenv var (must matchFORM_FRONTEND_TOKENon user service)uv syncon form service to installhttpxVITE_USER_SERVICE_URLandVITE_USER_SERVICE_TOKENfrom Vercel frontend env varsFORM_FRONTEND_TOKEN(was exposed in browser bundle)Checklist