Repository navigation
feat: enforce custom rule hermeticity at runtime - #868
Merged
Merged
Conversation
Replace the call-name ban with a runtime audit-hook guard in the custom rule host, launch the host with a scrubbed environment and a fixed hash seed, widen the import allowlist to pure deterministic stdlib modules, limit the static import check to the fingerprinted import closure, and make the public rule harness detect state leaking between evaluations.
Hash each Rule's full source file plus its import closure so any module statement edit invalidates cached results, pin the custom host's working directory to the resolved project directory and drop the invocation directory from its import path, and state in the docs that the guard is for cache correctness rather than a sandbox.
Route unaudited os and os.path metadata calls through the runtime guard so Rule code probing file existence or stat results is rejected with the non-hermetic error, and resolve every repository-owned rules module a Rule can execute (relative and multi-name imports, package initializers, and function-local imports) for both the static import check and the implementation fingerprint.
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.
Why
Custom-Rule results are cached, so a Rule must depend only on tracked inputs. The old check banned calls by name and allowed a short import list: it rejected pure code (
re.compile,fnmatch,json, helpers namedexists) and accepted environment reads, commands, directory listing and indirect file access, and it missed module-level state and set-order dependence. A module-level edit could also leave a stale cached result.Changes
ctypesaccess and non-allowlisted imports from Rule code;ctx.project.treereads stay allowed. Errors name the Rule and line.PYTHONHASHSEED=0and-P, clearsos.environand runs from the project directory before Rules load.evaluate_ruleevaluates each subject twice and fails when findings differ.Verification
sqb compilefor allowed modules, each rejected access, scrubbed environment, fixed set order, working directory, stale-cache invalidation andctx.project.treetracking; harness and import-check unit tests. New tests fail on the old code.make test,make check-ciand the hygiene scan pass; one independent review.