Repository navigation
v1.0.4
A security and robustness release, from a self-review of 1.0.3. No rule id,
flag, default or output field changed; the JSON and SARIF formats are
unchanged. Reporter: self-review.
Security
verify-fixreadsffifrom TOML under a conservative key
normalization. Foundry resolves case and separator aliases:FFI,Ffi,
ffi_andffi__all setffi(verified against forge 1.5.1). The guard
applies a deliberately coarser normalization than Foundry (lowercase ASCII;
keeps ASCII alphanumerics only, dropping Unicode too), which catches every alias Foundry
resolves and also refuses some spellings Foundry treats as unknown (f_f_i). Only
exactlyffiwith the boolean valuefalseis accepted, a booleantrue
is refused, any other value is refused conservatively, and every
non-canonical spelling is refused whatever its value. The scan is document-wide: spacing, tabs, quoted keys,
dotted keys, inline tables, the top-level table and profiles the program has
never heard of are all covered. Foundry's global config (~/.foundry/foundry.toml, or
%USERPROFILE%\.foundry\foundry.toml), the root tree, the--patchedtree
and the copy after--patchare checked before the tree is used, with the
global config and both copies parsed again immediately before each forge
start. Afoundry.tomlthat does not parse is
refused rather than assumed off. A config in an ancestor directory of the
temp copy is not checked; on Windows Foundry may resolve the OS known
profile folder while this check usesUSERPROFILE/HOME, so the two can
differ;docs/threat-model.mdH5 records both residuals.
FOUNDRY_FFI=falseis not described as a control: Foundry documents the
variable as an explicit exception to its environment overrides. Tests:
ffi_is_seen_however_toml_spells_it,
foundry_key_aliases_and_non_boolean_ffi_values_are_refused,
ffi_is_refused_in_the_root_the_patched_tree_and_after_a_patch(17 exact
and alias spellings),
a_global_config_with_an_ffi_alias_is_refused_before_forge_starts,
a_minimal_top_level_ffi_alias_is_refused_before_forge
(src/verify_fix.rs,tests/verify_fix_ffi.rs).- Write
fs_permissionsand its aliases are refused, closing the
config-rewrite path. A PoC could setfs_permissions = [{ access = "read-write", path = "C:/" }]and usevm.writeFileto rewrite the other
copy's or the global config to an ffi alias between the two runs; the key
itself has aliases too (FS_PERMISSIONS,FS-PERMISSIONS,fsPermissions,
fs_Permissions,Fs-Permissions,fs__permissions, the quoted key
"fs.permissions", and spaces), which Foundry resolves to the same setting.
The unquoted dotted formfs.permissions = ...parses as nested
fs/permissionskeys; neither Foundry nor the guard resolves it as
fs_permissions, so there is no gap. Any key normalized tofs_permissionsmust be
the exact spelling, and every entry in every checked config must grant
exactlyaccess = "read"; a write or read-write entry, a missing or
non-string access, a non-array value, a non-table entry, or an alias is
refused before any forge run. Both copies and the global config are also
re-parsed immediately before each run, which catches a simple rewrite; the
fs_permissionsrefusal is the primary control. Tests:
fs_permissions_must_be_read_only,
write_fs_permissions_are_refused_in_every_config_the_guard_reads,
fs_permissions_aliases_are_refused_in_every_config_the_guard_reads,
a_global_config_with_a_fs_permissions_alias_is_refused_before_forge_starts,
the_alias_cross_run_combination_is_refused_before_forge,
read_only_fs_permissions_reach_forge,
a_rewritten_tree_or_global_config_is_refused_before_the_next_run,
a_global_config_rewritten_by_the_first_run_is_refused_before_the_second. - The dotenv redirect is closed. Foundry loads a
.envafter it starts,
and dotenvy does not override an already-set variable. Removing
FOUNDRY_CONFIGtherefore let a--patchthat created.env+
evil.tomlpoint forge at an unparsedffi = trueconfig.FOUNDRY_CONFIG
is now pinned to the absolute path of a config the guard checked inside the
copy (a minimal[profile.default]file is created when the tree has none),
and any.envin a copied tree is refused before each forge run. Tests:
a_patch_that_adds_dotenv_and_an_evil_config_is_refused,
a_clean_dotenv_is_still_refused,
the_forge_child_gets_the_pinned_absolute_config(src/verify_fix.rs,
tests/verify_fix_ffi.rs). - Relative
--patchand--forgepaths are resolved before the copy's
working directory applies.--patch ../fix.diff(outside--root) and a
--forgevalue containing a separator keep working; a bareforgekeeps
PATH lookup (src/verify_fix.rs,tests/verify_fix_paths.rs). - The host policy is enforced in the library.
verifyrefuses a request
with noHostPolicybefore copying a tree or starting forge, so a library
caller is covered like the CLI (src/verify_fix.rs,
no_attestation_is_refused_before_forge_is_started). --patchrequires git.git apply --checkruns first and the
hand-written fallback applier is gone, so a tree the patch does not describe
is never run (src/verify_fix.rs,docs/verify-fix.md).- A Foundry config is size-checked before it is parsed. A tree or global
foundry.tomlmust be a regular file of at most 1 MiB; a larger one is
refused before the read (src/verify_fix.rs,
an_oversized_foundry_toml_is_refused_before_forge_starts). - Each forge run is time- and output-bounded. A run longer than 10 minutes,
or one that prints more than 64 MiB of stdout or 1 MiB of stderr, is killed
and is aVerifyError(exit 2), never a fail verdict; the verdict is not
taken from a truncated log (wait_forge,
a_forge_that_runs_past_the_timeout_is_killed_and_is_not_a_verdict,
a_forge_that_floods_stdout_is_killed_and_is_not_a_verdict). - The copied tree is bounded. The project or
--patchedtree is
attacker-controlled; the copy is capped at 50 000 files, 512 MiB in total,
50 000 directories and 64 levels deep, checked from metadata while copying,
so a hostile tree cannot fill the disk with files or empty directories before
forge's own limits apply (copy_tree,copy_tree_with_limits,
the_copy_file_byte_and_directory_caps_are_enforced,
a_tree_larger_than_the_copy_limit_is_refused_before_forge_starts,
a_tree_deeper_than_the_copy_limit_is_refused_before_forge_starts). - MCP framing is bounded.
Content-Lengthis refused above 8 MiB before
any allocation. The server writes a JSON-RPC error and stops (exit 2): it
does not claim to resynchronise past a body it refused, so a following ping
is not served. A header line is capped at 8 KiB; empty lines are skipped in a
loop instead of by recursion (src/mcp.rs,tests/mcp_stdio.rs). - Control characters and bidi formatting from source and claims do not
reach terminal output. The text, Markdown and evidence-card renderers
replace newline, carriage return, tab and U+2028/U+2029 with a space, and
drop other Unicode control characters plus the bidi controls U+061C, U+200E,
U+200F, U+202A-U+202E and U+2066-U+2069, from finding messages, evidence,
paths, suite and test names, claim text and evidence, suppression notes and
parse errors, before any colour wrapper. A Linux file name containing a
newline can no longer fabricate a report line. JSON and SARIF keep their
serde escaping (src/render/mod.rs,
control_characters_in_source_never_reach_text_or_markdown_output,
a_newline_or_bidi_in_a_path_cannot_fabricate_a_report_line).
Fixed
- Input caps. 8 MiB per source file (from metadata, before the read),
128 MiB and 20 000 files per run, 64 levels deep, and 16 MiB for a
--report,--claims,--declarationor--configfile. Every error names
the limit (src/project.rs,an_oversized_source_file_is_refused_by_name_before_it_is_read). - Policy inputs must be regular files. The 16 MiB cap alone did not bound a
FIFO: it has length zero, soread_to_stringblocked forever. The type is
now checked withsymlink_metadata, a FIFO is refused before it is opened,
and a symlink is refused too. The check is not atomic with the open; policy
files must come from a trusted location (src/project.rs,
a_non_regular_policy_input_is_refused_by_name,
a_fifo_policy_input_is_refused_without_blocking). - The trace is no longer quadratic in test count. A suite base (state
initializers, constructors,setUp()and callbacks) and the RG15 whole-file
fee-concession fact are computed once per suite; the test-function
duplicate check uses a set. The 5 MB / 40 000-function adversarial case is
enabled instead of ignored, and a 12 000-function case (serialised with the
other size tests so the measurement is stable) has a 5 s release bound and a
120 s debug bound the old quadratic run cannot meet (src/trace.rs,
src/project.rs,src/engine.rs,tests/adversarial.rs). - Deleted the dead no-op context-line branch in the removed fallback applier.
verify-fixconfig errors name the offending alias key and display paths
with one separator style on Windows.
Changed
verify_fix::Request::hostisOption<HostPolicy>;Noneis refused by
verify. The library API is documented as unstable, and this is the change
that puts the host decision inside the library.#![forbid(unsafe_code)]on the library and all three binaries.- CI has an MSRV job that reads
rust-versionfromCargo.toml(1.95, the
1.95.0 minimum) and runscargo test --lockedon that toolchain. The weekly,
non-gatingcargo-mutantsjob oversrc/rules/,src/claims/,src/bind/
andsrc/verify_fix.rslives in its ownmutants.ymlworkflow with a
schedule andworkflow_dispatch, so the regular CI jobs do not run weekly
(docs/test-quality.md).
Tests
tests/verify_fix_ffi.rs: 17 exact and alias spellings × the root, the
--patchedtree and the post-patch tree, each asserting exit 2 and an
absent fake-forge marker, plus a benign control that reaches forge; a fake
HOME whose global config enables ffi, one per spelling; the
fs_permissionsalias matrix (root with write and read-only values,
--patched, post-patch, global); the alias global-config cases; the
minimal top-levelFFI = trueand theFS_PERMISSIONS+FFIcombination;
a first run that rewrites the global config, asserting exit 2 and exactly
one forge invocation; a patch that adds.env+ an ffi config (refused); a
clean.env(refused by policy); the pinned absoluteFOUNDRY_CONFIGthe
child actually receives; a 2 MiB sparsefoundry.tomlrefused before the
read; write/read-writefs_permissionsrefused in the root,--patched,
post-patch and global configs; and a read-only control that reaches forge.tests/verify_fix_paths.rs: a relative--patchoutside--root, a
relative--forgewith a separator, and a patch thatgit apply --check
refuses (exit 2, no forge, original tree untouched).tests/verify_fix_copy_limits.rs: a sparse tree over 512 MiB and a tree 70
levels deep, both refused before forge starts.tests/mcp_stdio.rs: the stdio binary answers a 9 MBContent-Lengthwith
a JSON-RPC error, stops on that refusal (not on the body's line cap), does
not serve the following ping, and exits 2.- Adversarial: raw ESC in a Solidity string literal, a 1 GiB sparse file, a
non-regular policy input, a FIFO policy input with a deadline (Unix), the
enabled 5 MB case and the 12 000-function bound, with the size/timing tests
serialised. - Unit tests for the TOML
ffiscan under Foundry's key normalization, the
alias and non-boolean refusal, the host refusal, the global config,
fs_permissionsread-only enforcement (including non-table entries and
non-string access), per-run revalidation of a rewritten tree/global config,
the copy file/byte/directory/depth caps, relative forge paths, regular-file
inputs, the source count/total/depth caps, forge timeout and stdout flood,
bounded frames, empty-line looping, newline/bidi sanitization and claim-cell
sanitization. docs/threat-model.mdguarantees and hypotheses, anddocs/limitations.md,
updated to what is now tested, with the remaining unverified items marked.
Install
cargo binstall realism-gate
or download an archive below and check it:
sha256sum -c SHA256SUMS --ignore-missing
gh attestation verify <archive> --repo KhomDev/realism-gate
Three binaries are included: realism-gate (the checker), rgate
(the same program under a short name) and realism-gate-mcp (the MCP
server). cargo binstall installs all three. Linux builds are static
(musl).