{"id":"a2f6e24f7a5f60cc","repo":"gofiber/fiber","slug":"boundary-generation-w","errorCode":null,"errorMessage":"boundary generation: %w","messagePattern":"boundary generation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"client/hooks.go","lineNumber":153,"sourceCode":"\n\t// Set Content-Type and Accept headers based on the request body type.\n\tswitch req.bodyType {\n\tcase jsonBody:\n\t\treq.RawRequest.Header.SetContentType(applicationJSON)\n\t\treq.RawRequest.Header.Set(headerAccept, applicationJSON)\n\tcase xmlBody:\n\t\treq.RawRequest.Header.SetContentType(applicationXML)\n\tcase cborBody:\n\t\treq.RawRequest.Header.SetContentType(applicationCBOR)\n\tcase formBody:\n\t\treq.RawRequest.Header.SetContentType(applicationForm)\n\tcase filesBody:\n\t\treq.RawRequest.Header.SetContentType(multipartFormData)\n\t\t// If boundary is default, append a random string to it.\n\t\tif req.boundary == boundary {\n\t\t\trandStr, err := unsafeRandString(16)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"boundary generation: %w\", err)\n\t\t\t}\n\t\t\treq.boundary += randStr\n\t\t}\n\t\treq.RawRequest.Header.SetMultipartFormBoundary(req.boundary)\n\tdefault:\n\t\t// noBody or rawBody do not require special handling here.\n\t}\n\n\t// Set User-Agent header.\n\treq.RawRequest.Header.SetUserAgent(defaultUserAgent)\n\tif c.userAgent != \"\" {\n\t\treq.RawRequest.Header.SetUserAgent(c.userAgent)\n\t}\n\tif req.userAgent != \"\" {\n\t\treq.RawRequest.Header.SetUserAgent(req.userAgent)\n\t}\n\n\t// Set Referer header.","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/client/hooks.go#L135-L171","documentation":"Returned in parserRequestHeader (client/hooks.go:153) when unsafeRandString fails while generating the random suffix appended to the default multipart boundary for a filesBody request. It is a thin wrapper around the underlying rand.Read failure (errors 84/85). The boundary is only auto-generated when the request still uses the default boundary constant 'FiberFormBoundary'.","triggerScenarios":"Sending a multipart file upload (Request.SetFiles) without a custom boundary, on a host where crypto/rand.Read fails. The header-preparation hook tries to build boundary = 'FiberFormBoundary' + randomString(16) and returns this wrapped error.","commonSituations":"Same CSPRNG-unavailability contexts as errors 84/85 (locked-down container, missing /dev/urandom, blocked getrandom syscall), specifically manifesting during the header-building phase of a file upload.","solutions":["Fix the environment so crypto/rand works (expose /dev/urandom, allow getrandom).","As a workaround, set an explicit boundary via Request.SetBoundary so unsafeRandString is skipped.","Treat the error as fatal/infra-level — retrying on the same host will keep failing."],"exampleFix":"// before — relies on auto-generated boundary, fails without /dev/urandom\nclient.R().SetFiles(\"./a.txt\").Get(url)\n\n// after — set a boundary explicitly to bypass unsafeRandString\nclient.R().SetBoundary(\"MyAppBoundary123\").SetFiles(\"./a.txt\").Get(url)","handlingStrategy":"fallback","validationCode":"// Detect CSPRNG unavailability before attempting uploads.\nfunc canGenerateBoundary() bool {\n    return rand.Read(make([]byte, 1)) == nil\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.R().SetFiles(f).Get(url)\nif err != nil && strings.Contains(err.Error(), \"boundary generation\") {\n    // rand unavailable — retry with an explicit boundary\n    resp, err = client.R().SetBoundary(\"ManualBoundary\").SetFiles(f).Get(url)\n}","preventionTips":["Ensure /dev/urandom is available in the deployment environment.","Set an explicit boundary via Request.SetBoundary when randomness cannot be guaranteed.","Treat boundary-generation errors as infrastructure faults, not transient network errors."],"tags":["client","multipart","boundary","crypto-rand"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}