fix(security): collapse origin-allowlist duplication, finish sanitizer/comparison seams#500
Merged
Merged
Conversation
…izer/comparison seams Five API routes each reimplemented CORS/origin-allowlist checking slightly differently; extract a shared isAllowedOrigin()/corsHeaders() in src/utils/origin.ts, configured per-route policy so each route's actual (differing) rules are preserved rather than flattened. Also: sentry-webhook.ts now routes its signature check through the existing constantTimeEqual seam instead of a hand-rolled comparison; ProjectsNew.tsx and api/projects.ts now call the canonical sanitizeUrl/sanitizeEmail from projectData.ts instead of maintaining duplicate copies; notionClient.ts's five fetchers now share fileUrl/titleText/richText helpers instead of repeating Notion property-parsing inline five times.
Deploying website with
|
| Latest commit: |
8dafa58
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://18e223a6.website-aun.pages.dev |
| Branch Preview URL: | https://refactor-deepen-security-sea.website-aun.pages.dev |
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
From an architecture review of the codebase, three "Strong" deepening candidates:
donation-complete.ts,membership-complete.ts,pipe.ts,e4p-pledge-sign.ts, andendorsement-request.tseach reimplemented CORS/origin checking slightly differently (byte-identical in two cases, divergent preview-domain handling in others). Extractedsrc/utils/origin.tswithisAllowedOrigin(origin, policy)/corsHeaders()— policy is configurable per route so each route's actual rules are preserved, not flattened into one behavior.sentry-webhook.tshand-rolled its own constant-time signature comparison instead of using the existingconstantTimeEqualinsrc/utils/crypto.ts(used correctly bybasicAuth.ts). Now routes through it.ProjectsNew.tsxandapi/projects.tseach had their own copy of URL/email sanitization;src/components/projects/projectData.tsalready had the canonical implementation (proven byProjectDrawer.tsx). Both now import from it.Plus one "Worth exploring" candidate:
src/store/notionClient.ts's five fetcher functions each re-implemented the same Notion property-parsing logic (title/rich-text extraction, files→URL resolution with fallback). ExtractedfileUrl/titleText/richTexthelpers; all fetchers keep identical external signatures and return shapes.No behavior changes to any route's actual origin policy, sanitization rules, or Notion data shape — this is pure internal deduplication.
Test plan
pnpm checkpasses clean (0 errors, 0 warnings)pnpm format:checkclean on all touched files/api/projectsstill renders correctly on both/projectsand/projects-new