Skip to content

fix: fail closed when SUPABASE_JWT_SECRET is missing (#420)#486

Open
ionfwsrijan wants to merge 8 commits into
FireFistisDead:masterfrom
ionfwsrijan:fix/issue-420-fail-closed-jwt-secret
Open

fix: fail closed when SUPABASE_JWT_SECRET is missing (#420)#486
ionfwsrijan wants to merge 8 commits into
FireFistisDead:masterfrom
ionfwsrijan:fix/issue-420-fail-closed-jwt-secret

Conversation

@ionfwsrijan

@ionfwsrijan ionfwsrijan commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

requireSupabaseAuth middleware only enforced token presence when SUPABASE_JWT_SECRET was unset — any bearer token-shaped header passed through without cryptographic verification. In production, a missing or mistyped secret silently became an ingest-capable open gate for arbitrary requesters.

Made the middleware return HTTP 500 when the secret is not configured, and added a startup validation that throws in production so the server cannot start in an insecure state.

Related issue

Closes #420

Testing

  • I ran the relevant checks locally
  • I verified the app still starts
  • I tested the affected flow end-to-end

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Screenshots / recordings

N/A

Notes

  • Middleware: secret check moved to the top — returns 500 immediately if SUPABASE_JWT_SECRET is not set, before any token check
  • Startup: production throws a hard error; development logs a warning that requests will be rejected
  • Token verification (jwt.verify) now always runs since the secret is guaranteed present past the gate

Security

  • No sensitive data included

Summary by CodeRabbit

  • Chores

    • Removed duplicate export in validation schemas
    • Expanded test user database
    • Updated server startup initialization behavior
  • Tests

    • Enhanced authentication testing with realistic JWT token handling

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown

@ionfwsrijan is attempting to deploy a commit to the firefistisdead's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ionfwsrijan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 47 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cb3653af-c14d-4e43-9626-becc15e65dbc

📥 Commits

Reviewing files that changed from the base of the PR and between a218218 and 51fadaf.

📒 Files selected for processing (2)
  • rag-service/test_concurrent_uploads.py
  • rag-service/test_main.py
📝 Walkthrough

Walkthrough

Server initialization now triggers uploads cleanup when the backend starts. Express 404 handler middleware signature changes from three to two arguments. Authentication tests are updated to use real Supabase-style JWTs signed with the secret, test user data expands, and a duplicate schema export is removed.

Changes

Server and schema maintenance

Layer / File(s) Summary
Server startup with uploads cleanup initialization
server.js, server.test.js
app.listen callback now calls startUploadsCleanup() after logging startup. Test credential cache setup wires only cache helper functions without assigning the internal _credCache object.
Express 404 not-found handler middleware
server.js
Catch-all app.use middleware signature changes from (req, res, next) to (req, res) form, affecting Express middleware chaining for the 404 handler.
Authentication testing with real Supabase JWT
server.test.js, src/data/users.json
Two /process-from-url route tests replace hardcoded bearer tokens with JWTs signed using process.env.SUPABASE_JWT_SECRET. Test user data file adds multiple email/password pairs.
Schema export deduplication
validators/schemas.js
Duplicate sessionsLookupSchema export key removed from module.exports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • FireFistisDead/pdf-qa-bot#276: Uploads deletion and safety-net cleanup behavior directly connected to the new startUploadsCleanup() call during server startup.
  • FireFistisDead/pdf-qa-bot#384: JWT secret enforcement in requireSupabaseAuth middleware directly aligns with the test updates to use real Supabase-signed tokens.

Suggested labels

level:intermediate, quality:clean

Suggested reviewers

  • FireFistisDead

Poem

🐰 The server wakes to cleanup's call,
Express picks 404 with care,
JWTs now real and true for all,
Schemas deduplicate with flair!
A rabbit's work, both quick and clean. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: implementing fail-closed behavior when SUPABASE_JWT_SECRET is missing, addressing issue #420.
Description check ✅ Passed The description covers all required sections: summary explaining the security issue, related issue link, testing checklist, code review checklist, and security confirmation.
Linked Issues check ✅ Passed Code changes directly address issue #420 objectives: middleware returns HTTP 500 when secret missing, startup validation prevents insecure server start, and cryptographic verification always runs when secret is present.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the fail-open authentication issue: middleware hardening, startup validation, test updates for valid JWTs, schema cleanup, and user data expansion are all necessary for the security fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added backend Express or API gateway work bug Something isn't working docs Documentation only enhancement New feature or request feature A new feature or improvement fix A targeted fix or cleanup frontend Frontend-related work level:advanced type:security type:testing labels Jun 7, 2026
@ionfwsrijan ionfwsrijan closed this Jun 7, 2026
@ionfwsrijan ionfwsrijan force-pushed the fix/issue-420-fail-closed-jwt-secret branch from 677e2ae to 42ae762 Compare June 7, 2026 09:47
- Remove duplicate sessionsLookupSchema key in validators/schemas.js
- Generate valid JWT tokens in process-from-url tests instead of
  plaintext Bearer tokens (tests broken by requireSupabaseAuth change)
- Remove unused _credCache variable from server.test.js
- Remove unused next parameter from 404 handler in server.js
- Start uploadsCleanup interval on server startup
…rl tests

Replace Buffer return with Readable stream from Buffer to match the
streaming download handler, and mock axios.postForm (not axios.post)
since the handler now uses axios.postForm.
@ionfwsrijan ionfwsrijan reopened this Jun 7, 2026
- Return Buffer instead of Readable stream (handler uses responseType: 'arraybuffer')
- Mock axios.post instead of axios.postForm (handler uses axios.post with FormData)
@github-actions github-actions Bot added the rag-service FastAPI / model service work label Jun 7, 2026
@github-actions github-actions Bot added the duplicate This issue or pull request already exists label Jun 7, 2026
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@FireFistisDead You may review and merge this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Express or API gateway work bug Something isn't working docs Documentation only duplicate This issue or pull request already exists enhancement New feature or request feature A new feature or improvement fix A targeted fix or cleanup frontend Frontend-related work level:advanced rag-service FastAPI / model service work type:security type:testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process-from-url fails open when the Supabase JWT secret is missing

1 participant