Skip to content

fix(codeflow): [CI/rebase] CORS exposes x-api-key and authorization headers cross-origin with wildcard - #44

Open
nehraa wants to merge 1 commit into
mainfrom
claude-lane/task_audit_1780457435798_004-20260603120220
Open

nehraa wants to merge 1 commit into
mainfrom
claude-lane/task_audit_1780457435798_004-20260603120220

Conversation

@nehraa

@nehraa nehraa commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Original task: task_audit_1780457435798_004
PR branch: claude-lane/task_audit_1780457435798_004-20260603120220
CI failure: merge-conflict
Strategy: rebase

Hint: PR has merge conflicts with main. Run: git fetch origin && git rebase origin/main && git push --force-with-lease. The watcher's open_pr_for_task will detect the existing PR.

Failure log (last 3000 chars)

X Pull request #35 is not mergeable: the merge commit cannot be cleanly created.
To have the pull request merged after all the requirements have been met, add the `--auto` flag.

Workflow

  1. Read the failure log and the PR's diff (use git log origin/main..claude-lane/task_audit_1780457435798_004-20260603120220)
  2. Apply the fix on top of the SAME branch (claude-lane/task_audit_1780457435798_004-20260603120220) — the worktree is already set up by the dispatcher
  3. Commit with fix(ci): <one-line summary> (single line)
  4. The dispatcher will push your commit to the SAME branch and detect the existing PR
  5. The PR's CI re-runs automatically. Watcher picks it up on the next 5-min cycle.
  6. Report: files changed, commit SHA, what the fix was

Automated by DevPulse dispatcher.

Copilot AI lite review requested due to automatic review settings September 14, 2026 14:45
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1d71902f-460b-4a96-b33a-c7fba1c95f83


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Prevent cross-origin credential headers in CodeFlow MCP

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Remove authorization and x-api-key from CORS preflight responses in all origin modes.
• Preserve Content-Type and x-request-id support for legitimate cross-origin requests.
• Add regression coverage preventing credential headers from being advertised.
Diagram

sequenceDiagram
  actor Browser
  participant Server as HTTP Server
  participant Cors as CORS Builder
  Browser->>Server: OPTIONS preflight
  Server->>Cors: Build headers
  Cors-->>Server: Safe header list
  Server-->>Browser: 204 without credentials
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Require strict origin allowlisting
  • ➕ Preserves credential-bearing headers for explicitly trusted browser origins.
  • ➕ Supports authenticated browser clients without changing their request format.
  • ➖ Requires reliable deployment-specific origin configuration.
  • ➖ A misconfigured allowlist could reintroduce cross-origin credential risk.
  • ➖ Provides a less secure permissive default than omitting credential headers.

Recommendation: The PR's least-privilege approach is preferable when browser clients do not need to submit bearer tokens or API keys directly. If credentialed browser integrations are required, retaining these headers only under mandatory strict origin allowlisting should be considered as an explicit opt-in.

Files changed (2) +24 / -5

Bug fix (1) +7 / -2
index.tsRemove credential headers from CORS allowlists +7/-2

Remove credential headers from CORS allowlists

• Removes authorization and x-api-key from Access-Control-Allow-Headers in both strict and permissive origin modes. Non-credential headers remain supported for legitimate preflight requests.

packages/codeflow-mcp/src/invoke/index.ts

Tests (1) +17 / -3
index.test.tsAssert CORS preflights omit credential-bearing headers +17/-3

Assert CORS preflights omit credential-bearing headers

• Reverses the previous expectation that authorization and x-api-key are advertised. The regression test now verifies both credentials are absent while Content-Type and x-request-id remain available.

packages/codeflow-mcp/src/invoke/index.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02f5e7047f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"Access-Control-Allow-Origin": allowOrigin,
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, authorization, x-api-key, x-request-id",
"Access-Control-Allow-Headers": "Content-Type, x-request-id",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow auth headers for allowlisted browser clients

When MCP_ALLOWED_ORIGIN is configured for a browser client, any Authorization or x-api-key request triggers a preflight whose requested header is now absent here, so the browser rejects the request before the JSON-RPC POST is sent. This breaks the documented browser-based HTTP transport and its invokeMcpTool(..., { "x-api-key": ... }) usage (docs/codeflow-mcp.md:61, docs/codeflow-mcp.md:89) even for explicitly allowlisted origins; retain these headers in strict mode (or make them configurable) rather than removing them globally.

Useful? React with 👍 / 👎.

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Trusted browser clients lose access 🐞 Bug ≡ Correctness
Description
buildCorsHeaders removes authorization and x-api-key even when MCP_ALLOWED_ORIGIN identifies
the requesting origin as trusted. Browser clients using the documented header forwarding trigger a
preflight that omits their requested credential header, so the browser blocks both tool listing and
invocation before their POST requests reach the server.
Code

packages/codeflow-mcp/src/invoke/index.ts[230]

+      "Access-Control-Allow-Headers": "Content-Type, x-request-id",
Evidence
The HTTP transport explicitly supports browser-based clients, and the documented helper example
supplies x-api-key. Both client helpers forward arbitrary headers through fetch, while every
OPTIONS request receives the reduced header list before the POST handler can run; therefore an
allowlisted browser origin using either credential header cannot complete its preflight.

docs/codeflow-mcp.md[50-61]
docs/codeflow-mcp.md[79-93]
packages/codeflow-mcp/src/index.ts[21-40]
packages/codeflow-mcp/src/index.ts[70-93]
packages/codeflow-mcp/src/invoke/index.ts[214-230]
packages/codeflow-mcp/src/invoke/index.ts[285-289]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The strict CORS path removes `authorization` and `x-api-key` for explicitly allowlisted origins, breaking supported browser clients that pass those headers through `listMcpTools` or `invokeMcpTool`.

## Fix Focus Areas
- packages/codeflow-mcp/src/invoke/index.ts[214-237]
- packages/codeflow-mcp/src/invoke/index.test.ts[367-393]

## Recommended Fix
Retain `authorization` and `x-api-key` in `Access-Control-Allow-Headers` when the request origin matches `MCP_ALLOWED_ORIGIN`, while continuing to omit them in permissive mode. Add tests proving an allowlisted origin can preflight credential headers and an arbitrary origin cannot.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This is a security-sensitive CORS behavior change affecting cross-origin credential exposure, so it warrants a complete careful review despite its small, localized diff.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

"Access-Control-Allow-Origin": allowOrigin,
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, authorization, x-api-key, x-request-id",
"Access-Control-Allow-Headers": "Content-Type, x-request-id",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Trusted browser clients lose access 🐞 Bug ≡ Correctness

buildCorsHeaders removes authorization and x-api-key even when MCP_ALLOWED_ORIGIN identifies
the requesting origin as trusted. Browser clients using the documented header forwarding trigger a
preflight that omits their requested credential header, so the browser blocks both tool listing and
invocation before their POST requests reach the server.
Agent Prompt
## Issue description
The strict CORS path removes `authorization` and `x-api-key` for explicitly allowlisted origins, breaking supported browser clients that pass those headers through `listMcpTools` or `invokeMcpTool`.

## Fix Focus Areas
- packages/codeflow-mcp/src/invoke/index.ts[214-237]
- packages/codeflow-mcp/src/invoke/index.test.ts[367-393]

## Recommended Fix
Retain `authorization` and `x-api-key` in `Access-Control-Allow-Headers` when the request origin matches `MCP_ALLOWED_ORIGIN`, while continuing to omit them in permissive mode. Add tests proving an allowlisted origin can preflight credential headers and an arbitrary origin cannot.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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.

2 participants