Skip to content

Detect Cloudflare WAF block pages and show a helpful error message in stead of "Received a malformed response from the API"#13574

Open
dario-piotrowicz wants to merge 1 commit intomainfrom
dario/13312/malformed-response-block-page
Open

Detect Cloudflare WAF block pages and show a helpful error message in stead of "Received a malformed response from the API"#13574
dario-piotrowicz wants to merge 1 commit intomainfrom
dario/13312/malformed-response-block-page

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Apr 16, 2026

Fixes #13312

When the Cloudflare WAF blocks an API request, the response is an HTML page rather than JSON. Previously, this caused a confusing "Received a malformed response from the API" error with a truncated HTML snippet. Wrangler now detects WAF block pages and displays a clear error message explaining that the request was blocked by the firewall, along with the Cloudflare Ray ID (when available) for use in support tickets.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: UX improvement

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: e916798

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

Changeset Review

File Reviewed: .changeset/detect-waf-block-response.md

Criterion Status Notes
Version Type patch is appropriate for this bug fix (improving error message clarity)
Changelog Quality Clear description of the problem (confusing "malformed response" error) and solution (helpful WAF block detection with Ray ID)
Markdown Headers No h1/h2/h3 headers found
Analytics No analytics collection mentioned
Dependabot Not a dependabot changeset
Experimental Features Not an experimental feature

✅ All changesets look good

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13574

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13574

miniflare

npm i https://pkg.pr.new/miniflare@13574

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13574

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13574

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13574

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13574

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13574

wrangler

npm i https://pkg.pr.new/wrangler@13574

commit: e916798

@dario-piotrowicz dario-piotrowicz force-pushed the dario/13312/malformed-response-block-page branch 2 times, most recently from 5fb9af9 to 5fdb36a Compare April 17, 2026 12:02
…stead of "Received a malformed response from the API"
@dario-piotrowicz dario-piotrowicz force-pushed the dario/13312/malformed-response-block-page branch from 5fdb36a to e916798 Compare April 17, 2026 12:10
@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review April 17, 2026 12:11
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team April 17, 2026 12:11
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/cfetch-internal.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/cfetch/internal.ts: [@cloudflare/wrangler]

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

* @param body - The raw response body text to check.
* @returns `true` if the body appears to be a Cloudflare WAF block page.
*/
export function isWAFBlockResponse(body: string): boolean {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

* @param html - The HTML body of a WAF block page.
* @returns The Ray ID hex string, or `undefined` if not found.
*/
export function extractWAFBlockRayId(html: string): string | undefined {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i'd just pull from headers, body is fragile

@WalshyDev
Copy link
Copy Markdown
Member

also for any and all html instead of json it'd be good to get a ray id even aside WAF, we can always use that to dig into logs :)

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

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

Wrangler Deploy Error: Received a malformed response from the API

3 participants