@@ -39,7 +39,7 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
39
39
offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_key ),
40
40
NULL },
41
41
42
- { ngx_string ("auth_jwt_enabled" ),
42
+ { ngx_string ("auth_jwt_enabled" ),
43
43
NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_FLAG ,
44
44
ngx_conf_set_flag_slot ,
45
45
NGX_HTTP_LOC_CONF_OFFSET ,
@@ -85,6 +85,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
85
85
{
86
86
ngx_int_t n ;
87
87
ngx_str_t jwtCookieName = ngx_string ("rampartjwt" );
88
+ ngx_str_t passportKeyCookieName = ngx_string ("PassportKey" );
88
89
ngx_str_t jwtCookieVal ;
89
90
char * jwtCookieValChrPtr ;
90
91
ngx_http_auth_jwt_loc_conf_t * jwtcf ;
@@ -94,16 +95,14 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
94
95
jwt_alg_t alg ;
95
96
time_t exp ;
96
97
time_t now ;
97
- ngx_str_t passportKeyCookieName = ngx_string ("PassportKey" );
98
- ngx_str_t passportKeyCookieVal ;
99
98
100
99
101
- jwtcf = ngx_http_get_module_loc_conf (r , ngx_http_auth_jwt_module );
100
+ jwtcf = ngx_http_get_module_loc_conf (r , ngx_http_auth_jwt_module );
102
101
103
102
if (!jwtcf -> auth_jwt_enabled )
104
103
{
105
- return NGX_DECLINED ;
106
- }
104
+ return NGX_DECLINED ;
105
+ }
107
106
108
107
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Key: %s, Enabled: %d",
109
108
// jwtcf->auth_jwt_key.data,
@@ -114,9 +113,14 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
114
113
n = ngx_http_parse_multi_header_lines (& r -> headers_in .cookies , & jwtCookieName , & jwtCookieVal );
115
114
if (n == NGX_DECLINED )
116
115
{
117
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "failed to obtain rampartjwt cookie" );
118
- goto redirect ;
119
- }
116
+ // if we can't find the first cookie, check the legacy ___location
117
+ n = ngx_http_parse_multi_header_lines (& r -> headers_in .cookies , & passportKeyCookieName , & jwtCookieVal );
118
+ if (n == NGX_DECLINED )
119
+ {
120
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "failed to obtain a jwt cookie" );
121
+ goto redirect ;
122
+ }
123
+ }
120
124
121
125
// the cookie data is not necessarily null terminated... we need a null terminated character pointer
122
126
jwtCookieValChrPtr = ngx_alloc (jwtCookieVal .len + 1 , r -> connection -> log );
@@ -160,22 +164,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
160
164
goto redirect ;
161
165
}
162
166
163
- // ensure that the user has a matching PassportKey cookie.
164
- // this can be removed once we and our partners no longer use the PassportKey cookie
165
- n = ngx_http_parse_multi_header_lines (& r -> headers_in .cookies , & passportKeyCookieName , & passportKeyCookieVal );
166
- if (n == NGX_DECLINED ) {
167
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "failed to obtain passport cookie" );
168
- goto redirect ;
169
- };
170
-
171
- // compare both cookies
172
- if (ngx_strncmp (jwtCookieVal .data , passportKeyCookieVal .data , jwtCookieVal .len ))
173
- {
174
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "PassportKey cookie does not match rampartjwt cookie" );
175
- goto redirect ;
176
- }
177
-
178
- return NGX_OK ;
167
+ return NGX_OK ;
179
168
180
169
redirect :
181
170
r -> headers_out .___location = ngx_list_push (& r -> headers_out .headers );
@@ -286,4 +275,4 @@ hex_to_binary( const char* str, u_char* buf, int len ) {
286
275
* cpy ++ = low | (high << 4 );
287
276
}
288
277
return 0 ;
289
- }
278
+ }
0 commit comments