Hmbown/CodeWhale · error

xAI OAuth path must be a regular file

Error message

xAI OAuth path must be a regular file

What it means

validate_owned_file_handle stats the opened file and requires it to be a regular file. This blocks directories, FIFOs, devices, and symlinks-to-weird-things from being used as credential storage, closing TOCTOU holes where a path could swap between open and use.

Solutions

  1. Delete the non-regular path and re-authenticate so the store recreates a plain file.
  2. Ensure nothing in the environment creates symlinks or FIFOs in the credentials directory (sync tools, dotfile managers).
  3. Do not point the store at special filesystem paths (devices, procfs).
  4. Pre-check with symlink_metadata in your setup if the directory is not fully trusted.

Example fix

// before
let store = store.read_to_string(name)?; // fails: path is a FIFO
// after
let md = std::fs::symlink_metadata(dir.join(name))?;
anyhow::ensure!(md.is_file(), "credential path must be a regular file");
Defensive patterns

Strategy: validation

Validate before calling

let md = std::fs::symlink_metadata(path)?;
anyhow::ensure!(md.is_file(), "credential path must be a regular file, not symlink/FIFO");

Prevention

When it happens

Trigger: Any of read_to_string, write_owned_file, remove_raw, rename_raw, or the internal/windows openers encountering a path that resolved to something other than a regular file at open time — e.g. an attacker replaced the credential file with a FIFO or symlink.

Common situations: A symlink placed where the token file should be; a named pipe created by a mischievous script in the credentials dir; /dev-style device paths configured as the credential path.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/e88d24a1feb5495a. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/xai_credentials.rs:902

            )
        } != 0
        {
            return Err(std::io::Error::last_os_error()).context("retiring xAI OAuth file");
        }
        Ok(())
    }
}

#[cfg(unix)]
fn validate_owned_file_handle(file: &File, path: &Path) -> Result<fs::Metadata> {
    use std::os::unix::fs::MetadataExt as _;
    let metadata = file.metadata().with_context(|| {
        format!(
            "inspecting Codewhale-owned xAI OAuth file {}",
            crate::quote_os_path(path)
        )
    })?;
    anyhow::ensure!(metadata.is_file(), "xAI OAuth path must be a regular file");
    // SAFETY: geteuid(2) dereferences no pointers.
    anyhow::ensure!(
        metadata.uid() == unsafe { libc::geteuid() },
        "xAI OAuth file must be owned by the current user"
    );
    anyhow::ensure!(
        metadata.nlink() == 1,
        "xAI OAuth file must not have multiple filesystem links"
    );
    Ok(metadata)
}

#[cfg(windows)]
fn open_owned_credentials_directory(directory: &Path) -> Result<XaiOAuthCredentialStore> {
    use std::os::windows::fs::OpenOptionsExt as _;
    use windows_sys::Win32::Storage::FileSystem::{
        FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, FILE_GENERIC_READ,
        FILE_SHARE_READ, FILE_SHARE_WRITE, WRITE_DAC, WRITE_OWNER,

View on GitHub (pinned to 73e0f67d83)