{"record":{"id":"3b1700475fd0f616","repo":"jdx/mise","slug":"unexpected-request-body","errorCode":null,"errorMessage":"unexpected request body","messagePattern":"unexpected request body","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/github_relay.rs","lineNumber":616,"sourceCode":"                .body(Body::from(\"GitHub relay request denied or unavailable\"))\n                .expect(\"valid response\"),\n        }\n    }\n\n    async fn forward(broker: Broker, request: Request) -> Result<Response> {\n        let deadline = tokio::time::Instant::now() + broker.audit.options.request_timeout;\n        let operation = broker.audit.operation(&broker.scope, &request);\n        let permit = broker.permits.clone().try_acquire_owned()?;\n        let target = authorize(\n            &broker.scope,\n            request.method().as_str(),\n            request.uri().path().strip_prefix('/').unwrap_or_default(),\n            request.uri().query(),\n        )?;\n        let (parts, body) = request.into_parts();\n        let body = to_bytes(body, 8 * 1024 * 1024).await?;\n        if parts.method != Method::POST && !body.is_empty() {\n            bail!(\"unexpected request body\");\n        }\n        let upstream = target.url.clone();\n        #[cfg(test)]\n        let upstream = if let Some(base) = &broker.test_upstream {\n            let url = Url::parse(&upstream)?;\n            format!(\n                \"{base}{}{}\",\n                url.path(),\n                url.query().map(|q| format!(\"?{q}\")).unwrap_or_default()\n            )\n        } else {\n            upstream\n        };\n        let mut req = broker.client.request(parts.method.clone(), upstream);\n        if target.git {\n            req = req.basic_auth(\"x-access-token\", Some(broker.token.as_str()));\n        } else {\n            req = req.bearer_auth(broker.token.as_str());","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/github_relay.rs#L598-L634","documentation":"In `forward`, every proxied request body is read (up to 8 MiB) and, unless the method is POST, the body must be empty. The relay only expects a body for the git smart-HTTP `git-upload-pack` POST; any GET/HEAD request carrying a body, or a non-POST method with payload bytes, is rejected as a protocol violation before anything is sent upstream.","triggerScenarios":"A client sends GET/HEAD with a body (some HTTP clients serialize params into a body); a chunked or buffered body survives on requests that should be bodiless; a client mistakenly POSTs metadata with a body on a path whose allowlisted method is GET.","commonSituations":"HTTP libraries that attach an empty-but-present body to GET requests; misconfigured clients sending JSON payloads with GET; middleware adding bodies (e.g. signing wrappers) to otherwise read-only requests.","solutions":["Remove the body from the request; read-only relayed operations must be bodiless GET/HEAD requests","Configure your HTTP client to not send a body (and no Content-Length/Transfer-Encoding) for GET/HEAD","Only `POST git/OWNER/REPO/git-upload-pack` may carry a body — route writes elsewhere","Check middleware/proxies for code that injects bodies into outgoing requests"],"exampleFix":"// before\nclient.get(url).body(\"\").send()?;\n// after\nclient.get(url).send()?;","handlingStrategy":"try-catch","validationCode":"fn body_is_permitted(method: &Method, body: &[u8]) -> bool {\n    (method == Method::POST) || body.is_empty()\n}\nassert!(body_is_permitted(&Method::GET, b\"\"));","typeGuard":null,"tryCatchPattern":"let result = async {\n    let target = authorize(&scope, method, path, query)?;\n    forward(target, request).await\n}.await;\nif let Err(e) = result {\n    if e.to_string().contains(\"unexpected request body\") {\n        eprintln!(\"drop the body: only POST git-upload-pack may carry one\");\n    }\n}","preventionTips":["Send GET/HEAD requests with no body and no Content-Length/Transfer-Encoding headers","Configure your HTTP client to omit empty bodies on read requests","Only the git-upload-pack POST should carry a payload","Audit middleware for code that attaches bodies to outgoing requests"],"tags":["github","relay","http","request-body","protocol"],"backgroundTag":"unexpected-request-body","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}