{"record":{"id":"5bfae6958120e8b7","repo":"Hmbown/CodeWhale","slug":"invalid-codewhale-owned-xai-oauth-basename","errorCode":null,"errorMessage":"invalid Codewhale-owned xAI OAuth basename","messagePattern":"invalid Codewhale-owned xAI OAuth basename","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/xai_credentials.rs","lineNumber":431,"sourceCode":"\n    /// Permanently remove retired bytes after the replacement config commits.\n    pub fn commit(self, store: &XaiOAuthCredentialStore) -> Result<usize> {\n        let mut removed = 0;\n        for (_original, _tombstone) in self.retired {\n            #[cfg(windows)]\n            let target = _original;\n            #[cfg(not(windows))]\n            let target = _tombstone;\n            if store.remove_raw(&target)? {\n                removed += 1;\n            }\n        }\n        Ok(removed)\n    }\n}\n\nfn validate_owned_auth_name(name: &str) -> Result<()> {\n    anyhow::ensure!(\n        name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name),\n        \"invalid Codewhale-owned xAI OAuth basename\"\n    );\n    Ok(())\n}\n\nfn validate_private_basename(name: &str) -> Result<()> {\n    let path = Path::new(name);\n    anyhow::ensure!(\n        path.components().count() == 1\n            && matches!(path.components().next(), Some(Component::Normal(_)))\n            && path.file_name().and_then(|value| value.to_str()) == Some(name),\n        \"xAI OAuth private basename must be one UTF-8 path component\"\n    );\n    Ok(())\n}\n\n#[cfg(unix)]","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/config/src/xai_credentials.rs#L413-L449","documentation":"The store accepts exactly two filename shapes for owned credential files: the legacy name xai-auth.json, or a generation name xai-auth-<exactly 32 lowercase hex chars>.json (is_valid_xai_oauth_generation, xai_credentials.rs:53). read/write/remove validate the basename first (xai_credentials.rs:431) so no caller-controlled string reaches a path join.","triggerScenarios":"Passing a custom basename to XaiOAuthCredentialStore::write/read/remove: 'auth.json', 'xai-auth-abc.json' (id not 32 chars), uppercase hex, embedded separators, or any name other than the legacy file or a well-formed generation name.","commonSituations":"Client code inventing its own generation naming scheme; a UUID formatter emitting uppercase or braced ids; truncating or reformatting the 32-char id; ported code that used arbitrary filenames.","solutions":["Build names with the crate's public helpers: LEGACY_XAI_OAUTH_FILE_NAME or format!(\"xai-auth-{id:032x}.json\") with a lowercase 32-hex id","Validate with the public is_valid_xai_oauth_generation() before calling the store","Centralize generation-name creation in one function so no call site improvises a format"],"exampleFix":"// before\nstore.write(\"xai-auth-backup.json\", body.as_bytes(), false)?;\n\n// after\nlet name = format!(\"xai-auth-{id:032x}.json\");\nassert!(is_valid_xai_oauth_generation(&name));\nstore.write(&name, body.as_bytes(), false)?;","handlingStrategy":"type-guard","validationCode":"use codewhale_config::xai::{is_valid_xai_oauth_generation, LEGACY_XAI_OAUTH_FILE_NAME};\n\nfn ensure_valid_auth_name(name: &str) -> anyhow::Result<()> {\n    anyhow::ensure!(\n        name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name),\n        \"bad credential basename: {name}\"\n    );\n    Ok(())\n}","typeGuard":"fn is_valid_owned_auth_name(name: &str) -> bool {\n    name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name)\n}","tryCatchPattern":"match store.write(&name, bytes, false) {\n    Err(e) if e.to_string().contains(\"invalid Codewhale-owned xAI OAuth basename\") => {\n        let name = format!(\"xai-auth-{id:032x}.json\");\n        store.write(&name, bytes, false)\n    }\n    other => other,\n}","preventionTips":["Create generation names in exactly one helper using format!(\"xai-auth-{id:032x}.json\")","Unit-test the name generator against is_valid_xai_oauth_generation","Never accept filenames from user input at this boundary"],"tags":["filename-validation","credentials","oauth","codewhale"],"backgroundTag":"invalid-filename","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}