@@ -6539,6 +6539,17 @@ static int DoServiceRequest(WOLFSSH* ssh,
65396539
65406540 ret = GetString(name, &nameSz, buf, len, idx);
65416541
6542+ /* Check if requested service is 'ssh-userauth' */
6543+ if (ret == WS_SUCCESS) {
6544+ const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6545+ if (nameUserAuth == NULL || XSTRCMP(name, nameUserAuth) != 0) {
6546+ WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name);
6547+ SendDisconnect(ssh,
6548+ WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6549+ ret = WS_INVALID_STATE_E;
6550+ }
6551+ }
6552+
65426553 if (ret == WS_SUCCESS) {
65436554 WLOG(WS_LOG_DEBUG, "Requesting service: %s", name);
65446555 ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;
@@ -6557,6 +6568,15 @@ static int DoServiceAccept(WOLFSSH* ssh,
65576568
65586569 ret = GetString(name, &nameSz, buf, len, idx);
65596570
6571+ /* Check if accepted service is 'ssh-userauth' */
6572+ if (ret == WS_SUCCESS) {
6573+ const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6574+ if (nameUserAuth == NULL || XSTRCMP(name, nameUserAuth) != 0) {
6575+ WLOG(WS_LOG_DEBUG, "Accepted unexpected service: %s", name);
6576+ ret = WS_INVALID_STATE_E;
6577+ }
6578+ }
6579+
65606580 if (ret == WS_SUCCESS) {
65616581 WLOG(WS_LOG_DEBUG, "Accepted service: %s", name);
65626582 ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;
0 commit comments