fix(cron): check binary magic bytes instead of bare NUL for lifecycle guard (#77927) - #78083
Closed
RelaxJonh wants to merge 1 commit into
Closed
fix(cron): check binary magic bytes instead of bare NUL for lifecycle guard (#77927)#78083RelaxJonh wants to merge 1 commit into
RelaxJonh wants to merge 1 commit into
Conversation
… 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
Collaborator
Duplicate of #77928 — both repair the lifecycle guard's NUL-padded text-script bypass by distinguishing actual binary magic from an embedded NUL. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #77927. The
b"\x00" in datacheck in_read_referenced_script()treated any file containing a NUL byte as a compiled binary and skipped scanning. Butbashexecutes 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 (
ValueErrorfromPath.resolveon 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 datacheck with magic-byte detection via_is_known_binary_format():\x7fELF, Mach-O, PEMZ, Java class, WebAssembly): skip as before — binaries are not referenced shell scripts.\x00): strip NULs from the data before decoding, so downstreamPath.resolveand regex matching cannot raiseValueError.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