diff --git a/src/internal.c b/src/internal.c index 77f165dbb..b2d32f891 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6539,6 +6539,20 @@ static int DoServiceRequest(WOLFSSH* ssh, ret = GetString(name, &nameSz, buf, len, idx); + /* Requested service must be 'ssh-userauth' */ + if (ret == WS_SUCCESS) { + const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH); + if (nameUserAuth == NULL + || nameSz != (word32)XSTRLEN(nameUserAuth) + || XMEMCMP(name, nameUserAuth, nameSz) != 0) { + WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name); + /* Terminate session, ignore result of disconnect attempt */ + (void)SendDisconnect(ssh, + WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE); + ret = WS_INVALID_STATE_E; + } + } + if (ret == WS_SUCCESS) { WLOG(WS_LOG_DEBUG, "Requesting service: %s", name); ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE; @@ -6557,6 +6571,17 @@ static int DoServiceAccept(WOLFSSH* ssh, ret = GetString(name, &nameSz, buf, len, idx); + /* Requested service must be 'ssh-userauth' */ + if (ret == WS_SUCCESS) { + const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH); + if (nameUserAuth == NULL + || nameSz != (word32)XSTRLEN(nameUserAuth) + || XMEMCMP(name, nameUserAuth, nameSz) != 0) { + WLOG(WS_LOG_DEBUG, "Accepted unexpected service: %s", name); + ret = WS_INVALID_STATE_E; + } + } + if (ret == WS_SUCCESS) { WLOG(WS_LOG_DEBUG, "Accepted service: %s", name); ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;