@@ -98,6 +98,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
98
98
jwt_alg_t alg ;
99
99
time_t exp ;
100
100
time_t now ;
101
+ int BEARER_LEN = 7 ; // strlen("Bearer ");
101
102
102
103
jwtcf = ngx_http_get_module_loc_conf (r , ngx_http_auth_jwt_module );
103
104
@@ -110,16 +111,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
110
111
// jwtcf->auth_jwt_key.data,
111
112
// jwtcf->auth_jwt_enabled);
112
113
113
- ngx_table_elt_t * h ;
114
- ngx_str_t authorizationHeaderName = ngx_string ("Authorization" );
115
- h = search_headers_in (r , authorizationHeaderName .data , authorizationHeaderName .len );
116
- if (h != NULL )
117
- {
118
- char * authvalue = ngx_str_t_to_char_ptr (r -> pool , h -> value );
119
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "authorization header %s" , authvalue );
120
- }
121
-
122
-
123
114
124
115
// get the cookie
125
116
// TODO: the cookie name could be passed in dynamicallly
@@ -175,6 +166,29 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
175
166
goto redirect ;
176
167
}
177
168
169
+ // if an Authorization header exists, it must match the cookie
170
+ ngx_table_elt_t * authorizationHeader ;
171
+ ngx_str_t authorizationHeaderName = ngx_string ("Authorization" );
172
+ authorizationHeader = search_headers_in (r , authorizationHeaderName .data , authorizationHeaderName .len );
173
+ if (authorizationHeader != NULL )
174
+ {
175
+ // compare lengths first
176
+ if (authorizationHeader -> value .len != jwtCookieVal .len + BEARER_LEN )
177
+ {
178
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Authorization and Cookie do not match lengths" );
179
+ goto redirect ;
180
+ }
181
+
182
+ if (0 != strncmp (authorizationHeader -> value .data + BEARER_LEN , jwtCookieVal .data ))
183
+ {
184
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Authorization and Cookie do not match content" );
185
+ goto redirect ;
186
+ }
187
+
188
+ char * authvalue = ngx_str_t_to_char_ptr (r -> pool , authorizationHeader -> value );
189
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "authorization header %s" , authvalue );
190
+ }
191
+
178
192
return NGX_OK ;
179
193
180
194
redirect :
0 commit comments