wolfsshd: fix Match User/Group directive misparse#1039
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a security-relevant misparse of Match User / Match Group directives in wolfsshd by replacing an unanchored substring search with a positional token-pair parser, preventing “ghost” user/group tokens from unintentionally inheriting Match-block authentication overrides.
Changes:
- Replaced the old
Matchcriteria extraction logic withParseMatchCriteria()that matchesUser/Groupas whole tokens and consumes the following token as the literal principal name. - Made bare recognized keywords (e.g.,
Match User) fail closed (configuration error) and fixed an error-path leak by freeing an unlinked Match config node on parse failure. - Added regression tests covering substring/keyword-name edge cases, repeated keywords, bare keywords, and combined user+group criteria.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/wolfsshd/configuration.c | Introduces positional parsing for Match criteria and fixes error-path memory handling. |
| apps/wolfsshd/test/test_configuration.c | Adds regression tests to prevent reintroduction of the Match User/Group misparse and related edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1b61cf6 to
8d10dc0
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1039
Scan targets checked: wolfssh-bugs, wolfssh-src
Findings: 2
1 finding(s) posted as inline comments (see file-level comments below)
Low (1)
Stale leftover comment
Function: ParseMatchCriteria
Category: Code Quality
A stale leftover comment exists at line 874, not a security concern but indicates incomplete cleanup.
Recommendation: Remove the stale comment to maintain code cleanliness.
This review was generated automatically by Fenrir. Findings are non-blocking.
8d10dc0 to
67bd2bc
Compare
Summary
Match User/Match Groupdirectives inwolfsshdwere misparsed, allowing an authentication-policy bypass.AddRestrictedCase()located theUser/Groupkeyword in a Match directive value withXSTRSTR— an unanchored substring search. When a user name contained the substringGroup(e.g.GroupAdmin), theGrouppass matched inside that token and extracted a spuriousgroupAppliesTovalue (Admin). Symmetrically, a group name containingUser(e.g.UserStaff) produced a ghostusrAppliesTo.wolfSSHD_GetUserConf()then exact-matched these ghost tokens at every authentication attempt, so any OS account whose name or primary group equaled a ghost token inherited the Match block's overrides (e.g.PasswordAuthentication yesoverriding a globalno) — bypassing the intended per-user policy. The reverse direction incorrectly denied access to unrelated users.Fix
Replaced the per-keyword substring search with a positional token-pair parser (
ParseMatchCriteria) that walks the value as whitespace-separated tokens:User/Groupkeyword is matched as an exact whole token.Match User Group, a user literally namedGroup) is handled by position, not by substring.Match User) is now a configuration error (fail-closed), instead of being silently accepted as a dead node that quietly discarded the admin's subsequent settings.wolfsshddoes not yet support).Also:
XSTRSTReliminates an empty-keyword infinite-loop edge case.HandleMatch: the per-match config node was allocated but neither linked nor freed when criteria parsing failed.Tests
Added regression tests in
apps/wolfsshd/test/test_configuration.c:test_GetUserConfMatchSubstringGroup→ no ghost group tokentest_GetUserConfMatchSubstringGroupUser→ no ghost user tokentest_GetUserConfMatchLiteralKeywordNameMatch User Group→ user namedGroup, group unsettest_GetUserConfMatchBareKeywordMatch User→ fail-closedtest_GetUserConfMatchRepeatedKeywordMatch User a User b→ free-then-replace pathtest_GetUserConfMatchUserAndGroupVerification
test_configurationsuite passes.