🛡️ Sentinel: Harden CORS and Origin Validation#102
🛡️ Sentinel: Harden CORS and Origin Validation#102google-labs-jules[bot] wants to merge 1 commit into
Conversation
- Removed overly permissive global wildcard CORS policy from `next.config.mjs`. - Implemented robust origin validation in `src/app/api/chat/response.ts` using the `URL` constructor and strict subdomain matching. - Added an early access control check in the Chat API route to reject unauthorized origins with a 403 Forbidden status. - Expanded `getCorsHeaders` to include all necessary headers for AI SDK compatibility and restored `Access-Control-Allow-Credentials`. - Updated test suite with comprehensive cases for valid and malicious origins. - Documented learnings in the Sentinel journal.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This PR hardens the application's security posture by replacing a dangerous global CORS wildcard policy with strict, programmatic origin validation.
Key changes:
endsWithmatching with a robust check that extracts the hostname using theURLconstructor and ensures allowed suffixes (like.vercel.app) are matched only as legitimate subdomains. This prevents sibling domain bypasses (e.g.,evilvercel.app).POSThandler to return403 Forbiddenfor unauthorized origins, preventing abuse of AI resources from non-whitelisted sites.Access-Control-Allow-Origin: *fromnext.config.mjs, ensuring that the API route's whitelist is the sole source of truth for cross-origin access.getCorsHeadersto include the full set of headers previously provided by the global config, ensuring seamless integration with the AI assistant on whitelisted domains.response.test.tsto verify the new validation logic against various edge cases and malicious patterns. Updatedroute.test.tsto include origin validation.All tests passed successfully.
PR created automatically by Jules for task 12687875897409892546 started by @amrabed