{"record":{"id":"a6d02ead62d73cd0","repo":"Hmbown/CodeWhale","slug":"reviewed-plugin-executable-bytes-changed-before-sp","errorCode":null,"errorMessage":"reviewed plugin executable bytes changed before spawn","messagePattern":"reviewed plugin executable bytes changed before spawn","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/tui/src/mcp.rs","lineNumber":1027,"sourceCode":"        let mut hasher = sha2::Sha256::new();\n        hasher.update(b\"codewhale-plugin-file-bytes-v1\\0\");\n        let mut buffer = [0_u8; 64 * 1024];\n        loop {\n            let read = file\n                .read(&mut buffer)\n                .context(\"read reviewed launch file\")?;\n            if read == 0 {\n                break;\n            }\n            hasher.update(&buffer[..read]);\n        }\n        let actual = hasher\n            .finalize()\n            .iter()\n            .map(|byte| format!(\"{byte:02x}\"))\n            .collect::<String>();\n        if &actual != expected {\n            anyhow::bail!(\"reviewed plugin executable bytes changed before spawn\");\n        }\n        file.seek(std::io::SeekFrom::Start(0))\n            .context(\"rewind reviewed launch file after verification\")?;\n\n        #[cfg(unix)]\n        let launch_path = {\n            use std::os::fd::AsRawFd as _;\n            let fd = file.as_raw_fd();\n            // SAFETY: `fd` is owned by `file`; clearing only FD_CLOEXEC keeps\n            // that same descriptor available across the imminent exec.\n            let flags = unsafe { libc::fcntl(fd, libc::F_GETFD) };\n            if flags < 0 || unsafe { libc::fcntl(fd, libc::F_SETFD, flags & !libc::FD_CLOEXEC) } < 0\n            {\n                anyhow::bail!(\"failed to inherit reviewed plugin executable descriptor\");\n            }\n            #[cfg(target_os = \"linux\")]\n            let prefix = \"/proc/self/fd\";\n            #[cfg(not(target_os = \"linux\"))]","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L1009-L1045","documentation":"bind_file hashes the reviewed plugin's executable file bytes and compares them to the digest recorded at review time. This error means the on-disk executable no longer matches the reviewed hash, so spawning it would execute unreviewed code. It is a pre-spawn integrity check against binary tampering or replacement.","triggerScenarios":"bind_file (called from prepare_stdio_launch and bind_command) finalizes a SHA-based hasher over the launch file and bails when the computed hex digest differs from the expected hash. Any byte-level change to the executable between review and spawn triggers it.","commonSituations":"Package manager or plugin auto-update replaced the binary; a build tool rebuilt the executable with different bytes; antivirus or disk issues corrupted the file; symlink was retargeted to a different binary.","solutions":["Re-review / re-approve the plugin so the recorded hash matches the current executable, after verifying the new binary is authentic","Restore the original reviewed binary (reinstall the pinned plugin version) so the hash matches again","Pin the plugin to an immutable version or checksum-verified install method so updates cannot silently change bytes"],"exampleFix":"# before\n$ sha256sum $(which plugin)  # abc123... but reviewed hash is def456...\n# after\n$ codewhale plugin re-approve --path $(which plugin)  # records new hash after verification\n# or reinstall the pinned version:\n$ pkg install plugin==1.2.3","handlingStrategy":"validation","validationCode":"import hashlib\n\ndef executable_matches_reviewed(path: str, expected_sha256: str) -> bool:\n    return hashlib.sha256(open(path, 'rb').read()).hexdigest() == expected_sha256","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install plugins from checksum-verified, pinned releases so binaries never drift","Treat a hash mismatch as a security event: verify the new binary's provenance before re-approving","Disable plugin auto-update if you require review-before-spawn"],"tags":["security","integrity","hash-mismatch","mcp"],"backgroundTag":"checksum-mismatch","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"}