@@ -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,20 @@ static int DoServiceAccept(WOLFSSH* ssh,
65576571
65586572 ret = GetString(name, &nameSz, buf, len, idx);
65596573
6574+ /* Accepted 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+ /* Terminate session, ignore result of disconnect attempt */
6582+ (void)SendDisconnect(ssh,
6583+ WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6584+ ret = WS_INVALID_STATE_E;
6585+ }
6586+ }
6587+
65606588 if (ret == WS_SUCCESS) {
65616589 WLOG(WS_LOG_DEBUG, "Accepted service: %s", name);
65626590 ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;
0 commit comments