{"record":{"id":"4f3ca8ba4207db50","repo":"nats-io/nats-server","slug":"processroutedheadermsgargs-header-size-larger-then","errorCode":null,"errorMessage":"processRoutedHeaderMsgArgs Header Size larger then TotalSize: '%s'","messagePattern":"processRoutedHeaderMsgArgs Header Size larger then TotalSize: '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/route.go","lineNumber":365,"sourceCode":"\t\t// Grab size.\n\t\tc.pa.szb = args[len(args)-1]\n\t\tc.pa.size = parseSize(c.pa.szb)\n\n\t\t// Grab queue names.\n\t\tif c.pa.reply != nil {\n\t\t\tc.pa.queues = args[4 : len(args)-2]\n\t\t} else {\n\t\t\tc.pa.queues = args[3 : len(args)-2]\n\t\t}\n\t}\n\tif c.pa.hdr < 0 {\n\t\treturn fmt.Errorf(\"processRoutedHeaderMsgArgs Bad or Missing Header Size: '%s'\", arg)\n\t}\n\tif c.pa.size < 0 {\n\t\treturn fmt.Errorf(\"processRoutedHeaderMsgArgs Bad or Missing Size: '%s'\", args)\n\t}\n\tif c.pa.hdr > c.pa.size {\n\t\treturn fmt.Errorf(\"processRoutedHeaderMsgArgs Header Size larger then TotalSize: '%s'\", arg)\n\t}\n\n\t// Common ones processed after check for arg length\n\tc.pa.account = args[0]\n\tc.pa.subject = args[1]\n\tif len(an) > 0 {\n\t\tc.pa.pacache = c.pa.subject\n\t} else {\n\t\tc.pa.pacache = arg[:len(args[0])+len(args[1])+1]\n\t}\n\treturn nil\n}\n\n// Process an inbound RMSG or LMSG specification from the remote route.\nfunc (c *client) processRoutedMsgArgs(arg []byte) error {\n\t// Unroll splitArgs to avoid runtime/heap issues\n\targs := c.argsa[:0]\n\tvar an []byte","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/route.go#L347-L383","documentation":"When a route (or leaf/gateway forwarded) HPUB message is parsed, the protocol args carry a header size and a total payload size. If the declared header byte count (c.pa.hdr) exceeds the declared total size (c.pa.size), the protocol line is internally inconsistent, so processRoutedHeaderMsgArgs rejects it. This guards against corrupt or malicious inter-server traffic.","triggerScenarios":"A routed HMSG/HPUB whose args encode a header length greater than the total message size, e.g. 'HMSG <subject> <reply> <hdrSize> <totalSize>' where hdrSize > totalSize; produced by a corrupt, buggy, or hostile upstream server/route connection.","commonSituations":"NATS cluster peering with a server that mangles protocol lines (proxy rewriting, TCP corruption), custom client or bridge sending hand-crafted HPUB with swapped header/total size fields, or fuzzing/attack traffic on the route port.","solutions":["Inspect the client or intermediary that produced the message and fix the size fields so headers <= total size","Verify the route connection is not passing through a corrupting proxy or buggy middleware","Ensure all servers in the cluster run a compatible, recent NATS Server version","Check sender code that serializes HPUB: header byte length must be added to, not replace, the total size"],"exampleFix":"// before (sender)\nfmt.Printf(\"HMSG %s %s %d %d\\r\\n\", subj, reply, hdrLen, hdrLen)\n// after\nfmt.Printf(\"HMSG %s %s %d %d\\r\\n\", subj, reply, hdrLen, hdrLen+payloadLen)","handlingStrategy":"validation","validationCode":"// Go client/server operator: validate HPUB sizes before publishing\nif hdrLen > totalSize {\n    return fmt.Errorf(\"header size %d exceeds total size %d\", hdrLen, totalSize)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always compute totalSize as headerLen + payloadLen when emitting HPUB","Keep cluster links free of rewriting proxies","Run identical NATS Server versions across the cluster"],"tags":["nats-server","protocol","routing","message-parsing"],"backgroundTag":"protocol-size-mismatch","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}