Skip to content

🛡️ Sentinel: Harden CORS and Origin Validation#102

Draft
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
sentinel/harden-cors-origin-validation-12687875897409892546
Draft

🛡️ Sentinel: Harden CORS and Origin Validation#102
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
sentinel/harden-cors-origin-validation-12687875897409892546

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

This PR hardens the application's security posture by replacing a dangerous global CORS wildcard policy with strict, programmatic origin validation.

Key changes:

  1. Strict Origin Validation: Replaced weak endsWith matching with a robust check that extracts the hostname using the URL constructor and ensures allowed suffixes (like .vercel.app) are matched only as legitimate subdomains. This prevents sibling domain bypasses (e.g., evilvercel.app).
  2. Resource Protection: Added an early check in the Chat API POST handler to return 403 Forbidden for unauthorized origins, preventing abuse of AI resources from non-whitelisted sites.
  3. Defense in Depth: Removed the wildcard Access-Control-Allow-Origin: * from next.config.mjs, ensuring that the API route's whitelist is the sole source of truth for cross-origin access.
  4. Compatibility: Updated getCorsHeaders to include the full set of headers previously provided by the global config, ensuring seamless integration with the AI assistant on whitelisted domains.
  5. Testing: Added unit tests to response.test.ts to verify the new validation logic against various edge cases and malicious patterns. Updated route.test.ts to include origin validation.

All tests passed successfully.


PR created automatically by Jules for task 12687875897409892546 started by @amrabed

- 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.
@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
amrabed-github-io Ready Ready Preview, Comment Jul 14, 2026 4:25am

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants