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

Commit 951123a

Browse files
authored
add internal rule with id #19 that is triggered when no MainRules are present
1 parent 6001fc3 commit 951123a

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

naxsi_src/naxsi_runtime.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ ngx_http_rule_t nx_int__empty_post_body = {/*type*/ 0, /*whitelist flag*/ 0,
108108
ngx_http_rule_t *nx_int__libinject_sql; /*ID:17*/
109109
ngx_http_rule_t *nx_int__libinject_xss; /*ID:18*/
110110

111+
ngx_http_rule_t nx_int__no_rules = {/*type*/ 0, /*whitelist flag*/ 0,
112+
/*wl_id ptr*/ NULL, /*rule_id*/ 19,
113+
/*log_msg*/ NULL, /*score*/ 0,
114+
/*sscores*/ NULL,
115+
/*sc_block*/ 0, /*sc_allow*/ 0,
116+
/*block*/ 0, /*allow*/ 0, /*drop*/ 1, /*log*/ 0,
117+
/*br ptrs*/ NULL};
118+
111119

112120

113121

@@ -2105,7 +2113,9 @@ ngx_http_dummy_uri_parse(ngx_http_dummy_main_conf_t *main_cf,
21052113
if ( (ctx->block && !ctx->learning) || ctx->drop )
21062114
return ;
21072115
if (!main_cf->generic_rules && !cf->generic_rules) {
2108-
dummy_error_fatal(ctx, r, "no generic rules ?!");
2116+
tmp.data = NULL;
2117+
tmp.len = 0;
2118+
ngx_http_apply_rulematch_v_n(&nx_int__no_rules, ctx, r, &tmp, &tmp, URL, 1, 0);
21092119
return ;
21102120
}
21112121
tmp.len = r->uri.len;

t/31norules.t

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#vi:filetype=perl
2+
3+
4+
# A AJOUTER :
5+
# TEST CASE AVEC UNE REGLE SUR UN HEADER GENERIQUE
6+
# La même sur des arguments :)
7+
8+
use lib 'lib';
9+
use Test::Nginx::Socket;
10+
11+
repeat_each(3);
12+
13+
plan tests => repeat_each(1) * blocks();
14+
no_root_location();
15+
no_long_string();
16+
$ENV{TEST_NGINX_SERVROOT} = server_root();
17+
run_tests();
18+
19+
20+
__DATA__
21+
=== TEST 1: Basic GET request with no rules, drop
22+
--- main_config
23+
load_module /tmp/naxsi_ut/modules/ngx_http_naxsi_module.so;
24+
--- config
25+
location / {
26+
SecRulesEnabled;
27+
LearningMode;
28+
DeniedUrl "/RequestDenied";
29+
CheckRule "$SQL >= 8" BLOCK;
30+
CheckRule "$RFI >= 8" BLOCK;
31+
CheckRule "$TRAVERSAL >= 4" BLOCK;
32+
CheckRule "$XSS >= 8" BLOCK;
33+
LibInjectionXss;
34+
CheckRule "$LIBINJECTION_XSS >= 8" BLOCK;
35+
LibInjectionSql;
36+
CheckRule "$LIBINJECTION_SQL >= 8" BLOCK;
37+
38+
root $TEST_NGINX_SERVROOT/html/;
39+
index index.html index.htm;
40+
}
41+
location /RequestDenied {
42+
return 412;
43+
}
44+
--- request
45+
GET /?a=buibui
46+
--- error_code: 412
47+
=== TEST 1.1: Basic GET request with no rules, whitelist the special rule.
48+
--- main_config
49+
load_module /tmp/naxsi_ut/modules/ngx_http_naxsi_module.so;
50+
--- config
51+
location / {
52+
SecRulesEnabled;
53+
BasicRule wl:19;
54+
LearningMode;
55+
DeniedUrl "/RequestDenied";
56+
CheckRule "$SQL >= 8" BLOCK;
57+
CheckRule "$RFI >= 8" BLOCK;
58+
CheckRule "$TRAVERSAL >= 4" BLOCK;
59+
CheckRule "$XSS >= 8" BLOCK;
60+
LibInjectionXss;
61+
CheckRule "$LIBINJECTION_XSS >= 8" BLOCK;
62+
LibInjectionSql;
63+
CheckRule "$LIBINJECTION_SQL >= 8" BLOCK;
64+
65+
root $TEST_NGINX_SERVROOT/html/;
66+
index index.html index.htm;
67+
}
68+
location /RequestDenied {
69+
return 412;
70+
}
71+
--- request
72+
GET /?a=buibui
73+
--- error_code: 200

0 commit comments

Comments
 (0)