-
Notifications
You must be signed in to change notification settings - Fork 102
Add validation for accept request and reply #902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6539,6 +6539,17 @@ static int DoServiceRequest(WOLFSSH* ssh, | |||||||||||||||||
|
|
||||||||||||||||||
| ret = GetString(name, &nameSz, buf, len, idx); | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Check if requested service is 'ssh-userauth' */ | ||||||||||||||||||
| if (ret == WS_SUCCESS) { | ||||||||||||||||||
| const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH); | ||||||||||||||||||
| if (nameUserAuth == NULL || XSTRCMP(name, nameUserAuth) != 0) { | ||||||||||||||||||
| WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name); | ||||||||||||||||||
| SendDisconnect(ssh, | ||||||||||||||||||
| WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE); | ||||||||||||||||||
| ret = WS_INVALID_STATE_E; | ||||||||||||||||||
|
Comment on lines
+6547
to
+6549
|
||||||||||||||||||
| SendDisconnect(ssh, | |
| WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE); | |
| ret = WS_INVALID_STATE_E; | |
| ret = SendDisconnect(ssh, | |
| WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE); | |
| if (ret == WS_SUCCESS) { | |
| ret = WS_INVALID_STATE_E; | |
| } |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XSTRCMP(name, nameUserAuth) is not binary-safe for SSH "string" fields. A malicious or non-conforming peer could send an accepted service like "ssh-userauth\0junk" and pass this check because XSTRCMP stops at the embedded NUL. Prefer a length-based comparison (check nameSz against WSTRLEN(nameUserAuth) and use XMEMCMP) or parse via GetStringRef and compare IDs via NameToId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XSTRCMP(name, nameUserAuth)compares C strings and can be bypassed with an SSH "string" that contains an embedded NUL (e.g., "ssh-userauth\0junk"). BecauseGetString()copies bytes and NUL-terminates,XSTRCMPwill stop at the first NUL and treat it as a valid match even if the received string length differs. Use a length-checked, binary-safe comparison (e.g., validatenameSzequals the expected length and compare withXMEMCMP, or parse withGetStringRef+NameToId).