Skip to content

Commit d67a5b8

Browse files
committed
Upgrade OWASP_MODSECURITY_CRS_VERSION 3.3.5 to 4.4.0 and update docs
Signed-off-by: jessebot <jessebot@linux.com>
1 parent f228895 commit d67a5b8

File tree

2 files changed

+100
-9
lines changed

2 files changed

+100
-9
lines changed

docs/user-guide/third-party-addons/modsecurity.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,97 @@ The default `Serial` value in SecAuditLogType can impact performance.
1414
The OWASP ModSecurity Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity or compatible web application firewalls. The CRS aims to protect web applications from a wide range of attacks, including the OWASP Top Ten, with a minimum of false alerts.
1515
The directory `/etc/nginx/owasp-modsecurity-crs` contains the [OWASP ModSecurity Core Rule Set repository](https://github.com/coreruleset/coreruleset).
1616
Using `enable-owasp-modsecurity-crs: "true"` we enable the use of the rules.
17+
18+
## Supported annotations
19+
20+
For more info on supported annotations, please see [annotations/#modsecurity](https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#modsecurity)
21+
22+
## Example of using ModSecurity with plugins via the helm chart
23+
24+
Suppose you have a ConfigMap that contains the contents of the [nextcloud-rule-exclusions plugin](https://github.com/coreruleset/nextcloud-rule-exclusions-plugin/blob/main/plugins/nextcloud-rule-exclusions-before.conf) like this:
25+
26+
```yaml
27+
apiVersion: v1
28+
kind: ConfigMap
29+
metadata:
30+
name: modsecurity-plugins
31+
data:
32+
empty-after.conf: |
33+
# no data
34+
empty-before.conf: |
35+
# no data
36+
empty-config.conf: |
37+
# no data
38+
nextcloud-rule-exclusions-before.conf:
39+
# this is just a snippet
40+
# find the full file at https://github.com/coreruleset/nextcloud-rule-exclusions-plugin
41+
#
42+
# [ File Manager ]
43+
# The web interface uploads files, and interacts with the user.
44+
SecRule REQUEST_FILENAME "@contains /remote.php/webdav" \
45+
"id:9508102,\
46+
phase:1,\
47+
pass,\
48+
t:none,\
49+
nolog,\
50+
ver:'nextcloud-rule-exclusions-plugin/1.2.0',\
51+
ctl:ruleRemoveById=920420,\
52+
ctl:ruleRemoveById=920440,\
53+
ctl:ruleRemoveById=941000-942999,\
54+
ctl:ruleRemoveById=951000-951999,\
55+
ctl:ruleRemoveById=953100-953130,\
56+
ctl:ruleRemoveByTag=attack-injection-php"
57+
```
58+
59+
If you're using the helm chart, you can pass in the following parameters in your `values.yaml`:
60+
61+
```yaml
62+
controller:
63+
config:
64+
# Enables Modsecurity
65+
enable-modsecurity: "true"
66+
67+
# Update ModSecurity config and rules
68+
modsecurity-snippet: |
69+
# this enables the mod security nextcloud plugin
70+
Include /etc/nginx/owasp-modsecurity-crs/plugins/nextcloud-rule-exclusions-before.conf
71+
72+
# this enables the default OWASP Core Rule Set
73+
Include /etc/nginx/owasp-modsecurity-crs/nginx-modsecurity.conf
74+
75+
# Enable prevention mode. Options: DetectionOnly,On,Off (default is DetectionOnly)
76+
SecRuleEngine On
77+
78+
# Enable scanning of the request body
79+
SecRequestBodyAccess On
80+
81+
# Enable XML and JSON parsing
82+
SecRule REQUEST_HEADERS:Content-Type "(?:text|application(?:/soap\+|/)|application/xml)/" \
83+
"id:200000,phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
84+
85+
SecRule REQUEST_HEADERS:Content-Type "application/json" \
86+
"id:200001,phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
87+
88+
# Reject if larger (we could also let it pass with ProcessPartial)
89+
SecRequestBodyLimitAction Reject
90+
91+
# Send ModSecurity audit logs to the stdout (only for rejected requests)
92+
SecAuditLog /dev/stdout
93+
94+
# format the logs in JSON
95+
SecAuditLogFormat JSON
96+
97+
# could be On/Off/RelevantOnly
98+
SecAuditEngine RelevantOnly
99+
100+
# Add a volume for the plugins directory
101+
extraVolumes:
102+
- name: plugins
103+
configMap:
104+
name: modsecurity-plugins
105+
106+
# override the /etc/nginx/enable-owasp-modsecurity-crs/plugins with your ConfigMap
107+
extraVolumeMounts:
108+
- name: plugins
109+
mountPath: /etc/nginx/owasp-modsecurity-crs/plugins
110+
```

images/nginx-1.25/rootfs/build.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export MODSECURITY_VERSION=v1.0.3
4141
# Check for recent changes: https://github.com/SpiderLabs/ModSecurity/compare/v3.0.8...v3/master
4242
export MODSECURITY_LIB_VERSION=v3.0.12
4343

44-
# Check for recent changes: https://github.com/coreruleset/coreruleset/compare/v3.3.5...main
45-
export OWASP_MODSECURITY_CRS_VERSION=v3.3.5
44+
# Check for recent changes: https://github.com/coreruleset/coreruleset/compare/v3.3.5...v4.0/main
45+
export OWASP_MODSECURITY_CRS_VERSION=v4.4.0
4646

4747
# Check for recent changes: https://github.com/openresty/lua-nginx-module/compare/b5d1688ae722538ba4dc8a7ec08820a08abfb93d...master
4848
export LUA_NGX_VERSION=b5d1688ae722538ba4dc8a7ec08820a08abfb93d
@@ -181,7 +181,7 @@ apk add \
181181
c-ares-dev \
182182
re2-dev \
183183
grpc-dev \
184-
protobuf-dev
184+
protobuf-dev
185185

186186
# apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing opentelemetry-cpp-dev
187187

@@ -388,17 +388,13 @@ mv rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example rules/REQUEST-900-E
388388
mv rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
389389
cd ..
390390

391-
# OWASP CRS v3 rules
391+
# OWASP CRS v4 rules
392392
echo "
393393
Include /etc/nginx/owasp-modsecurity-crs/crs-setup.conf
394394
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
395395
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-901-INITIALIZATION.conf
396-
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-903.9001-DRUPAL-EXCLUSION-RULES.conf
397-
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-903.9002-WORDPRESS-EXCLUSION-RULES.conf
398396
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-905-COMMON-EXCEPTIONS.conf
399-
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-910-IP-REPUTATION.conf
400397
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-911-METHOD-ENFORCEMENT.conf
401-
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-912-DOS-PROTECTION.conf
402398
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-913-SCANNER-DETECTION.conf
403399
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf
404400
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-921-PROTOCOL-ATTACK.conf
@@ -407,7 +403,7 @@ Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-930-APPLICATION-ATTACK-LF
407403
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-931-APPLICATION-ATTACK-RFI.conf
408404
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-932-APPLICATION-ATTACK-RCE.conf
409405
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-933-APPLICATION-ATTACK-PHP.conf
410-
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-934-APPLICATION-ATTACK-NODEJS.conf
406+
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-934-APPLICATION-ATTACK-GENERIC.conf
411407
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-941-APPLICATION-ATTACK-XSS.conf
412408
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf
413409
Include /etc/nginx/owasp-modsecurity-crs/rules/REQUEST-943-APPLICATION-ATTACK-SESSION-FIXATION.conf
@@ -418,6 +414,7 @@ Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-951-DATA-LEAKAGES-SQL.co
418414
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-952-DATA-LEAKAGES-JAVA.conf
419415
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-953-DATA-LEAKAGES-PHP.conf
420416
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-954-DATA-LEAKAGES-IIS.conf
417+
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-955-WEB-SHELLS.conf
421418
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-959-BLOCKING-EVALUATION.conf
422419
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf
423420
Include /etc/nginx/owasp-modsecurity-crs/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf

0 commit comments

Comments
 (0)