Repository navigation
Backlog
Backlog
Feature
Copy link
Labels
Milestone
Description
Goal
A user's allow rule auto-runs only the commands it visibly describes. An allow regex must match the whole command part, and a * in the middle of an allow glob stands for exactly one argument. Deny and confirm rules keep matching at least as often as today.
Context
- User rules are matched in
Pattern::matches_for_user_rule(crates/core/src/filter/pattern.rs:189-221). For globs that are not path-shaped and for regexes it falls through toPattern::matches(:108-124,:219). - Globs are compiled with the
globsetdefaults (pattern.rs:128-130):*also matches spaces. So the allow globgit log *matchesgit log --output=/root/x, andfind . -name *matchesfind . -name x -delete. A glob counts as path-shaped if a whitespace token contains/(pattern.rs:280-284); its strict branch (literal_separator(true),:189-221) keeps*from crossing/, but not from crossing spaces. - Regexes use
Regex::is_matchwithout anchors (pattern.rs:131-133). The allow regexlstherefore matches every command part that contains "ls", e.g.rm -r /srv/tools. - Matching runs per command part: the parser splits at
&&,||,;,|,&and newlines first (crates/core/src/filter/parser.rs:29-77). Hard blacklist, deny rules, substitutions, redirections, comments and the risk escalations apply independently of the allow match (crates/core/src/filter/engine.rs:553-556,:603-605,:620-628,:933). Pattern::matchesand the compiled patterns are also used by the risk classifier and the hard blacklist (pattern.rs:108-124,:657-689) and must not change.- Rule suggestions:
last_arg_open_pattern(crates/app-logic/src/rule_suggestions.rs:257-271) emitstool mid *, labelled "Any last argument: …" (quickRuleLabel.lastArgOpen,apps/smart-ssh-community/frontend/src/locales/en/common.json:451).suggestion_covers(rule_suggestions.rs:283) drops suggestions that would not match the confirmed command. - Specs: 0002 §2 and §3.2 (rule types, user rules; examples
ls *,cat /var/log/*), 0060 (glob and/, §3 existing rules, §4 adversarial cases), 0077 (validation parity), 0011 (quick-accept suggestions), 0117 (rule packs carry patterns as text).
Requirements
Decided by maintainer:
- Allow regex: an allow rule's regex must match the whole command part, as if written
^(?:…)$. Deny and confirm regexes keep the current unanchored matching. - Allow glob: a
*that is not the last character of the pattern matches within one argument only (never whitespace). A*at the end of the pattern still covers all remaining arguments.?likewise never matches whitespace. For path-shaped globs this applies in addition to the existing/rule of Spec 0060. - Deny and confirm rules match at least everything they match today: for them the current permissive matching stays (for path-shaped globs the existing
strict || matchesstays). Pattern::matches, the hard blacklist and the risk classifier patterns are unchanged.validate()/compile_failure_reason()cover every new compile path (Spec 0077 parity test extended).
Consequences for existing rules (decided):
- Stored patterns are not rewritten; no data migration. Existing allow rules whose middle
*covered several arguments, or whose regex matched only part of a command, now lead to a confirmation for those commands. This is the fail-safe direction. - A changelog fragment tells users that allow rules now match more precisely, with one glob and one regex example and the hint to write a
*at the end or.*in a regex to cover more. - The suggestion
tool mid *stays (its final*covers the remaining arguments); its label becomes "Any further arguments: {{patterns}}" in English and is translated in every locale underapps/smart-ssh-community/frontend/src/locales/.suggestion_coverskeeps every suggestion that matched before for the confirmed command. - Imported rule packs (Spec 0117) use the same matching; nothing extra.
- Specs 0002, 0060 and 0011 describe the new allow semantics with examples.
Acceptance Criteria
- Allow glob
git log *still matchesgit log --oneline -5; allow globsystemctl * nginxmatchessystemctl restart nginxbut notsystemctl restart foo nginx - Allow glob
find . -name * -printdoes not matchfind . -name x -delete -print - Allow glob
cat /var/log/*still matchescat /var/log/syslog(Spec 0060 cases stay green) - Allow regex
lsdoes not matchrm -r /srv/toolsnorls -la; allow regexls( .*)?matchesls -la - Deny glob
rm * /dataand deny regexrmmatch every command they match today (property test over generated commands: old deny/confirm match ⇒ new deny/confirm match) - Hard blacklist and risk classifier results are unchanged (existing tests green, including
test_server_risk_red_dd_to_device) - An allow rule that no longer matches leads to Confirm, never to Deny or AutoExec (engine test)
- Validation parity: every pattern that
validate()accepts compiles in every matching path (extended parity test) - Rule suggestions: for a set of confirmed commands, every suggestion offered before the change is still offered and still covers the command; the label text is updated in all locales; i18n checks pass
- Relevant automated tests pass
Technical Notes
- Security-critical module: filter engine. The change only narrows allow matches; it must never make a deny or confirm rule or the blacklist match less. Follow the project rule: regression tests with counter-probes, adversarial cases from Spec 0060 §4.
- New tests go into a new file
crates/core/src/filter/tests_allow_precision.rs. - User-visible: changelog fragment (see above).
Files: crates/core/src/filter/pattern.rs, crates/core/src/filter/mod.rs, crates/core/src/filter/ (new tests_allow_precision.rs), crates/app-logic/src/rule_suggestions.rs, apps/smart-ssh-community/frontend/src/locales/, docs/specs/0002-filter-engine-spec.md, docs/specs/0060-glob-path-separator.md, docs/specs/0011-rule-quick-accept.md, changelog.d/
Spec impact: update 0002
Open questions
- How to implement "
*within one argument": (a) translate the allow glob into a regex (*→[^\s]*, final*→.*), (b) match token-wise against the split arguments. Recommendation: (a), one compiled matcher per rule, mirrored invalidate().
Related Work
- Core: display layout of a command, split at top-level separators from the filter parser #1662 (also edits Spec 0002)
- Rule quick-accept: suggest path-scoped and last-argument-open rules #588 (rule quick-accept suggestions)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
P2 - Normal
Activity