{"record":{"id":"3862f358869afa9c","repo":"Hmbown/CodeWhale","slug":"codewhale-owned-credential-file-exceeds-the","errorCode":null,"errorMessage":"Codewhale-owned credential file {} exceeds the {} byte safety limit","messagePattern":"Codewhale-owned credential file (.+?) exceeds the (.+?) byte safety limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/external_credentials.rs","lineNumber":126,"sourceCode":"                format!(\n                    \"securely opening Codewhale-owned credential file {}\",\n                    codewhale_config::quote_os_path(path)\n                )\n            });\n        }\n    };\n    let mut bytes = Vec::new();\n    file.by_ref()\n        .take(MAX_EXTERNAL_CREDENTIAL_BYTES + 1)\n        .read_to_end(&mut bytes)\n        .with_context(|| {\n            format!(\n                \"reading Codewhale-owned credential file {}\",\n                codewhale_config::quote_os_path(path)\n            )\n        })?;\n    if bytes.len() as u64 > MAX_EXTERNAL_CREDENTIAL_BYTES {\n        bail!(\n            \"Codewhale-owned credential file {} exceeds the {} byte safety limit\",\n            codewhale_config::quote_os_path(path),\n            MAX_EXTERNAL_CREDENTIAL_BYTES\n        );\n    }\n    String::from_utf8(bytes).map(Some).with_context(|| {\n        format!(\n            \"Codewhale-owned credential file {} is not valid UTF-8\",\n            codewhale_config::quote_os_path(path)\n        )\n    })\n}\n\n#[cfg(unix)]\nfn open_secure_regular_file(path: &Path, require_owner_only: bool) -> io::Result<File> {\n    use std::ffi::CString;\n    use std::os::fd::FromRawFd;\n    use std::os::unix::ffi::OsStrExt;","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/external_credentials.rs#L108-L144","documentation":"read_codewhale_owned_to_string applies the same bounded-read guard as the external-grant reader to files owned by Codewhale itself (below its credentials directory). If the file is larger than MAX_EXTERNAL_CREDENTIAL_BYTES, the read fails closed instead of returning the contents, protecting against corrupted or hijacked credential files.","triggerScenarios":"Reading a Codewhale-owned credential file (e.g. a stored token or key file under Codewhale's credentials directory) whose byte length exceeds MAX_EXTERNAL_CREDENTIAL_BYTES — as exercised by owned_read_is_bounded and owned_read_is_bounded_on_windows.","commonSituations":"The credential file was corrupted or appended to repeatedly by a faulty writer; something else (a log, a bundle) was written at that basename; a sync tool merged conflicting versions into one large file.","solutions":["Inspect the file at the path in the message; delete and re-authenticate so Codewhale rewrites a fresh credential file.","Find what is growing the file (concurrent writers, sync conflict copies) and stop it before re-creating the credential.","Ensure only Codewhale writes under its credentials directory; don't redirect other outputs there.","Restore the file from a known-good backup if available, keeping size within the limit."],"exampleFix":"// before: token file grown to megabytes by repeated appends\n$ rm ~/.codewhale/credentials/<file> && codewhale auth login   // recreated within limit","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(path)?;\nif meta.len() > codewhale::tui::external_credentials::MAX_EXTERNAL_CREDENTIAL_BYTES {\n    eprintln!(\"owned credential file oversized, re-auth required: {}\", path.display());\n}","typeGuard":null,"tryCatchPattern":"match read_codewhale_owned_to_string(path) {\n    Ok(Some(contents)) => use_token(contents),\n    Ok(None) => reauthenticate(),\n    Err(e) if e.to_string().contains(\"exceeds\") => { delete_and_reauth(path); }\n    Err(e) => return Err(e),\n}","preventionTips":["Only Codewhale should write under its credentials directory; redirect other outputs elsewhere.","Disable file-sync tools on the credentials directory to avoid conflict-copy bloat.","On this error, delete the file and re-authenticate rather than trying to repair it in place."],"tags":["credentials","file-size","security","fail-closed"],"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"}