Blame SOURCES/0021-prevent-XSS-and-open-redirect-on-OIDC-session-manage.patch

5f8edb
From a1b8e7aa92e5e624a5f90bb736c307dae22230a1 Mon Sep 17 00:00:00 2001
5f8edb
From: Hans Zandbelt <hans.zandbelt@zmartzone.eu>
5f8edb
Date: Mon, 27 Jul 2020 19:35:29 +0200
5f8edb
Subject: [PATCH 2/4] prevent XSS and open redirect on OIDC session
5f8edb
 managemement OP iframe
5f8edb
5f8edb
- apply OIDCRedirectURLsAllowed on the login_uri parameter
5f8edb
- thanks Andrew Brady
5f8edb
- bump to 2.4.4rc3
5f8edb
5f8edb
Signed-off-by: Hans Zandbelt <hans.zandbelt@zmartzone.eu>
5f8edb
(cherry picked from commit 51d997899afea6ea454abda49bd4cd41aa7c0cdc)
5f8edb
---
5f8edb
 ChangeLog              | 12 ++++++------
5f8edb
 auth_openidc.conf      |  3 ++-
5f8edb
 configure.ac           |  2 +-
5f8edb
 src/mod_auth_openidc.c | 21 +++++++++++++++++----
5f8edb
 4 files changed, 26 insertions(+), 12 deletions(-)
5f8edb
5f8edb
diff --git a/ChangeLog b/ChangeLog
5f8edb
index eba2ebc..075f98d 100644
5f8edb
--- a/ChangeLog
5f8edb
+++ b/ChangeLog
5f8edb
@@ -86,7 +86,7 @@
5f8edb
 - bump to 2.3.5rc0
5f8edb
 
5f8edb
 04/27/2018
5f8edb
-- avoid crash when a relative logout URL parameter is passed in; thanks Vivien Delenne 
5f8edb
+- avoid crash when a relative logout URL parameter is passed in; thanks Vivien Delenne
5f8edb
 - release 2.3.4
5f8edb
 
5f8edb
 03/22/2018
5f8edb
@@ -258,7 +258,7 @@
5f8edb
 - bump to 2.2.1rc6
5f8edb
 
5f8edb
 05/18/2017
5f8edb
-- fix parse function of OIDCRequestObject configuration option; thanks @suttod 
5f8edb
+- fix parse function of OIDCRequestObject configuration option; thanks @suttod
5f8edb
 
5f8edb
 05/17/2017
5f8edb
 - avoid crash when the X-Forwarded-Proto header is not correctly set by a reverse proxy in front of mod_auth_openidc
5f8edb
@@ -325,7 +325,7 @@
5f8edb
 
5f8edb
 02/20/2017
5f8edb
 - security fix: scrub headers for "AuthType oauth20"
5f8edb
-- release 2.1.6 
5f8edb
+- release 2.1.6
5f8edb
 
5f8edb
 02/15/2017
5f8edb
 - improve logging of session max duration and session inactivity timeout
5f8edb
@@ -534,7 +534,7 @@
5f8edb
 - bump to 1.9.0rc3
5f8edb
 
5f8edb
 7/19/2016
5f8edb
-- add support for chunked session cookies; closes #153; thanks @glatzert 
5f8edb
+- add support for chunked session cookies; closes #153; thanks @glatzert
5f8edb
 - bump to 1.9.0rc2
5f8edb
 
5f8edb
 7/9/2016
5f8edb
@@ -911,7 +911,7 @@
5f8edb
 
5f8edb
 1/1/2015
5f8edb
 - update copyright to 2015
5f8edb
-- use json_int_t (seconds) for "exp" and "iat" fields, instead of apr_time_t (microseconds) 
5f8edb
+- use json_int_t (seconds) for "exp" and "iat" fields, instead of apr_time_t (microseconds)
5f8edb
 - correct expiry debug printout
5f8edb
 - bump to 1.7.2rc1
5f8edb
 
5f8edb
@@ -1191,7 +1191,7 @@
5f8edb
 - support using a Bearer token on client registration calls
5f8edb
 
5f8edb
 4/22/2014
5f8edb
-- match request and response type 
5f8edb
+- match request and response type
5f8edb
 - check at_hash value on "token id_token" implicit flow
5f8edb
 - use shared memory caching by default
5f8edb
 - release 1.2
5f8edb
diff --git a/auth_openidc.conf b/auth_openidc.conf
5f8edb
index 87685f6..75cdb8e 100644
5f8edb
--- a/auth_openidc.conf
5f8edb
+++ b/auth_openidc.conf
5f8edb
@@ -786,7 +786,8 @@
5f8edb
 #OIDCStateInputHeaders [none|user-agent|x-forwarded-for|both]
5f8edb
 
5f8edb
 # Define one or more regular expressions that specify URLs (or domains) allowed for post logout and
5f8edb
-# other redirects such as the "return_to" value on refresh token requests, e.g.:
5f8edb
+# other redirects such as the "return_to" value on refresh token requests, and the "login_uri" value
5f8edb
+# on session management based logins through the OP iframe, e.g.:
5f8edb
 #   OIDCRedirectURLsAllowed ^https://www.example.com ^https://(\w+).example.org ^https://example.net/app
