From: Shuanglei Tao Date: Sat, 6 Mar 2021 09:37:30 +0000 (+0800) Subject: protocol: fix auth token check X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=f67feebcc2a7d169336102d0ec906fe2425191c4;p=ttyd.git protocol: fix auth token check --- diff --git a/src/protocol.c b/src/protocol.c index 94e4d01..02eb95d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -284,16 +284,17 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (pss->process != NULL) break; uint16_t columns = 0; uint16_t rows = 0; - char *token = NULL; json_object *obj = parse_window_size(pss->buffer, pss->len, &columns, &rows); if (server->credential != NULL) { struct json_object *o = NULL; if (json_object_object_get_ex(obj, "AuthToken", &o)) { const char *token = json_object_get_string(o); - pss->authenticated = token != NULL && !strcmp(token, server->credential); + if (token != NULL && !strcmp(token, server->credential)) + pss->authenticated = true; + else + lwsl_warn("WS authentication failed with token: %s\n", token); } if (!pss->authenticated) { - lwsl_warn("WS authentication failed with token: %s\n", token); json_object_put(obj); lws_close_reason(wsi, LWS_CLOSE_STATUS_POLICY_VIOLATION, NULL, 0); return -1;