Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

431 Request header too large

My project is coded with typescript, framework is nodejs 16. I have problem with cloud function of firebase. More specific, after I deploy my project to cloud function of firebase. In postman desktop, everything's fine. But when call api with postman in browser or app (kotlin, xcode) this request return error code 431 with message "Request header too large". I tried remove all header, but it still happens. And then, when I use api in serverless cloud functions to webhook in stripe, I got an error with message "Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?" while I test get and process in local is fine. No problem. Please support me. Thank for all.

0 2 4,248
2 REPLIES 2

The HTTP Error 431: Request Header Fields Too Large response status code indicates that the origin server refuses to fulfill users’ requests. This issue happens when HTTP headers are too large.

When encountering this error, the following can be done to fix it: 

  • Checking the cookies
  • Shortening the referrer URL 
  • Optimizing the code 

Here is an article that can help you with the troubleshooting:

[1]:https://www.hostinger.com/tutorials/error-431

The Stripe Error is very, very specific: while the request body can be *PARSED* as JSON, Stripe uses "stegonography" to encode extra data on the JSON body.  They use *non*-coding extra spaces, line breaks, tabs, etc.  This can still be *parsed* as JSON, but the signature verification*needs* the non-coding parts - that's why you have to be quite careful to *not* modify it at all before checking signature. (it also kinda masks the issue - the body parses as JSON just fine, so it *looks* like it's correct, but the verification fails).  This is often caused by using request.body instead of request.rawbody, or by something like Express middleware.