Hmbown/CodeWhale · error
invalid Codewhale-owned xAI OAuth basename
Error message
invalid Codewhale-owned xAI OAuth basename
What it means
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.
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
Example fix
// before
store.write("xai-auth-backup.json", body.as_bytes(), false)?;
// after
let name = format!("xai-auth-{id:032x}.json");
assert!(is_valid_xai_oauth_generation(&name));
store.write(&name, body.as_bytes(), false)?; Defensive patterns
Strategy: type-guard
Validate before calling
use codewhale_config::xai::{is_valid_xai_oauth_generation, LEGACY_XAI_OAUTH_FILE_NAME};
fn ensure_valid_auth_name(name: &str) -> anyhow::Result<()> {
anyhow::ensure!(
name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name),
"bad credential basename: {name}"
);
Ok(())
} Type guard
fn is_valid_owned_auth_name(name: &str) -> bool {
name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name)
} Try / catch
match store.write(&name, bytes, false) {
Err(e) if e.to_string().contains("invalid Codewhale-owned xAI OAuth basename") => {
let name = format!("xai-auth-{id:032x}.json");
store.write(&name, bytes, false)
}
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- agy OAuth token JSON carries no access token member
- agy OAuth token member
- atomically replacing xAI OAuth credentials
- bearer credentials are not an API key
- Codewhale-owned OAuth credentials at
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/5bfae6958120e8b7.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/xai_credentials.rs:431
/// Permanently remove retired bytes after the replacement config commits.
pub fn commit(self, store: &XaiOAuthCredentialStore) -> Result<usize> {
let mut removed = 0;
for (_original, _tombstone) in self.retired {
#[cfg(windows)]
let target = _original;
#[cfg(not(windows))]
let target = _tombstone;
if store.remove_raw(&target)? {
removed += 1;
}
}
Ok(removed)
}
}
fn validate_owned_auth_name(name: &str) -> Result<()> {
anyhow::ensure!(
name == LEGACY_XAI_OAUTH_FILE_NAME || is_valid_xai_oauth_generation(name),
"invalid Codewhale-owned xAI OAuth basename"
);
Ok(())
}
fn validate_private_basename(name: &str) -> Result<()> {
let path = Path::new(name);
anyhow::ensure!(
path.components().count() == 1
&& matches!(path.components().next(), Some(Component::Normal(_)))
&& path.file_name().and_then(|value| value.to_str()) == Some(name),
"xAI OAuth private basename must be one UTF-8 path component"
);
Ok(())
}
#[cfg(unix)]View on GitHub (pinned to 0c42157ee5)