@@ -94,6 +94,14 @@ func analyze(fname string, stmt *Directive, term string, ctx blockCtx, options *
9494 masks , knownDirective := directives [stmt .Directive ]
9595 currCtx , knownContext := contexts [ctx .key ()]
9696
97+ if ! knownDirective {
98+ for _ , matchFn := range options .MatchFuncs {
99+ if masks , knownDirective = matchFn (stmt .Directive ); knownDirective {
100+ break
101+ }
102+ }
103+ }
104+
97105 // if strict and directive isn't recognized then throw error
98106 if options .ErrorOnUnknownDirectives && ! knownDirective {
99107 return & ParseError {
@@ -2401,9 +2409,13 @@ var directives = map[string][]uint{
24012409 "zone_sync_timeout" : {
24022410 ngxStreamMainConf | ngxStreamSrvConf | ngxConfTake1 ,
24032411 },
2412+ }
24042413
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+ //
2417+ //nolint:gochecknoglobals
2418+ var appProtectWAFv4Directives = map [string ][]uint {
24072419 "app_protect_compressed_requests_action" : {
24082420 ngxHTTPMainConf | ngxConfTake1 ,
24092421 },
@@ -2441,3 +2453,59 @@ var directives = map[string][]uint{
24412453 ngxHTTPMainConf | ngxConfTake1 ,
24422454 },
24432455}
2456+
2457+ // MatchAppProtectWAFv4 is a match function for parsing an NGINX config that contains the
2458+ // App Protect v4 module.
2459+ func MatchAppProtectWAFv4 (directive string ) ([]uint , bool ) {
2460+ masks , matched := appProtectWAFv4Directives [directive ]
2461+ return masks , matched
2462+ }
2463+
2464+ //nolint:gochecknoglobals
2465+ var appProtectWAFv5Directives = map [string ][]uint {
2466+ // https://docs.nginx.com/nginx-app-protect-waf/v5/configuration-guide/configuration/#global-directives
2467+ "app_protect_physical_memory_util_thresholds" : {
2468+ ngxHTTPMainConf | ngxConfTake2 ,
2469+ },
2470+ "app_protect_cpu_thresholds" : {
2471+ ngxHTTPMainConf | ngxConfTake2 ,
2472+ },
2473+ "app_protect_failure_mode_action" : {
2474+ ngxHTTPMainConf | ngxConfTake1 ,
2475+ },
2476+ "app_protect_cookie_seed" : {
2477+ ngxHTTPMainConf | ngxConfTake1 ,
2478+ },
2479+ "app_protect_request_buffer_overflow_action" : {
2480+ ngxHTTPMainConf | ngxConfTake1 ,
2481+ },
2482+ "app_protect_reconnect_period_seconds" : {
2483+ ngxHTTPMainConf | ngxConfTake1 ,
2484+ },
2485+ // https://docs.nginx.com/nginx-app-protect-waf/v5/configuration-guide/configuration/#app-protect-specific-directives
2486+ "app_protect_enforcer_address" : {
2487+ ngxHTTPMainConf | ngxConfTake1 ,
2488+ },
2489+ "app_protect_enable" : {
2490+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfFlag ,
2491+ },
2492+ "app_protect_policy_file" : {
2493+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfTake1 ,
2494+ },
2495+ "app_protect_security_log_enable" : {
2496+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfFlag ,
2497+ },
2498+ "app_protect_security_log" : {
2499+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfTake2 ,
2500+ },
2501+ "app_protect_custom_log_attribute" : {
2502+ ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfTake2 ,
2503+ },
2504+ }
2505+
2506+ // MatchAppProtectWAFv5 is a match function for parsing an NGINX config that contains the
2507+ // App Protect v5 module.
2508+ func MatchAppProtectWAFv5 (directive string ) ([]uint , bool ) {
2509+ masks , matched := appProtectWAFv5Directives [directive ]
2510+ return masks , matched
2511+ }
0 commit comments