@@ -6539,6 +6539,20 @@ static int DoServiceRequest(WOLFSSH* ssh,
65396539
65406540 ret = GetString(name, &nameSz, buf, len, idx);
65416541
6542+ /* Requested service must be 'ssh-userauth' */
6543+ if (ret == WS_SUCCESS) {
6544+ const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6545+ if (nameUserAuth == NULL
6546+ || nameSz != (word32)XSTRLEN(nameUserAuth)
6547+ || XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6548+ WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name);
6549+ /* Terminate session, ignore result of disconnect attempt */
6550+ (void)SendDisconnect(ssh,
6551+ WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6552+ ret = WS_INVALID_STATE_E;
6553+ }
6554+ }
6555+
65426556 if (ret == WS_SUCCESS) {
65436557 WLOG(WS_LOG_DEBUG, "Requesting service: %s", name);
65446558 ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;
@@ -6557,6 +6571,17 @@ static int DoServiceAccept(WOLFSSH* ssh,
65576571
65586572 ret = GetString(name, &nameSz, buf, len, idx);
65596573
6574+ /* Requested service must be 'ssh-userauth' */
6575+ if (ret == WS_SUCCESS) {
6576+ const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6577+ if (nameUserAuth == NULL
6578+ || nameSz != (word32)XSTRLEN(nameUserAuth)
6579+ || XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6580+ WLOG(WS_LOG_DEBUG, "Accepted unexpected service: %s", name);
6581+ ret = WS_INVALID_STATE_E;
6582+ }
6583+ }
6584+
65606585 if (ret == WS_SUCCESS) {
65616586 WLOG(WS_LOG_DEBUG, "Accepted service: %s", name);
65626587 ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;
0 commit comments