{"record":{"id":"f471fde9ac55528e","repo":"Netflix/zuul","slug":"received-invalid-message-from-client","errorCode":null,"errorMessage":"Received invalid message from client","messagePattern":"Received invalid message from client","errorType":"exception","errorClass":"ZuulException","httpStatus":null,"severity":"error","filePath":"zuul-core/src/main/java/com/netflix/zuul/netty/server/OriginResponseReceiver.java","lineNumber":256,"sourceCode":"                        fireWriteError(\"request headers\", future.cause(), ctx);\n                    }\n                }\n            });\n\n            preWriteHook(ctx, zuulReq);\n\n            super.write(ctx, buildOriginHttpRequest(zuulReq), promise);\n        } else if (msg instanceof HttpContent) {\n            promise.addListener((future) -> {\n                if (!future.isSuccess()) {\n                    fireWriteError(\"request content chunk\", future.cause(), ctx);\n                }\n            });\n            super.write(ctx, msg, promise);\n        } else {\n            // should never happen\n            ReferenceCountUtil.release(msg);\n            throw new ZuulException(\"Received invalid message from client\", true);\n        }\n    }\n\n    /**\n     * Override to add custom pre-write functionality\n     *\n     * @param ctx     channel handler context\n     * @param zuulReq request message to modify\n     */\n    protected void preWriteHook(ChannelHandlerContext ctx, HttpRequestMessage zuulReq) {}\n\n    private void fireWriteError(String requestPart, Throwable cause, ChannelHandlerContext ctx) {\n        String errMesg = \"Error while proxying \" + requestPart + \" to origin \";\n        if (edgeProxy != null) {\n            ProxyEndpoint ep = edgeProxy;\n            edgeProxy = null;\n            errMesg += ep.getOrigin().getName();\n            ep.errorFromOrigin(cause);","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/Netflix/zuul/blob/14bf53c52dcf571894619ff65a674cbe2cce3ac6/zuul-core/src/main/java/com/netflix/zuul/netty/server/OriginResponseReceiver.java#L238-L274","documentation":"OriginResponseReceiver.writeInternal writes messages from the client side toward the origin connection and only accepts valid Zuul request/HTTP message types. If a write arrives with any other type, Zuul releases it and throws this error, since forwarding an unrecognized object to the origin would corrupt the proxied request. The 'should never happen' comment marks it as an internal invariant guard.","triggerScenarios":"An object that is not a recognized Zuul request message (e.g. raw String, ByteBuf, or custom object) is written into the origin-bound pipeline — typically from a custom pre-origin ZuulFilter or handler writing a foreign object type.","commonSituations":"Custom request filters mutating session/context and returning raw objects; version mismatches between custom filter code and zuul-core message APIs; errant pipeline handlers forwarding non-HTTP messages during proxying.","solutions":["Locate the filter writing the invalid object (log msg.getClass() before the write) and convert it to the proper ZuulMessage/HttpRequest type.","Ensure request filters set data via the Zuul session/message API (e.g. zuulRequest buffers/headers) rather than writing custom objects to the channel.","Align custom filter code and zuul-core versions so request message types match.","Audit pipeline customizations in the origin channel init for handlers that fire non-HTTP messages."],"exampleFix":"// before (custom request filter)\nctx.write(myCustomPayload);\n// after\ncontext.getZuulRequest().setBody(payloadBytes); // mutate the Zuul request message, don't write foreign objects","handlingStrategy":"validation","validationCode":"// before writing toward the origin, assert the message is a supported Zuul/Netty request type\nif (!(msg instanceof HttpRequest || msg instanceof HttpContent || msg instanceof ZuulMessage)) {\n    throw new IllegalArgumentException(\"Unsupported request message: \" + msg.getClass().getName());\n}","typeGuard":"boolean isValidOriginRequest(Object msg) {\n    return msg instanceof HttpRequest || msg instanceof HttpContent || msg instanceof ZuulMessage;\n}","tryCatchPattern":"try {\n    ctx.write(msg);\n} catch (ZuulException e) {\n    if (\"Received invalid message from client\".equals(e.getMessage())) {\n        log.error(\"Filter wrote invalid object to origin pipeline\", e);\n        promise.setFailure(e);\n    }\n}","preventionTips":["Mutate the Zuul request via its API (headers/body) instead of writing custom objects to the channel","Only fire HttpRequest/HttpContent/ZuulMessage types into the origin-bound pipeline","Integration-test custom request filters against a live Zuul pipeline before deploy","Align custom filter dependencies with the running zuul-core version"],"tags":["netty","zuul-filter","internal-invariant","origin-request"],"backgroundTag":"internal-invariant-violation","analyzedSha":"14bf53c52dcf571894619ff65a674cbe2cce3ac6","analyzedAt":"2026-09-07T10:00:54.873Z","contentChangedAt":"2026-09-07T10:00:54.873Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}