Treat combined Match User/Group blocks as a conjunction in wolfsshd#1027
Treat combined Match User/Group blocks as a conjunction in wolfsshd#1027yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes wolfSSHD_GetUserConf so that a combined Match User X Group Y block is evaluated with AND (conjunction) semantics rather than the previous OR behavior, aligning wolfSSHD config resolution with OpenSSH and preventing unintended application of more-permissive policies.
Changes:
- Reworked the
wolfSSHD_GetUserConfmatching loop to require all non-NULL selectors present on a node (currentlyUserandGroup) to match before selecting that node. - Added a new unit test covering combined
Match User + Group, single-selector behavior, and the NULL-group fail-closed case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
apps/wolfsshd/configuration.c |
Updates user/group match resolution to conjunction semantics and prevents combined-selector bypass. |
apps/wolfsshd/test/test_configuration.c |
Adds regression coverage for combined vs single-selector Match blocks and NULL-group behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1027
Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1027
Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1027
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
Summary
wolfSSHD_GetUserConfevaluated a combinedMatch User X Group Yconfig block with OR semantics instead of AND. OpenSSH treats aMatchline as a conjunction, but the lookup loop broke out on a username match or a group match independently. Since a combinedMatch User X Group Yline sets bothusrAppliesToandgroupAppliesToon the same config node, the block was returned for:aliceregardless of group, andadminsregardless of name.When such a block relaxes a global
ForceCommand(e.g. frominternal-sftpto a full shell) or changesChrootDir, an authenticated user satisfying only one of the two selectors inherited the permissive policy and could escape SFTP-only confinement.Fix
Each config node is now evaluated as a conjunction of its set selectors: a node applies only when every non-NULL selector on it matches; a NULL selector acts as a wildcard.
This preserves the legitimate, common single-selector blocks (
Match User alice,Match Group admins) while closing the combined-block bypass. When no node matches, it still falls back to the global head config. The NULL-group path (WIN32, or failed group resolution inwolfSSHD_AuthGetUserConf) now fails closed against a combined node rather than treating NULL as a wildcard.Changes
apps/wolfsshd/configuration.c— rewrote the matching loop inwolfSSHD_GetUserConfto use per-node conjunction semantics.apps/wolfsshd/test/test_configuration.c— addedtest_GetUserConfMatchGroupAndcovering combined and single-selector blocks with users satisfying zero, one, and both selectors, plus the NULL-group fail-closed case.Testing
test_GetUserConfMatchGroupAndand existingtest_GetUserConfMatchOverridepass.ret=-1001), confirming it actually catches the OR bug.-fsanitize=address,undefined -fno-omit-frame-pointer— clean, no ASan/UBSan reports.