C: Fix critical issues — proto clamping, entities export auth, DB_SCHEMA default - #14
Open
davidpomerenke wants to merge 1 commit into
Open
C: Fix critical issues — proto clamping, entities export auth, DB_SCHEMA default#14davidpomerenke wants to merge 1 commit into
davidpomerenke wants to merge 1 commit into
Conversation
…ties export; unify DB_SCHEMA import
|
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.
Summary\n\nFixes three bugs identified in the code review (REVIEW.md):\n\n### Fix 1 — Clamp
x-forwarded-prototo known schemes (src/lib/get-base-url.ts)\n\ngetBaseUrl()previously passed the rawx-forwarded-protoheader value directly into the URL scheme. An attacker who can craft requests to a directly-exposed Node process could set this header to an arbitrary value (e.g.,http) and downgrade the magic-link URL in emails to plain HTTP, causing the token to be transmitted in clear text.\n\nNow the scheme is clamped: only\"http\"and\"https\"are accepted; anything else (including absence of the header) defaults to\"https\". Localhost is always forced to\"http\"regardless.\n\n### Fix 2 — Add admin auth guard to entities export route (src/app/api/export/entities/route.ts)\n\nThePOST /api/export/entitiesendpoint accepted arbitrary JSON data and rendered it to a UN-branded Excel file with no authentication. Any unauthenticated caller could generate spoofed UN-branded spreadsheets.\n\nNow the route callsgetCurrentUser()and returns 403 unless the user is an admin.\n\n### Fix 3 — UnifyDB_SCHEMAdefault insrc/lib/config.ts\n\nTheconfig.tsfile exportedDB_SCHEMAwith a default of\"app\", while every API route that used the schema directly re-declared it locally with the correct default of\"sg_reports_survey\". These inconsistent defaults would cause auth queries to silently target the wrong schema on a fresh deployment withoutDB_SCHEMAset.\n\nThe default inconfig.tsis now\"sg_reports_survey\"(matching the SQL files), making it safe to import from there rather than re-declaring locally.\n\n## Test plan\n\n- [ ]pnpm typecheck— no errors\n- [ ]pnpm build— builds cleanly\n- [ ] UnauthenticatedPOST /api/export/entitiesreturns 403\n- [ ] Non-admin authenticatedPOST /api/export/entitiesreturns 403\n- [ ] AdminPOST /api/export/entitiesstill returns Excel file\n- [ ] Magic-link emails usehttps://whenx-forwarded-protois absent or contains a non-standard value\n- [ ] Magic-link emails usehttp://for localhost\n\n🤖 Generated with Claude CodeGenerated by Claude Code