5f8edb
 # or:
5f8edb
 #   OIDCRedirectURLsAllowed ^https://www.example.com/logout$ ^https://www.example.com/app/return_to$ 
5f8edb
diff --git a/configure.ac b/configure.ac
5f8edb
index ad5ba0e..c61d117 100644
5f8edb
--- a/configure.ac
5f8edb
+++ b/configure.ac
5f8edb
@@ -91,7 +91,7 @@ HAVE_LIBJQ=0
5f8edb
 
5f8edb
 AC_ARG_WITH(jq,
5f8edb
         [  --with-jq=PATH          location of your libjq installation])
5f8edb
-    
5f8edb
+
5f8edb
 if test -n "$with_jq"
5f8edb
 then
5f8edb
     JQ_CFLAGS="-I$with_jq/include"
5f8edb
diff --git a/src/mod_auth_openidc.c b/src/mod_auth_openidc.c
5f8edb
index 215ed5e..68fbca5 100644
5f8edb
--- a/src/mod_auth_openidc.c
5f8edb
+++ b/src/mod_auth_openidc.c
5f8edb
@@ -2688,7 +2688,8 @@ static int oidc_handle_logout_request(request_rec *r, oidc_cfg *c,
5f8edb
 }
5f8edb
 
5f8edb
 static apr_byte_t oidc_validate_redirect_url(request_rec *r, oidc_cfg *c,
5f8edb
-		const char *url, char **err_str, char **err_desc) {
5f8edb
+		const char *url, apr_byte_t restrict_to_host, char **err_str,
5f8edb
+		char **err_desc) {
5f8edb
 	apr_uri_t uri;
5f8edb
 	const char *c_host = NULL;
5f8edb
 	apr_hash_index_t *hi = NULL;
5f8edb
@@ -2717,7 +2718,7 @@ static apr_byte_t oidc_validate_redirect_url(request_rec *r, oidc_cfg *c,
5f8edb
 			oidc_error(r, "%s: %s", *err_str, *err_desc);
5f8edb
 			return FALSE;
5f8edb
 		}
5f8edb
-	} else if (uri.hostname != NULL) {
5f8edb
+	} else if ((uri.hostname != NULL) && (restrict_to_host == TRUE)) {
5f8edb
 		c_host = oidc_get_current_url_host(r);
5f8edb
 		if ((strstr(c_host, uri.hostname) == NULL)
5f8edb
 				|| (strstr(uri.hostname, c_host) == NULL)) {
5f8edb
@@ -2792,7 +2793,7 @@ static int oidc_handle_logout(request_rec *r, oidc_cfg *c,
5f8edb
 	} else {
5f8edb
 
5f8edb
 		/* do input validation on the logout parameter value */
5f8edb
-		if (oidc_validate_redirect_url(r, c, url, &error_str,
5f8edb
+		if (oidc_validate_redirect_url(r, c, url, TRUE, &error_str,
5f8edb
 				&error_description) == FALSE) {
5f8edb
 			return oidc_util_html_send_error(r, c->error_template, error_str,
5f8edb
 					error_description,
5f8edb
@@ -2948,6 +2949,18 @@ static int oidc_handle_session_management_iframe_rp(request_rec *r, oidc_cfg *c,
5f8edb
 	if (s_poll_interval == NULL)
5f8edb
 		s_poll_interval = "3000";
5f8edb
 
5f8edb
+	int poll_interval = s_poll_interval ? strtol(s_poll_interval, NULL, 10) : 0;
5f8edb
+	if ((poll_interval <= 0) || (poll_interval > 3600 * 24))
5f8edb
+		poll_interval = 3000;
5f8edb
+
5f8edb
+	char *login_uri = NULL, *error_str = NULL, *error_description = NULL;
5f8edb
+	oidc_util_get_request_parameter(r, "login_uri", &login_uri);
5f8edb
+	if ((login_uri != NULL)
5f8edb
+			&& (oidc_validate_redirect_url(r, c, login_uri, FALSE, &error_str,
5f8edb
+					&error_description) == FALSE)) {
5f8edb
+		return HTTP_BAD_REQUEST;
5f8edb
+	}
5f8edb
+
5f8edb
 	const char *redirect_uri = oidc_get_redirect_uri(r, c);
5f8edb
 	java_script = apr_psprintf(r->pool, java_script, origin, client_id,
5f8edb
 			session_state, op_iframe_id, s_poll_interval, redirect_uri,
5f8edb
@@ -3061,7 +3074,7 @@ static int oidc_handle_refresh_token_request(request_rec *r, oidc_cfg *c,
5f8edb
 	}
5f8edb
 
5f8edb
 	/* do input validation on the return to parameter value */
5f8edb
-	if (oidc_validate_redirect_url(r, c, return_to, &error_str,
5f8edb
+	if (oidc_validate_redirect_url(r, c, return_to, TRUE, &error_str,
5f8edb
 			&error_description) == FALSE) {
5f8edb
 		oidc_error(r, "return_to URL validation failed: %s: %s", error_str,
5f8edb
 				error_description);
5f8edb
-- 
5f8edb
2.31.1
5f8edb