4747#include "state.h"
4848#include "util.h"
4949
50- static int oidc_request_check_cookie_domain (request_rec * r , oidc_cfg_t * c , oidc_proto_state_t * proto_state ,
51- const char * original_url ) {
50+ apr_byte_t oidc_request_check_cookie_domain (request_rec * r , oidc_cfg_t * c , const char * original_url ) {
5251 /*
5352 * printout errors if Cookie settings are not going to work
5453 */
@@ -58,44 +57,41 @@ static int oidc_request_check_cookie_domain(request_rec *r, oidc_cfg_t *c, oidc_
5857 _oidc_memset (& r_uri , 0 , sizeof (apr_uri_t ));
5958 apr_uri_parse (r -> pool , original_url , & o_uri );
6059 apr_uri_parse (r -> pool , oidc_util_redirect_uri (r , c ), & r_uri );
61- if ((_oidc_strcmp (o_uri .scheme , r_uri .scheme ) != 0 ) && (_oidc_strcmp (r_uri .scheme , "https" ) == 0 )) {
60+ if ((_oidc_strnatcasecmp (o_uri .scheme , r_uri .scheme ) != 0 ) && (_oidc_strcmp (r_uri .scheme , "https" ) == 0 )) {
6261 oidc_error (r ,
6362 "the URL scheme (%s) of the configured " OIDCRedirectURI
6463 " does not match the URL scheme of the URL being accessed (%s): the \"state\" and "
6564 "\"session\" cookies will not be shared between the two!" ,
6665 r_uri .scheme , o_uri .scheme );
67- oidc_proto_state_destroy (proto_state );
68- return HTTP_INTERNAL_SERVER_ERROR ;
66+ return FALSE;
6967 }
7068
7169 if (oidc_cfg_cookie_domain_get (c ) == NULL ) {
72- if (_oidc_strcmp (o_uri .hostname , r_uri .hostname ) != 0 ) {
70+ if (_oidc_strnatcasecmp (o_uri .hostname , r_uri .hostname ) != 0 ) {
7371 char * p = _oidc_strstr (o_uri .hostname , r_uri .hostname );
7472 if ((p == NULL ) || (_oidc_strcmp (r_uri .hostname , p ) != 0 )) {
7573 oidc_error (r ,
7674 "the URL hostname (%s) of the configured " OIDCRedirectURI
7775 " does not match the URL hostname of the URL being accessed (%s): the "
7876 "\"state\" and \"session\" cookies will not be shared between the two!" ,
7977 r_uri .hostname , o_uri .hostname );
80- oidc_proto_state_destroy (proto_state );
8178 OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHN_REQUEST_ERROR_URL );
82- return HTTP_INTERNAL_SERVER_ERROR ;
79+ return FALSE ;
8380 }
8481 }
8582 } else {
86- if (!oidc_util_cookie_domain_valid (r_uri .hostname , oidc_cfg_cookie_domain_get (c ))) {
83+ if (!oidc_util_cookie_domain_valid (o_uri .hostname , oidc_cfg_cookie_domain_get (c ))) {
8784 oidc_error (r ,
8885 "the domain (%s) configured in " OIDCCookieDomain
8986 " does not match the URL hostname (%s) of the URL being accessed (%s): setting "
9087 "\"state\" and \"session\" cookies will not work!!" ,
9188 oidc_cfg_cookie_domain_get (c ), o_uri .hostname , original_url );
92- oidc_proto_state_destroy (proto_state );
9389 OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHN_REQUEST_ERROR_URL );
94- return HTTP_INTERNAL_SERVER_ERROR ;
90+ return FALSE ;
9591 }
9692 }
9793
98- return OK ;
94+ return TRUE ;
9995}
10096
10197static const char * oidc_request_samesite_cookie (request_rec * r , struct oidc_cfg_t * c ) {
@@ -248,10 +244,9 @@ int oidc_request_authenticate_user(request_rec *r, oidc_cfg_t *c, oidc_provider_
248244 return rc ;
249245 }
250246
251- rc = oidc_request_check_cookie_domain (r , c , proto_state , original_url );
252- if (rc != OK ) {
247+ if (oidc_request_check_cookie_domain (r , c , original_url ) == FALSE) {
253248 oidc_proto_state_destroy (proto_state );
254- return rc ;
249+ return HTTP_INTERNAL_SERVER_ERROR ;
255250 }
256251
257252 /* send off to the OpenID Connect Provider */
0 commit comments