* feat(native): report binary hardening for ELF, PE and Mach-O Documents inspect_binary_hardening and its CLI equivalent, including per-property states, supporting evidence, read budgets, and one report per Mach-O slice. Explains that missing protection imports remain unknown, signature presence does not establish validity, and hardened runtime requires inspect_signature. Adds hardening links throughout the documentation. The supplied diff also removes the advanced CodeQL workflow and configuration, along with snapshot-binding mismatch guidance. * fix(native): validate declared payloads and dynamic tables before hardening rows Run the shared range checks for ELF, read imports from the dynamic tables rather than section metadata, and keep an unresolved symbol count apart from an absent table. Check every Mach-O command before building rows and retain only the offsets the rows need. Make the verifier's readelf output wide, check the emitted format before parsing Mach-O, and place the sources before the libraries in the link. * fix(native): share Mach-O segment admission with hardening reads A segment with a section count its cmdsize cannot hold passed the hardening reader and could enable restrict_segment. Move the size, section count and file range checks to a shared admission that readMachoImage and the hardening reader both use, and pin the ELF load-size case with a regression test. * fix(hardening): reject Mach-O section payloads past the slice and empty ELF interpreters Segment admission never checked each section's payload range, so a file-backed section past the slice still produced rows. Decode sections with the section header owner and mark the slice malformed when a payload leaves it; zero-fill and empty sections own no file bytes and are exempt. admitInterp accepted a NUL first byte in a longer extent, which counted an empty interpreter as PIE evidence. It now requires a nonempty path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KuWHGvzJkrhCqjtEHUwqyH * fix(native): read CFG instrumentation from decoded GuardFlags Use the IMAGE_GUARD_CF_INSTRUMENTED flag that guardFlagRecord already decodes instead of masking the raw GuardFlags word a second time. * fix(native): reject ELF table spans a second PT_LOAD remaps The hardening reader mapped DT_STRTAB, DT_SYMTAB and hash tables through the one PT_LOAD containing the table's first address. A second PT_LOAD starting inside the table could map the rest of it from other file bytes and the reader still reported parsed import evidence. Cap each mapping at the next PT_LOAD that starts inside it, reject a requested range that crosses that boundary, and stop hash reads at the same limit, matching the conflicting-mapping refusal in readElfSymbols. * fix(native): dedupe ELF note tables only on shared boundaries The hardening reader dropped any note table whose bytes another table already covered. A covering SHT_NOTE can hold a non-GNU note whose descriptor is itself a complete GNU property note, while PT_NOTE names that inner note directly. Walking only the outer stream missed the GNU marker and reported CET disabled. Drop an alias only when it starts and ends on boundaries of admitted tables, which are note boundaries of the walked streams. Any other covered alias leaves the feature rows unknown, as a partial overlap already does. * fix(native): admit every Mach-O symbol record after a canary match The Mach-O stack protector scan returned as soon as it found an undefined ___stack_chk_fail, so a later undefined symbol whose n_strx lay outside the string table was never checked. The same damaged table parsed or failed as malformed depending only on record order. Keep the match and finish the bounded record walk. Records after the match are only checked against the string table bounds, so their names are not read or charged to the scan budget. The ELF reader already admits its whole symbol table before matching names. * fix(native): accept ELF load aliases with the same file translation The hardening reader treated every PT_LOAD that starts inside a table, or that also contains the table's address, as a conflicting mapping. A load with the same address-to-file translation names the same file bytes, so tables it overlaps still have one interpretation, and the canonical ElfLoadMap already merges such spans. Treat equivalent loads as one interpretation. A load with a different translation, or the zero-filled tail of an equivalent load, still ends the usable range, so a remapped table is still rejected. * fix(native): keep same-span ELF note tables with different alignments unknown A section and a program header that share endpoints were treated as one note stream even when their effective note alignments differed. Walking the same bytes at 4 and 8 can frame different notes, so dropping the second table could hide a GNU property word and report CET or BTI as disabled. Require matching effective alignment at both endpoints, and no alignment change inside the covered span, before treating a table as an alias. Otherwise mark the feature rows unknown. The fixture's .note.gnu.property section now declares the class's note alignment, as toolchains emit it. * refactor(native): read LC_SYMTAB through the shared fixed-word decoder Move the Mach-O fixed uint32 command layouts out of MachoCommandNames into domain/apple/machoLoadCommands so there is one owner of those offsets. MachoCommandNames and the hardening reader now both decode through it; the hardening reader keeps its own bounds and import policy. * fix(native): skip Mach-O common definitions in canary imports A common definition sets N_UNDF|N_EXT like an import but stores its allocation size in n_value. An object holding only `int __stack_chk_fail;` therefore reported stack_protector: enabled. Require a zero n_value before an undefined external counts as an import, for both nlist widths. * refactor(native): read linkedit data commands through the shared fixed-word decoder readMachoLinkeditDataCommand reproduced the dataoff/datasize offsets that FIXED_WORD_FIELDS already owns. Take the command and decode through decodeMachoFixedWordFields, as readMachoSymtabCommand does, keeping the truncation and endianness behavior. * fix(native): skip empty SHT_NOTE sections in ELF hardening A zero-sized SHT_NOTE owns no bytes, so the section directory marks it not file-backed and the hardening reader rejected the whole image as malformed, while readElfImage accepted the same bytes. Skip empty note sections before the file-backing check; they have nothing to walk. * fix(scripts): run hardening verifier commands through the shared owner The binary hardening verifier started its probes and compiler drivers with raw spawnSync, which bypassed the src/process/ supervision that AGENTS.md requires. Every launch now goes through createVerifierCommands, and the temporary root is removed only after the owner closes cleanly. * fix(scripts): clean up hardening verifier commands on Ctrl-C SIGINT or SIGTERM ended Node before withVerifierCleanup ran, so detached compiler trees and the temporary root could outlive the verifier. The verifier now turns those signals into an abort that every owned command receives, so cleanup closes the owner and removes the root before exit. * fix(scripts): fail the hardening verifier when a signal lands outside a command Only the owned commands read the interruption signal, so a SIGINT or SIGTERM during the final cleanup or between commands was recorded and then dropped, and the verifier exited 0. After cleanup settles, the verifier now throws the interruption reason. A failure the operation or its cleanup already raised still leaves first and is not replaced. * fix(native): fail Mach-O slices with a malformed encryption command The hardening reader turned every malformed status from the shared encryption reader into an unknown `encrypted` row, so a short LC_ENCRYPTION_INFO_64 or an encrypted range past the slice still left the slice parsed with a full report. Only two conflicting encryption commands stay an unknown row now. Any other encryption defect fails the slice like other structural command failures. * fix(native): ignore STB_LOCAL undefined ELF symbols as imports A local undefined __stack_chk_fail or __memcpy_chk is never resolved against another object, so it does not establish an external import. Skip STB_LOCAL bindings when reading protector signs, and give the fixture's positive symbols STB_GLOBAL binding. --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
8.0 KiB
Binary hardening verification - 2026-10-31
Command: npm run verify:binary-hardening
package.json maps that script to node scripts/verify-binary-hardening.mjs.
The script loads its TypeScript sources with importVerifierSource. Its stderr
printed ExperimentalWarning: stripTypeScriptTypes is an experimental feature and might change at any time.
The process exited 0. No target was executed. readelf was not present, so
this run did not compare ELF rows with readelf output.
Host from the script JSON: darwin arm64. node was v24.22.1. The script's
npm -v line was 11.16.0.
Tools the script found
xcrun --find from the script:
| Name | Status | Path |
|---|---|---|
readelf |
72 | none |
llvm-readelf |
72 | none |
clang |
0 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang |
gcc |
0 | /Applications/Xcode.app/Contents/Developer/usr/bin/gcc |
cc |
0 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc |
ld |
0 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld |
The stored readelf stderr was xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find readelf 2> /dev/null' failed with exit code 17664: .
The stored llvm-readelf stderr was xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find llvm-readelf 2> /dev/null' failed with exit code 17.
The script keeps 240 characters of that stderr.
Compilers selected, with the version line the script ran:
| Name | Command | Version line |
|---|---|---|
gcc |
/usr/bin/gcc |
Apple clang version 21.0.0 (clang-2100.1.1.101) |
clang-linux-gnu |
/usr/bin/clang |
Apple clang version 21.0.0 (clang-2100.1.1.101) |
clang-linux-musl |
/usr/bin/clang |
Apple clang version 21.0.0 (clang-2100.1.1.101) |
zig-linux-gnu |
/opt/homebrew/bin/zig |
0.16.0 |
zig-linux-musl |
/opt/homebrew/bin/zig |
0.16.0 |
x86_64-linux-gnu-gcc, aarch64-linux-gnu-gcc, and musl-gcc were not in
that list. The script recorded elf-readelf: No readelf or llvm-readelf was found. Compiled ELF images are still parsed.
For each variant the script tries later compilers when an earlier one does not
emit the requested ELF feature. It stops that variant at the first ELF whose
parsed rows meet the feature. execstack needs NX disabled. stack-protector
needs stack_protector enabled. Other variants accept the first ELF. A
missing feature is recorded and does not fail the process. A present readelf
that disagrees still fails the process. This run had no readelf.
DT_NEEDED and build-id below are the script's own little-endian ELF reads,
because readelf was absent.
Synthetic PE
peHardeningImage() built a PE32+ fixture. readPeHardening reported bits 64
and these states:
| Property | State |
|---|---|
dynamic_base |
enabled |
high_entropy_va |
enabled |
nx_compat |
enabled |
force_integrity |
disabled |
no_seh |
disabled |
guard_cf |
enabled |
cfg_instrumented |
enabled |
authenticode_present |
disabled |
debug_record_present |
disabled |
ELF
/usr/bin/gcc compiled pie, no-pie, stack-protector, dynamic, and
two-needed, and the script skipped each with compiler did not emit ELF.
The same compiler exited 1 for relro-now, relro, no-relro, execstack,
and build-id. Those stderrs named unused -pie and ld: unknown options
for -z or --build-id=sha1.
/usr/bin/clang --target=x86_64-linux-gnu and
/usr/bin/clang --target=x86_64-linux-musl exited 1 for every variant. The
pie stderr was ld: unknown options: --hash-style=gnu --eh-frame-hdr -dynamic-linker --as-needed --no-as-needed --as-needed --no-as-needed and
clang: error: linker command failed with exit code 1 (use -v to see invocation).
zig cc -target x86_64-linux-gnu emitted an ELF for every variant except
execstack. The script stopped those variants there, except stack-protector,
where stack_protector stayed unknown, so it also parsed
zig cc -target x86_64-linux-musl.
| Variant | Compiler | Bytes | DT_NEEDED |
Build-id | PIE | NX | RELRO | Stack protector | Stripped | CET |
|---|---|---|---|---|---|---|---|---|---|---|
pie |
zig-linux-gnu | 3792792 | 3 | no | enabled | enabled | enabled | unknown | disabled | disabled |
no-pie |
zig-linux-gnu | 3788400 | 3 | no | disabled | enabled | enabled | unknown | disabled | disabled |
relro-now |
zig-linux-gnu | 3792792 | 3 | no | enabled | enabled | enabled | unknown | disabled | disabled |
relro |
zig-linux-gnu | 3792768 | 3 | no | enabled | enabled | partial | unknown | disabled | disabled |
no-relro |
zig-linux-gnu | 3792600 | 3 | no | enabled | enabled | disabled | unknown | disabled | disabled |
stack-protector |
zig-linux-gnu | 3792792 | 3 | no | enabled | enabled | enabled | unknown | disabled | disabled |
stack-protector |
zig-linux-musl | 4476552 | 0 | no | enabled | enabled | enabled | unknown | disabled | disabled |
build-id |
zig-linux-gnu | 3792912 | 3 | yes | enabled | enabled | enabled | unknown | disabled | disabled |
dynamic |
zig-linux-gnu | 3792792 | 3 | no | enabled | enabled | enabled | unknown | disabled | disabled |
two-needed |
zig-linux-gnu | 3792952 | 5 | no | enabled | enabled | enabled | unknown | disabled | disabled |
build-id note alignments recorded by the script were 4:32 and 4:36.
cet_ibt_shstk on that image was disabled.
stack-protector was recorded unavailable: No compiler emitted an ELF with an undefined dynamic __stack_chk_fail, so stack_protector enabled was not observed.
execstack (-Wl,-z,execstack) produced no ELF. Both zig targets exited 1
with error: unsupported linker extension flag: -z execstack. The script
recorded: No compiler emitted an ELF whose PT_GNU_STACK is executable, so NX disabled was not observed.
NX disabled was not exercised by a real ELF on this host.
Mach-O
/usr/bin/cc -arch arm64 compiled one image. cc --version printed
Apple clang version 21.0.0 (clang-2100.1.1.101). REA reported one image, PIE
enabled, hardened_runtime unknown. /usr/bin/otool -hv agreed
(otoolPie: true). otool -version exited 1. The stored text begins
"error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: unknown char `s' in flag -version".
/usr/bin/cc -arch x86_64 -arch arm64 produced a universal image. REA returned
two parsed slices, x86_64 and arm64, both with PIE enabled.