{"record":{"id":"dc08a65fd103e240","repo":"Hmbown/CodeWhale","slug":"legacy-spillover-ownership-sidecar-must-not-be-a-s","errorCode":null,"errorMessage":"legacy spillover ownership sidecar must not be a symlink","messagePattern":"legacy spillover ownership sidecar must not be a symlink","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/truncate.rs","lineNumber":166,"sourceCode":"        digest: crate::hashing::sha256_hex(bytes),\n        size_bytes: bytes.len().try_into().unwrap_or(u64::MAX),\n    };\n    let sidecar = legacy_spillover_ownership_path(payload_path);\n    let encoded = serde_json::to_vec_pretty(&ownership)\n        .map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;\n    crate::utils::write_atomic(&sidecar, &encoded)?;\n    Ok(sidecar)\n}\n\npub(crate) fn read_legacy_spillover_ownership(\n    payload_path: &Path,\n) -> io::Result<LegacySpilloverOwnership> {\n    let sidecar = legacy_spillover_ownership_path(payload_path);\n    if std::fs::symlink_metadata(&sidecar)?\n        .file_type()\n        .is_symlink()\n    {\n        return Err(io::Error::new(\n            io::ErrorKind::PermissionDenied,\n            \"legacy spillover ownership sidecar must not be a symlink\",\n        ));\n    }\n    let ownership = serde_json::from_slice::<LegacySpilloverOwnership>(&std::fs::read(sidecar)?)\n        .map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;\n    if ownership.schema_version != LEGACY_SPILLOVER_OWNER_SCHEMA_VERSION {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"unsupported legacy spillover ownership schema\",\n        ));\n    }\n    Ok(ownership)\n}\n\n/// Resolve the spillover-file path for a SHA256 content hash. Separate\n/// namespace (`sha_<hex>.txt`) from the tool-call-id files so legacy\n/// SHA-addressed evidence can be recognized without colliding with","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/truncate.rs#L148-L184","documentation":"read_legacy_spillover_ownership performs a symlink check on the ownership sidecar via std::fs::symlink_metadata before reading it, refusing PermissionDenied with this message if the sidecar itself is a symlink. This is a security guard preventing an attacker from redirecting the ownership read to an arbitrary file through a planted symlink.","triggerScenarios":"read_legacy_spillover_ownership finding legacy_spillover_ownership_path(payload_path) exists as a symlink — e.g. a malicious file placed in a shared/artifact directory pointing the sidecar at /etc/passwd or another target.","commonSituations":"Shared or world-writable spillover directories where another user planted a symlink; build/test setups that symlink fixture directories; restore tools that recreated sidecars as links.","solutions":["Remove the symlinked sidecar and let the owning session republish it (`rm <sidecar>` then re-run the operation).","Ensure spillover/artifact directories are writable only by the owning user (chmod 700 / private temp dirs).","Audit how the sidecar directory was populated; do not symlink fixture or restore paths into it.","Keep the symlink check in place — recreate the file as a regular file, never as a link."],"exampleFix":"// before\nls -l spillover.json  # spillover.json -> /etc/passwd (symlink)\n// after\nrm spillover.json && chmod 700 $(dirname spillover.json)  # republish creates a regular file","handlingStrategy":"validation","validationCode":"// check before read\nlet meta = std::fs::symlink_metadata(path)?;\nif meta.file_type().is_symlink() { return Err(\"sidecar is a symlink; remove it\"); }","typeGuard":"fn is_regular_file(p: &std::path::Path) -> bool {\n    std::fs::symlink_metadata(p).map(|m| m.is_file()).unwrap_or(false)\n}","tryCatchPattern":"// rust\nmatch read_legacy_spillover_ownership(&payload) {\n    Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {\n        eprintln!(\"ownership sidecar is a symlink; remove it and republish\");\n    }\n    other => other?,\n}","preventionTips":["Keep spillover directories private to the owning user (0700) so symlinks cannot be planted.","Never symlink into artifact/spillover directories; copy fixtures as regular files.","Keep symlink (TOCTOU) checks on any path that is read after being resolved from user-reachable directories."],"tags":["security","symlink","file-read","permission"],"backgroundTag":"permission-denied","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"}