Cloudflare Error 1040 / 1041: Invalid request header modification

A Transform Rule tried to set or remove a request header that Cloudflare doesn’t allow to be modified, or produced an invalid value.

Seen on: Cloudflare

Meaning

Some headers (Host, Content-Length, cf-* headers) can’t be modified with Transform Rules, and values must be valid header text.

Common causes

  • Modifying a reserved header (Host, cf-connecting-ip, etc.)
  • Invalid characters in the new header value
  • Dynamic expression evaluating to an invalid value

⚡ Quick fix

  1. Remove the modification of reserved headers
  2. Use Origin Rules for Host header overrides
  3. Validate the header value expression

Detailed fix by platform

Cloudflare

  1. # Rules → Origin Rules → Host Header override (instead of a request header Transform Rule)

How to diagnose

  1. Header — Which header is modified?
  2. Value — Valid characters?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.