Skip to content

fix(cron): check binary magic bytes instead of bare NUL for lifecycle guard (#77927) - #78083

Closed
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/lifecycle-guard-nul-bypass-77927
Closed

fix(cron): check binary magic bytes instead of bare NUL for lifecycle guard (#77927)#78083
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/lifecycle-guard-nul-bypass-77927

Conversation

@RelaxJonh

Copy link
Copy Markdown
Contributor

Summary

Fixes #77927. The b"\x00" in data check in _read_referenced_script() treated any file containing a NUL byte as a compiled binary and skipped scanning. But bash executes text scripts straight past embedded NULs, so a single pad byte lets a script bypass the lifecycle guard entirely.

Root Cause

The #76762 fix traded a loud failure (ValueError from Path.resolve on NUL bytes) for a silent one: the guard allows the command. The gap is between "contains a NUL" and "is a compiled binary" — those are different questions.

Fix

Replace the bare b"\x00" in data check with magic-byte detection via _is_known_binary_format():

  • Known binary (ELF \x7fELF, Mach-O, PE MZ, Java class, WebAssembly): skip as before — binaries are not referenced shell scripts.
  • Unknown format with NULs (text script with stray \x00): strip NULs from the data before decoding, so downstream Path.resolve and regex matching cannot raise ValueError.

Changes

  • cron/lifecycle_guard.py: Add _is_known_binary_format() helper; update _read_referenced_script() to distinguish real binaries from NUL-padded text scripts.

Testing

# NUL-padded script is now scanned (not skipped)
echo -e '#!/bin/bash\n\x00hermes gateway restart' > /tmp/test.sh
# Before: returns None (skipped) — guard allows the command
# After: returns text with lifecycle command detected — guard blocks

# ELF binary is still correctly skipped
cp /usr/bin/ls /tmp/test.bin
# Returns None, False (correct — not a shell script)

… guard (NousResearch#77927)

The NUL-byte check in _read_referenced_script treated ANY file containing
a NUL byte as a compiled binary and skipped scanning. But bash executes
text scripts straight past embedded NULs, so a single pad byte lets a
script bypass the lifecycle guard entirely.

Fix: check well-known binary magic bytes (ELF, Mach-O, PE, Java class,
WebAssembly) to distinguish real binaries from NUL-padded text scripts.
Non-binary files with NULs have them stripped before decoding so
downstream Path.resolve and regex matching cannot raise ValueError.

Fixes NousResearch#77927
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management duplicate This issue or pull request already exists labels Aug 4, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #77928 — both repair the lifecycle guard's NUL-padded text-script bypass by distinguishing actual binary magic from an embedded NUL.

@RelaxJonh RelaxJonh closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lifecycle_guard: NUL-padded text script bypasses the scan (regression from #76762 binary check)

3 participants