@@ -22,6 +22,7 @@ static void * ngx_http_auth_jwt_create_loc_conf(ngx_conf_t *cf);
22
22
static char * ngx_http_auth_jwt_merge_loc_conf (ngx_conf_t * cf , void * parent , void * child );
23
23
static int hex_char_to_binary ( char ch , char * ret );
24
24
static int hex_to_binary ( const char * str , u_char * buf , int len );
25
+ static char * ngx_str_t_to_char_ptr (ngx_pool_t * pool , ngx_str_t str );
25
26
26
27
static ngx_command_t ngx_http_auth_jwt_commands [] = {
27
28
@@ -123,14 +124,12 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
123
124
}
124
125
125
126
// the cookie data is not necessarily null terminated... we need a null terminated character pointer
126
- jwtCookieValChrPtr = ngx_alloc (jwtCookieVal .len + 1 , r -> connection -> log );
127
- ngx_memcpy (jwtCookieValChrPtr , jwtCookieVal .data , jwtCookieVal .len );
128
- * (jwtCookieValChrPtr + jwtCookieVal .len ) = '\0' ;
127
+ jwtCookieValChrPtr = ngx_str_t_to_char_ptr (r -> pool , jwtCookieVal );
129
128
130
129
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "rampartjwt: %s %d", jwtCookieValChrPtr, jwtCookieVal.len);
131
130
132
131
// convert key from hex to binary
133
- keyBinary = ngx_alloc ( jwtcf -> auth_jwt_key .len / 2 , r -> connection -> log );
132
+ keyBinary = ngx_palloc ( r -> pool , jwtcf -> auth_jwt_key .len / 2 );
134
133
if (0 != hex_to_binary ((char * )jwtcf -> auth_jwt_key .data , keyBinary , jwtcf -> auth_jwt_key .len ))
135
134
{
136
135
ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "failed to turn hex key into binary" );
@@ -207,29 +206,24 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
207
206
uri .len = request_uri_var -> len ;
208
207
ngx_memcpy (uri .data , request_uri_var -> data , request_uri_var -> len );
209
208
210
-
211
- char * tmp = ngx_alloc (uri .len + 1 , r -> connection -> log );
212
- ngx_memcpy (tmp , uri .data , uri .len );
213
- * (tmp + uri .len ) = '\0' ;
214
-
215
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "found uri with querystring %s" , tmp );
209
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "found uri with querystring %s", ngx_str_t_to_char_ptr(r->pool, uri));
216
210
}
217
211
else
218
212
{
219
213
// fallback to the querystring without params
220
214
uri = r -> uri ;
221
215
222
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "fallback to querystring without params" );
216
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "fallback to querystring without params");
223
217
}
224
218
225
219
// escape the URI
226
- escaped_len = 2 * ngx_escape_uri (NULL , uri .data , uri .len , NGX_ESCAPE_URI ) + uri .len ;
220
+ escaped_len = 2 * ngx_escape_uri (NULL , uri .data , uri .len , NGX_ESCAPE_ARGS ) + uri .len ;
227
221
uri_escaped .data = ngx_palloc (r -> pool , escaped_len );
228
222
uri_escaped .len = escaped_len ;
229
- ngx_escape_uri (uri_escaped .data , uri .data , uri .len , NGX_ESCAPE_URI );
223
+ ngx_escape_uri (uri_escaped .data , uri .data , uri .len , NGX_ESCAPE_ARGS );
230
224
231
225
r -> headers_out .___location -> value .len = loginlen + sizeof ("?return_url=" ) - 1 + strlen (scheme ) + sizeof ("://" ) - 1 + server .len + uri_escaped .len ;
232
- return_url = ngx_alloc (r -> headers_out .___location -> value .len , r -> connection -> log );
226
+ return_url = ngx_palloc (r -> pool , r -> headers_out .___location -> value .len );
233
227
ngx_memcpy (return_url , jwtcf -> auth_jwt_loginurl .data , jwtcf -> auth_jwt_loginurl .len );
234
228
int return_url_idx = jwtcf -> auth_jwt_loginurl .len ;
235
229
ngx_memcpy (return_url + return_url_idx , "?return_url=" , sizeof ("?return_url=" ) - 1 );
@@ -244,7 +238,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
244
238
return_url_idx += uri_escaped .len ;
245
239
r -> headers_out .___location -> value .data = (u_char * )return_url ;
246
240
247
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "return_url: %s" , return_url );
241
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "return_url: %s", ngx_str_t_to_char_ptr(r->pool, r->headers_out.___location->value) );
248
242
}
249
243
else
250
244
{
@@ -335,7 +329,8 @@ hex_char_to_binary( char ch, char* ret )
335
329
}
336
330
337
331
static int
338
- hex_to_binary ( const char * str , u_char * buf , int len ) {
332
+ hex_to_binary ( const char * str , u_char * buf , int len )
333
+ {
339
334
u_char
340
335
* cpy = buf ;
341
336
char
@@ -357,3 +352,13 @@ hex_to_binary( const char* str, u_char* buf, int len ) {
357
352
return 0 ;
358
353
}
359
354
355
+ /** copies an nginx string structure to a newly allocated character pointer */
356
+ static char * ngx_str_t_to_char_ptr (ngx_pool_t * pool , ngx_str_t str )
357
+ {
358
+ char * char_ptr = ngx_palloc (pool , str .len + 1 );
359
+ ngx_memcpy (char_ptr , str .data , str .len );
360
+ * (char_ptr + str .len ) = '\0' ;
361
+ return char_ptr ;
362
+ }
363
+
364
+
0 commit comments