@@ -94,6 +94,14 @@ func analyze(fname string, stmt *Directive, term string, ctx blockCtx, options *
94
94
masks , knownDirective := directives [stmt .Directive ]
95
95
currCtx , knownContext := contexts [ctx .key ()]
96
96
97
+ if ! knownDirective {
98
+ for _ , matchFn := range options .MatchFuncs {
99
+ if masks , knownDirective = matchFn (stmt .Directive ); knownDirective {
100
+ break
101
+ }
102
+ }
103
+ }
104
+
97
105
// if strict and directive isn't recognized then throw error
98
106
if options .ErrorOnUnknownDirectives && ! knownDirective {
99
107
return & ParseError {
@@ -2401,9 +2409,11 @@ var directives = map[string][]uint{
2401
2409
"zone_sync_timeout" : {
2402
2410
ngxStreamMainConf | ngxStreamSrvConf | ngxConfTake1 ,
2403
2411
},
2412
+ }
2404
2413
2405
- // nginx app protect specific and global directives
2406
- // [https://docs.nginx.com/nginx-app-protect/configuration-guide/configuration/#directives]
2414
+ // nginx app protect specific and global directives
2415
+ // [https://docs.nginx.com/nginx-app-protect/configuration-guide/configuration/#directives]
2416
+ var appProtectWAFv4Directives = map [string ][]uint {
2407
2417
"app_protect_compressed_requests_action" : {
2408
2418
ngxHTTPMainConf | ngxConfTake1 ,
2409
2419
},
@@ -2441,3 +2451,58 @@ var directives = map[string][]uint{
2441
2451
ngxHTTPMainConf | ngxConfTake1 ,
2442
2452
},
2443
2453
}
2454
+
2455
+ // MatchAppProtectWAFv4 is a match function for parsing an NGINX config that contains the
2456
+ // App Protect v4 module.
2457
+ func MatchAppProtectWAFv4 (directive string ) (masks []uint , matched bool ) {
2458
+ masks , matched = appProtectWAFv4Directives [directive ]
2459
+ return
2460
+ }
2461
+
2462
+ var appProtectWAFv5Directives = map [string ][]uint {
2463
+ // https://docs.nginx.com/nginx-app-protect-waf/v5/configuration-guide/configuration/#global-directives
2464
+ "app_protect_physical_memory_util_thresholds" : {
2465
+ ngxHTTPMainConf | ngxConfTake2 ,
2466
+ },
2467
+ "app_protect_cpu_thresholds" : {
2468
+ ngxHTTPMainConf | ngxConfTake2 ,
2469
+ },
2470
+ "app_protect_failure_mode_action" : {
2471
+ ngxHTTPMainConf | ngxConfTake1 ,
2472
+ },
2473
+ "app_protect_cookie_seed" : {
2474
+ ngxHTTPMainConf | ngxConfTake1 ,
2475
+ },
2476
+ "app_protect_request_buffer_overflow_action" : {
2477
+ ngxHTTPMainConf | ngxConfTake1 ,
2478
+ },
2479
+ "app_protect_reconnect_period_seconds" : {
2480
+ ngxHTTPMainConf | ngxConfTake1 ,
2481
+ },
2482
+ // https://docs.nginx.com/nginx-app-protect-waf/v5/configuration-guide/configuration/#app-protect-specific-directives
2483
+ "app_protect_enforcer_address" : {
2484
+ ngxHTTPMainConf | ngxConfTake1 ,
2485
+ },
2486
+ "app_protect_enable" : {
2487
+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfFlag ,
2488
+ },
2489
+ "app_protect_policy_file" : {
2490
+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfTake1 ,
2491
+ },
2492
+ "app_protect_security_log_enable" : {
2493
+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfFlag ,
2494
+ },
2495
+ "app_protect_security_log" : {
2496
+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfTake2 ,
2497
+ },
2498
+ "app_protect_custom_log_attribute" : {
2499
+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLmtConf | ngxConfTake2 ,
2500
+ },
2501
+ }
2502
+
2503
+ // MatchAppProtectWAFv5 is a match function for parsing an NGINX config that contains the
2504
+ // App Protect v5 module.
2505
+ func MatchAppProtectWAFv5 (directive string ) (masks []uint , matched bool ) {
2506
+ masks , matched = appProtectWAFv5Directives [directive ]
2507
+ return
2508
+ }
0 commit comments