{"record":{"id":"58805af9f2394bf9","repo":"Hmbown/CodeWhale","slug":"refusing-oversized-xai-oauth-credential-payload","errorCode":null,"errorMessage":"refusing oversized xAI OAuth credential payload","messagePattern":"refusing oversized xAI OAuth credential payload","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/xai_credentials.rs","lineNumber":263,"sourceCode":"            })?;\n        if bytes.len() as u64 > XAI_OAUTH_FILE_LIMIT {\n            bail!(\n                \"Codewhale-owned xAI OAuth file {} exceeds the {} byte limit\",\n                crate::quote_os_path(&self.directory.join(name)),\n                XAI_OAUTH_FILE_LIMIT\n            );\n        }\n        String::from_utf8(bytes).map(Some).map_err(|_| {\n            anyhow::anyhow!(\n                \"Codewhale-owned xAI OAuth file {} is not valid UTF-8\",\n                crate::quote_os_path(&self.directory.join(name))\n            )\n        })\n    }\n\n    pub fn write(&self, name: &str, bytes: &[u8], allow_replace: bool) -> Result<()> {\n        validate_owned_auth_name(name)?;\n        anyhow::ensure!(\n            bytes.len() as u64 <= XAI_OAUTH_FILE_LIMIT,\n            \"refusing oversized xAI OAuth credential payload\"\n        );\n        self.write_owned_file(name, bytes, allow_replace)\n    }\n\n    pub fn remove(&self, name: &str) -> Result<bool> {\n        validate_owned_auth_name(name)?;\n        self.remove_raw(name)\n    }\n\n    pub fn clear_all(&self) -> Result<usize> {\n        let mut removed = 0;\n        for name in self.owned_auth_names()? {\n            if self.remove(&name)? {\n                removed += 1;\n            }\n        }","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/config/src/xai_credentials.rs#L245-L281","documentation":"write() refuses any payload larger than XAI_OAUTH_FILE_LIMIT bytes before touching disk. The credential store enforces a hard size ceiling on the files it owns to bound read sizes and prevent abuse. The write is aborted with no file created or replaced.","triggerScenarios":"Calling XaiOAuthCredentialStore::write with a bytes slice whose length as u64 exceeds XAI_OAUTH_FILE_LIMIT.","commonSituations":"Passing an entire OAuth token response JSON instead of just the token file contents; accidentally writing a bundle of credentials; a bug concatenating files.","solutions":["Trim the payload to only the credential document the store expects.","Check bytes.len() against the limit before calling and surface a clearer application-level error.","Split oversized data into separate storage outside the credential store.","Update the caller that is assembling the payload if it recently changed."],"exampleFix":"// before\nstore.write(name, entire_response_body.as_bytes(), true)?;\n// after\nanyhow::ensure!(entire_response_body.len() < XAI_OAUTH_FILE_LIMIT, \"payload too large\");\nstore.write(name, token_document.as_bytes(), true)?;","handlingStrategy":"validation","validationCode":"anyhow::ensure!(payload.len() as u64 <= XAI_OAUTH_FILE_LIMIT, \"payload {} exceeds limit\", payload.len());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write only the minimal credential document, not whole API responses","Check payload size in tests that construct token blobs","Assert byte lengths after any JSON transformation before writing"],"tags":["file-size","credentials","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}