Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Fix #418 : Bad parsing of quoted json #420

Merged
merged 2 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions naxsi_src/naxsi_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ngx_http_nx_json_quoted(ngx_json_t *js, ngx_str_t *ve)
if (*(js->src+js->off) == '\\') {
js->off += 2;
if (js->off >= js->len) break;
continue;
}
if (*(js->src+js->off) == '"') {
vn_end = js->src+js->off;
Expand Down Expand Up @@ -161,7 +162,7 @@ ngx_http_nx_json_val(ngx_json_t *js) {
ngx_http_basestr_ruleset_n(js->r->pool, &js->ckey, &val,
js->main_cf->body_rules, js->r, js->ctx,
BODY);
NX_DEBUG(_debug_json, NGX_LOG_DEBUG_HTTP, js->r->connection->log, 0, "JSON '%V' : '%V'",
NX_DEBUG(_debug_json, NGX_LOG_DEBUG_HTTP, js->r->connection->log, 0, "quoted-JSON '%V' : '%V'",
&(js->ckey), &(val));
}
return (ret);
Expand Down Expand Up @@ -318,7 +319,7 @@ ngx_http_dummy_json_parse(ngx_http_request_ctx_t *ctx,
{
ngx_json_t *js;


js = ngx_pcalloc(r->pool, sizeof(ngx_json_t));
if (!js) return ;
js->json.data = js->src = src;
Expand All @@ -327,7 +328,7 @@ ngx_http_dummy_json_parse(ngx_http_request_ctx_t *ctx,
js->ctx = ctx;
js->loc_cf = ngx_http_get_module_loc_conf(r, ngx_http_naxsi_module);
js->main_cf = ngx_http_get_module_main_conf(r, ngx_http_naxsi_module);

if (ngx_http_nx_json_seek(js, '{')) {
ngx_http_apply_rulematch_v_n(&nx_int__invalid_json, ctx, r, NULL, NULL, BODY, 1, 0);
return ;
Expand Down
32 changes: 32 additions & 0 deletions t/14json.t
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,35 @@ use URI::Escape;
\"fu\" : { \"aa\" : \"bb\"
}"
--- error_code: 412

=== JSON14 : bug_418
--- main_config
load_module /tmp/naxsi_ut/modules/ngx_http_naxsi_module.so;
--- http_config
include /tmp/naxsi_ut/naxsi_core.rules;
--- config
set $naxsi_extensive_log 1;
location / {
SecRulesEnabled;
DeniedUrl "/RequestDenied";
CheckRule "$SQL >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$TRAVERSAL >= 4" BLOCK;
CheckRule "$XSS >= 8" BLOCK;
root $TEST_NGINX_SERVROOT/html/;
index index.html index.htm;
error_page 405 = $uri;
}
location /RequestDenied {
return 412;
}
--- more_headers
Content-Type: application/json
--- request eval
use URI::Escape;
"POST /
{
\"error\":
\"ERROR_REPORT:{\\\"request\\\":{\\\"bar\\\":\\\"\\\"},\\\"response\\\":{\\\"bar\\\":[{\\\"schema_id\\\":\\\"foo\\\"}]}}\"
}"
--- error_code: 412