@@ -242,8 +242,6 @@ void ngx_http_lua_set_sa_restart(ngx_log_t *log);
242
242
#endif
243
243
244
244
size_t ngx_http_lua_escape_log (u_char * dst , u_char * src , size_t size );
245
- ngx_int_t ngx_http_lua_check_header_safe (ngx_http_request_t * r , u_char * str ,
246
- size_t len );
247
245
248
246
249
247
static ngx_inline void
@@ -491,6 +489,58 @@ ngx_inet_get_port(struct sockaddr *sa)
491
489
#endif
492
490
493
491
492
+ static ngx_inline ngx_int_t
493
+ ngx_http_lua_check_unsafe_header (ngx_http_request_t * r , u_char * str , size_t len )
494
+ {
495
+ size_t i , buf_len ;
496
+ u_char c ;
497
+ u_char * buf , * src = str ;
498
+
499
+ /* %00-%1F, %7F */
500
+
501
+ static uint32_t unsafe [] = {
502
+ 0xffffffff , /* 1111 1111 1111 1111 1111 1111 1111 1111 */
503
+
504
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
505
+ 0x00000000 , /* 0000 0000 0000 0000 0000 0000 0000 0000 */
506
+
507
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
508
+ 0x00000000 , /* 0000 0000 0000 0000 0000 0000 0000 0000 */
509
+
510
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
511
+ 0x80000000 , /* 1000 0000 0000 0000 0000 0000 0000 0000 */
512
+
513
+ 0x00000000 , /* 0000 0000 0000 0000 0000 0000 0000 0000 */
514
+ 0x00000000 , /* 0000 0000 0000 0000 0000 0000 0000 0000 */
515
+ 0x00000000 , /* 0000 0000 0000 0000 0000 0000 0000 0000 */
516
+ 0x00000000 /* 0000 0000 0000 0000 0000 0000 0000 0000 */
517
+ };
518
+
519
+ for (i = 0 ; i < len ; i ++ , str ++ ) {
520
+ c = * str ;
521
+ if (unsafe [c >> 5 ] & (1 << (c & 0x1f ))) {
522
+ buf_len = ngx_http_lua_escape_log (NULL , src , len );
523
+ buf = ngx_palloc (r -> pool , buf_len );
524
+ if (buf == NULL ) {
525
+ return NGX_ERROR ;
526
+ }
527
+
528
+ ngx_http_lua_escape_log (buf , src , len );
529
+
530
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
531
+ "unsafe byte \"0x%uxd\" in header \"%*s\"" ,
532
+ (unsigned ) c , buf_len , buf );
533
+
534
+ ngx_pfree (r -> pool , buf );
535
+
536
+ return NGX_ERROR ;
537
+ }
538
+ }
539
+
540
+ return NGX_OK ;
541
+ }
542
+
543
+
494
544
extern ngx_uint_t ngx_http_lua_location_hash ;
495
545
extern ngx_uint_t ngx_http_lua_content_length_hash ;
496
546
0 commit comments