Repository navigation
fix: make policy add place rules where they take effect - #20
Merged
Asdivyansh merged 1 commit intoNov 16, 2026
Merged
Conversation
Rules are first-match, but policy add appended the new rule, so an earlier rule with the opposite action (allow *.npmjs.org) shadowed it and a deny for evil.npmjs.org was never reached, while the CLI reported success. - Add placeRule(), which returns the index just ahead of the first earlier rule that matches the new host with the opposite action (else the end). - policy add inserts there and says which rule it was placed before. - Say so when policy add bootstraps a policy file from the standard preset. - Reject negated patterns (!host): they match every other host. - Update policy-engine.md and cli-reference.md to describe the behaviour. Fixes SilosLabs#19
Member
|
Critical, thanks for the fix. |
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.
Fixes #19
Problem
Policy rules are first-match, but
silo policy addappended the new rule. When an earlier rule with the opposite action matched the same host, the new rule was never reached.silo policy add evil.npmjs.org --action denyprinted "Added rule → deny", but the host stayed allowed, becauseallow *.npmjs.orgcame first.Change
placeRule()(src/policy/engine.ts): returns where a rule must go to take effect. That's just ahead of the first earlier rule that matches the new host with the opposite action, or the end of the list if none does. The new host is tested as a literal against existing patterns, so*.evil.npmjs.orgalso lands ahead of*.npmjs.org. Matching is case-insensitive, like evaluation.silo policy addinserts the rule at that index and tells the user when it had to move ahead of a rule:Placed before "*.npmjs.org" (allow)…. Deny now prints in red.standardpreset, but now says so, with a pointer tosilo policy show.!evil.com, exit 1). In picomatch,!negates, so the rule would match every host except the one named.docs/policy-engine.mdanddocs/cli-reference.mdnow describe the placement. The bootstrap description also now matches the code: it's always thestandardpreset, not the onboard mode.Rules already in a policy file are left alone. Only the position of newly added rules changes.
Before and after
The same commands in a throwaway
HOMEwith a fresh config (rule order from~/.silo/policy.yaml; verdicts fromevaluate()):mainpolicy add evil.npmjs.org --action deny*.npmjs.org, with a message saying soevil.npmjs.orgcdn.npmjs.org/registry.npmjs.orgpolicy add '!evil.com'standardTests
7 new cases for
placeRuleintests/policy/engine.test.ts:default: allow.npm run typecheck,npm test(352 passing) andnpm run buildare green. The branch merges cleanly with #13.Not changed here:
parsePolicyFilestill accepts!patterns in hand-written policy files. Rejecting them in the schema would make an existing file fail to load, so I've left that decision to you.