PolicyEngine / PolicyEngine/policyengine-uk-chat
Security: enforce backend Supabase JWT authentication
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 1
- Avg merge
- 16h 46m
- Merged PRs (30d)
- 2
Description
Problem
The frontend has Supabase login, but the FastAPI backend does not verify a Supabase JWT. Backend routes currently accept requests directly and trust caller-supplied identity fields such as user_id.
Affected areas observed:
backend/api/main.pyincludes routers directly without auth middleware/dependencies.- Chat, conversations, and billing routes accept identity via request body, query params, or headers instead of deriving it from a verified token.
Risk
Anyone who can reach the backend can call protected-looking endpoints without proving identity. This makes downstream ownership checks and billing checks unreliable.
Suggested fix
Add a shared FastAPI auth dependency that:
- validates
Authorization: Bearer <Supabase JWT>; - verifies issuer/audience/signature/expiry;
- derives the authenticated user id from the token subject;
- exposes a typed current-user object to route handlers;
- rejects unauthenticated requests with
401where login is required.
Once this exists, route handlers should stop accepting trusted user_id values from clients.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in backend/api/main.py, then inspect the chat, conversations, and billing routes to trace how identity is currently accepted. Define the shared FastAPI dependency around the requested Supabase JWT checks and identify every protected route that must use it. Done means authenticated routes derive the user from the verified token, reject missing or invalid credentials with 401, and no longer trust client-supplied user_id values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python, supabase
- Domain
- api, authentication, backend, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100