Skip to content

fix(cloudflare): Return HTTPException responses instead of 500 - #1775

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/cloudflare-http-exception-responses
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/cloudflare-http-exception-responses

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Cross-site form POSTs to the Cloudflare app, mostly bots and scanners hitting paths that don't exist, come back as 500s. Each one also creates a Sentry error event. That is the source of MCP-SERVER-GDZ.

csrf() is mounted on * and throws HTTPException(403) when it rejects a request. The app's onError handler did not check for HTTPException. It called logIssue on every error and returned a generic 500. A CSRF rejection that should be a 403 became a reported server error. This also affects real browser CSRF failures on POST /oauth/authorize. /oauth/token is handled by the OAuth provider before the app, so it is not affected.

onError now returns err.getResponse() for HTTPException, and calls logIssue only when the status is 5xx. Other errors still get a 500 and are reported as before.

The 4xx rejections are still kept so they can be audited. Each one writes a warn-level HTTP exception response log entry to Sentry Logs. That is a log entry, not an issue. It records the status, method, path, Origin, Sec-Fetch-Site and Content-Type. A header that wasn't sent is recorded as (absent). It records no IPs, cookies, auth headers or bodies. The csrf middleware is wrapped so its rejections are tagged app.http_exception.reason=csrf, which makes them searchable. Any other 4xx HTTPException is logged with reason=unknown.

Three changes to app.test.ts:

  • A cross-site form POST returns 403, does not call logIssue, and writes the audit log entry with the expected fields.
  • A generic thrown error still returns 500 and is reported.
  • A generic error does not write the audit entry.

via David Cramer.

--

View Session [Sentry]

The app onError handler turned every error into a 500 and reported it
with logIssue, including HTTPException(403) thrown by csrf() for
cross-site form POSTs. Return the exception's own response and only
report server-error statuses.

Co-Authored-By: David Cramer <david@sentry.io>
@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 31, 2026 10:31pm UTC

Request Review

CSRF rejections and other 4xx HTTPExceptions now emit a warn-level
"HTTP exception response" log entry (Sentry Logs, not an issue) with
status, method, path, Origin, Sec-Fetch-Site, and Content-Type. csrf()
rejections are tagged so the entry carries app.http_exception.reason=csrf.

Co-Authored-By: David Cramer <david@sentry.io>
@BYK
BYK marked this pull request as ready for review November 1, 2026 15:02
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 1, 2026

This branch was previously deployed

1 inactive deployment
Preview — b846690b Deployed Oct 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant