{"record":{"id":"b6a34c371b49f1ff","repo":"epi052/feroxbuster","slug":"request-headers-contain-invalid-utf-8","errorCode":null,"errorMessage":"Request headers contain invalid UTF-8","messagePattern":"Request headers contain invalid UTF-8","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/config/utils.rs","lineNumber":467,"sourceCode":"            if c <= l {\n                (c, 4)\n            } else {\n                (l, 2)\n            }\n        }\n        (Some(c), None) => (c, 4),\n        (None, Some(l)) => (l, 2),\n        (None, None) => bail!(\"Invalid request: Missing head/body separator\"),\n    };\n\n    // split the request head and body\n    let head_bytes = &contents[..sep_idx];\n    let body_bytes = &contents[sep_idx + sep_len..];\n\n    // decode only the head; HTTP framing is generally ascii/utf-8\n    // compatible\n    let head = std::str::from_utf8(head_bytes)\n        .map_err(|_| anyhow::anyhow!(\"Request headers contain invalid UTF-8\"))?;\n\n    // normalize line endings in the decoded head\n    let normalized = head.replace(\"\\r\\n\", \"\\n\");\n\n    // we only want to use the request's body bytes if the user hasn't\n    // overridden it on the cli\n    if config.data.is_empty() {\n        config.data = body_bytes.to_vec();\n    }\n\n    // begin parsing the request line and normalized headers\n    let mut head_parts = normalized.split(\"\\n\");\n\n    let Some(request_line) = head_parts.next() else {\n        bail!(\"Invalid request: Missing request line\");\n    };\n\n    if request_line.is_empty() {","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/epi052/feroxbuster/blob/1f595dab5c76858d5a14fbc47dabf2563d729c62/src/config/utils.rs#L449-L485","documentation":"parse_request_file reads a raw HTTP request file and splits head from body. Only the head section is decoded as UTF-8 because HTTP framing is expected to be ascii/UTF-8 compatible; if the header bytes fail std::str::from_utf8, the function bails with this error.","triggerScenarios":"Providing a raw request file whose header section (everything before the head/body separator) contains bytes that are not valid UTF-8 — e.g. Latin-1 encoded headers, binary data, or a separator misdetection that pulls binary body bytes into the head.","commonSituations":"Exporting a request from a proxy in raw binary form, copying a request with non-UTF-8 encodings, or saving a request with a compressed/binary body and no proper blank-line separator so the split index lands inside binary data.","solutions":["Re-save the request file as UTF-8 (or plain ASCII) without BOM or binary content in the header section","Ensure headers and body are separated by a proper blank line (\\r\\n\\r\\n) so binary body bytes are not treated as headers","Remove any binary/compressed body from the file and supply the body via the CLI instead"],"exampleFix":"// before\n\"POST / HTTP/1.1\\r\\nHost: x\\r\\n\\xff\\xfe\" // invalid bytes in head\n// after\n\"POST / HTTP/1.1\\r\\nHost: x\\r\\n\\r\\n\" // clean head; body via --data","handlingStrategy":"validation","validationCode":"let bytes = std::fs::read(path)?;\nlet head_end = find_separator(&bytes); // locate \\r\\n\\r\\n\nstd::str::from_utf8(&bytes[..head_end]).map_err(|_| anyhow!(\"headers are not UTF-8\"))?;","typeGuard":"fn is_utf8_head(bytes: &[u8], sep_idx: usize) -> bool { std::str::from_utf8(&bytes[..sep_idx]).is_ok() }","tryCatchPattern":"match parse_request_file(path) { Err(e) if e.to_string().contains(\"invalid UTF-8\") => eprintln!(\"re-save request file as UTF-8\"), Err(e) => return Err(e), Ok(cfg) => use(cfg) }","preventionTips":["Save raw request files as UTF-8/ASCII","Separate headers from binary bodies with a proper blank line","Pass bodies via CLI flags instead of embedding binary data in the request file"],"tags":["encoding","utf8","http","request-file"],"backgroundTag":"invalid-argument-format","analyzedSha":"1f595dab5c76858d5a14fbc47dabf2563d729c62","analyzedAt":"2026-09-13T19:33:06.208Z","contentChangedAt":"2026-09-13T19:33:06.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}