PolicyEngine / PolicyEngine/policyengine-uk-chat

Security: enforce backend Supabase JWT authentication

Open
#128 1 comment 0 reactions 0 assignees View on GitHub

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.py includes 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 401 where login is required.

Once this exists, route handlers should stop accepting trusted user_id values from clients.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.