Skip to content

Commit 1b6c771

Browse files
author
Rafał Miłecki
committed
Detect redirection command in failed authentication response
In some situations server may command user agent to redirect to a specific page as a result of a failed authentication attempt. Examples of such responses: 1. ret=0,redir=/remote/login?&err=sslvpn_login_permission_denied&lang=en 2. ret=0,redir=/remote/login?&err=sslvpn_login_password_expired&lang=en When using a real web browser it results in JavaScript redirecting user to the URL from "redir" key. Those redirection URLs may contain a meaningful error code (see examples above). Check them and log a relevant error message with "err" parameter value if present. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
1 parent 12fc457 commit 1b6c771

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/http.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,29 @@ int auth_log_in(struct tunnel *tunnel)
718718
ret = get_value_from_response(res, "ret=", auth_ret_text, 8);
719719
if (ret == 1) {
720720
int auth_ret = strtol(auth_ret_text, NULL, 10);
721+
char redir[128];
721722

722723
switch (auth_ret) {
723724
case 0:
724725
log_error("Authentication failed\n");
726+
727+
ret = get_value_from_response(res, "redir=", redir, 128);
728+
if (ret == 1) {
729+
const char *err_start;
730+
731+
log_debug("Received redirection: \"%s\"\n", redir);
732+
733+
/* Check for error value in the redirection URL */
734+
err_start = strstr(redir, "err=");
735+
if (err_start) {
736+
const char *err_end = strstr(err_start, "&");
737+
738+
log_error("Authentication ended up in redirection with error value: \"%.*s\"\n",
739+
err_end ? err_end - err_start - 4 : -1,
740+
err_start + 4);
741+
}
742+
}
743+
725744
ret = ERR_HTTP_PERMISSION;
726745
goto end;
727746
case 1:

0 commit comments

Comments
 (0)