Skip to content

Potential fix for code scanning alert no. 58: CORS misconfiguration for credentials transfer#113

Merged
utsavjosh1 merged 1 commit into
mainfrom
alert-autofix-58
Apr 29, 2026
Merged

Potential fix for code scanning alert no. 58: CORS misconfiguration for credentials transfer#113
utsavjosh1 merged 1 commit into
mainfrom
alert-autofix-58

Conversation

@utsavjosh1

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/utsavjosh1/Postly/security/code-scanning/58

To fix this safely, keep the allowlist logic but stop writing the raw request header back to Access-Control-Allow-Origin. Instead:

  • Normalize and validate the request origin.
  • Explicitly reject "null".
  • Find an exact match in the normalized trusted origins list.
  • Set Access-Control-Allow-Origin to the trusted matched value (server-side canonical value), not origin.

In apps/api/src/middleware/error-handler.ts, update the CORS block around lines 23–36:

  • Build allowedOrigins as normalized values.
  • Ensure normalizedOrigin !== "null".
  • Use const matchedOrigin = allowedOrigins.find((o) => o === normalizedOrigin);
  • If matched, set header with matchedOrigin instead of origin as string.

No new imports or dependencies are required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…or credentials transfer

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Apr 28, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
postly-web Ready Ready Preview, Comment Apr 28, 2026 5:33pm

@utsavjosh1 utsavjosh1 marked this pull request as ready for review April 29, 2026 10:14
@utsavjosh1 utsavjosh1 merged commit 3faff14 into main Apr 29, 2026
7 checks passed
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.

1 participant