{"record":{"id":"9b7db86d1371ff98","repo":"cloudflare/cloudflared","slug":"invalid-request-id-length-provided","errorCode":null,"errorMessage":"invalid request id length provided","messagePattern":"invalid request id length provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/request.go","lineNumber":15,"sourceCode":"package v3\n\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n)\n\nconst (\n\tdatagramRequestIdLen = 16\n)\n\nvar (\n\t// ErrInvalidRequestIDLen is returned when the provided request id can not be parsed from the provided byte slice.\n\tErrInvalidRequestIDLen error = errors.New(\"invalid request id length provided\")\n\t// ErrInvalidPayloadDestLen is returned when the provided destination byte slice cannot fit the whole request id.\n\tErrInvalidPayloadDestLen error = errors.New(\"invalid payload size provided\")\n)\n\n// RequestID is the request-id-v2 identifier, it is used to distinguish between specific flows or sessions proxied\n// from the edge to cloudflared.\ntype RequestID uint128\n\ntype uint128 struct {\n\thi uint64\n\tlo uint64\n}\n\n// RequestIDFromSlice reads a request ID from a byte slice.\nfunc RequestIDFromSlice(data []byte) (RequestID, error) {\n\tif len(data) != datagramRequestIdLen {\n\t\treturn RequestID{}, ErrInvalidRequestIDLen\n\t}","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/request.go#L1-L33","documentation":"ErrInvalidRequestIDLen is returned by RequestIDFromSlice in quic/v3/request.go when the input byte slice is not exactly 16 bytes (datagramRequestIdLen). RequestID is a 128-bit (request-id-v2) identifier used to distinguish proxied flows/sessions between the edge and cloudflared, so it can only be parsed from exactly 16 bytes. The library throws this instead of guessing/truncating to keep request IDs lossless.","triggerScenarios":"Calling v3.RequestIDFromSlice with a slice whose len != 16: e.g. passing a truncated datagram payload, a payload with a header/length prefix not stripped, an empty slice, or a 64-bit request ID produced by an older edge protocol version.","commonSituations":"Parsing a QUIC datagram that was truncated in transit; mixing cloudflared versions where edge sends request-id-v1 (8-byte) payloads but the local library expects request-id-v2 (16-byte); hand-crafting test payloads of the wrong size; reading a fixed-size record from a stream and miscounting the offset.","solutions":["Check len(data) == 16 before calling RequestIDFromSlice and fix the caller that produces a shorter/longer slice.","Strip any datagram header/length prefix so the slice starts exactly at the 16-byte request id.","Verify both sides use the same request-id version (request-id-v2, 16 bytes); upgrade cloudflared/edge consistently.","If handling variable-size payloads, guard with a length check and return a descriptive error instead of panicking on the sentinel."],"exampleFix":"// before\nreqID, err := v3.RequestIDFromSlice(payload[:8])\n// after\nif len(payload) < v3.DatagramRequestIdLen { // or explicitly: len(payload[:16]) == 16\n    return fmt.Errorf(\"datagram too short: %d bytes\", len(payload))\n}\nreqID, err := v3.RequestIDFromSlice(payload[:16])","handlingStrategy":"validation","validationCode":"if len(data) != 16 {\n    return fmt.Errorf(\"request id must be 16 bytes, got %d\", len(data))\n}\nreqID, err := v3.RequestIDFromSlice(data)","typeGuard":"func isFullRequestID(b []byte) bool { return len(b) == 16 }","tryCatchPattern":"reqID, err := v3.RequestIDFromSlice(data)\nif errors.Is(err, v3.ErrInvalidRequestIDLen) {\n    // log payload length, skip or resync datagram framing\n    return err\n}","preventionTips":["Keep a single constant (16) for request-id size shared by producer and consumer code.","Strip datagram headers before slicing the request id.","Keep cloudflared and edge on matching request-id protocol versions."],"tags":["quic","datagram","request-id","length-check"],"backgroundTag":"invalid-argument-format","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}