Skip to content

Commit 3075b72

Browse files
authored
Merge pull request #902 from padelsbach/request-validation
Add validation for accept request and reply
2 parents b318bc9 + ffa646a commit 3075b72

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/internal.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6537,6 +6537,20 @@ static int DoServiceRequest(WOLFSSH* ssh,
65376537

65386538
ret = GetString(name, &nameSz, buf, len, idx);
65396539

6540+
/* Requested service must be 'ssh-userauth' */
6541+
if (ret == WS_SUCCESS) {
6542+
const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6543+
if (nameUserAuth == NULL
6544+
|| nameSz != (word32)XSTRLEN(nameUserAuth)
6545+
|| XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6546+
WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name);
6547+
/* Terminate session, ignore result of disconnect attempt */
6548+
(void)SendDisconnect(ssh,
6549+
WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6550+
ret = WS_INVALID_STATE_E;
6551+
}
6552+
}
6553+
65406554
if (ret == WS_SUCCESS) {
65416555
WLOG(WS_LOG_DEBUG, "Requesting service: %s", name);
65426556
ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;
@@ -6555,6 +6569,20 @@ static int DoServiceAccept(WOLFSSH* ssh,
65556569

65566570
ret = GetString(name, &nameSz, buf, len, idx);
65576571

6572+
/* Accepted service must be 'ssh-userauth' */
6573+
if (ret == WS_SUCCESS) {
6574+
const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6575+
if (nameUserAuth == NULL
6576+
|| nameSz != (word32)XSTRLEN(nameUserAuth)
6577+
|| XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6578+
WLOG(WS_LOG_DEBUG, "Accepted unexpected service: %s", name);
6579+
/* Terminate session, ignore result of disconnect attempt */
6580+
(void)SendDisconnect(ssh,
6581+
WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6582+
ret = WS_INVALID_STATE_E;
6583+
}
6584+
}
6585+
65586586
if (ret == WS_SUCCESS) {
65596587
WLOG(WS_LOG_DEBUG, "Accepted service: %s", name);
65606588
ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;

0 commit comments

Comments
 (0)