Skip to content

Commit e8421d0

Browse files
authored
Merge pull request #13 from madebymode/v2
v2 | CRSv4.3.0 Support
2 parents f16701c + b958413 commit e8421d0

33 files changed

+1533
-2818
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212

13-
- name: Set up Go 1.17
13+
- name: Set up Go 1.22
1414
uses: actions/setup-go@v5
1515
with:
16-
go-version: ^1.17
16+
go-version: ^1.22
1717

1818
- name: Check out code into the Go module directory
1919
uses: actions/checkout@v4

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v5
2121
with:
22-
go-version: 1.19
22+
go-version: 1.22
2323

2424
- name: Build
2525
run: go build -v ./...

.traefik.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,12 @@ import: github.com/madebymode/traefik-modsecurity-plugin
66
summary: 'Traefik plugin to proxy requests through owasp/modsecurity-crs'
77

88
testData:
9-
ModsecurityUrl: http://waf:80
10-
MaxBodySize: 10485760
9+
ModsecurityUrl: http://waf:8080
1110
TimeoutMillis: 2000
12-
CacheConditionsMethods:
13-
- GET
14-
CacheConditionsNoBody: true
15-
CacheKeyIncludeMethod: true
16-
CacheKeyIncludeRequestURI: true
17-
CacheKeyIncludeHeaders: false
18-
CacheKeyHeaders:
19-
- User-Agent
20-
- Cache-Control
21-
CacheKeyMatchAllHeaders: false
22-
CacheKeyIncludeHost: true
23-
CacheKeyIncludeRemoteAddress: false
11+
JailEnabled: false
12+
JailTimeDurationSecs: 600
13+
BadRequestsThresholdCount: 25
14+
BadRequestsThresholdPeriodSecs: 600
2415

2516
iconPath: ./img/icon.png
2617
bannerPath: ./img/banner.png

README.md

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
this is a fork of the original: https://github.com/acouvreur/traefik-modsecurity-plugin
66

7-
This fork introduces alpine images, and a custom http.transport, and a caching layer once mod-security has processed a
8-
request
7+
This fork introduces alpine images, CRS 4.x suppport, a custom http.transport, and a 429 jail for repeat offenders
98

109
see: https://github.com/traefik/plugindemo#troubleshooting
1110

@@ -65,30 +64,10 @@ This plugin supports these configuration:
6564
* `modSecurityUrl`: (**mandatory**) it's the URL for the owasp/modsecurity container.
6665
* `timeoutMillis`: (optional) timeout in milliseconds for the http client to talk with modsecurity container. (default 2
6766
seconds)
68-
* `maxBodySize`: (optional) it's the maximum limit for requests body size. Requests exceeding this value will be
69-
rejected using `HTTP 413 Request Entity Too Large`.
70-
The default value for this parameter is 10MB. Zero means "use default value".
71-
72-
* `cacheConditionsMethods`: (optional) An array of HTTP methods for which caching is allowed. (default ["GET"])
73-
* `cacheConditionsNoBody`: (optional) Specifies if requests with no body (content-length of 0) should be cached. (
74-
default true)
75-
76-
* `cacheKeyIncludeHost`: (optional) Specifies if the host should be included in the cache key. (default true)
77-
* `cacheKeyIncludeRemoteAddress`: (optional) Speifics if the remote request address should be included in the cache
78-
key (default true)
79-
* `cacheKeyIncludeHeaders`: (optional) Specifies if the headers should be included in the cache key. (default true)
80-
* `cacheKeyHeaders`: (optional) An array of specific headers to be included in the cache key when CacheKeyIncludeHeaders is true. (ie: the default ["User-Agent"])
81-
82-
**Note**: some headers are ALWAYS blacklisted, and even if you list
83-
them here, they will still not be cached:
84-
```
85-
Authorization: *, Set-Cookie: *, Cache-Control: no-store, Pragma: no-cache, Expires: -1 (date in the past)
86-
```
87-
88-
**Note**: body of every (non-cached) request will be buffered in memory while the request is in-flight (i.e.: during the
89-
security
90-
check and during the request processing by traefik and the backend), so you may want to tune `maxBodySize` depending on
91-
how much RAM you have.
67+
* `jailEnabled`: (optional) 429 jail for repeat offenders (based on threshold settings)
68+
* `JailTimeDurationSecs`: (optional) how long a client will be jailed for, in seconds
69+
* `badRequestsThresholdCount`: (optional) # of 403s a clientIP can trigger from OWASP before being adding to jail
70+
* `badRequestsThresholdPeriodSecs` (optional) # the period, in seconds, that the threshold must meet before a client is added to the 429 jail
9271

9372
## Local development (docker-compose.local.yml)
9473

docker-compose.local.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ version: "3.7"
22

33
services:
44
traefik:
5-
image: traefik
5+
image: "traefik:v2.11.4"
66
ports:
77
- "80:80"
88
- "8080:8080"
99
command:
10+
- "--log.level=DEBUG"
1011
- "--accesslog=true"
1112
- --api.dashboard=true
1213
- --api.insecure=true
@@ -19,26 +20,30 @@ services:
1920
labels:
2021
- traefik.enable=true
2122
- traefik.http.services.traefik.loadbalancer.server.port=8080
22-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.modSecurityUrl=http://waf:80
23-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.maxBodySize=10485760
24-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheEnabled=true
25-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheConditionsMethods=["GET"]
26-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheConditionsNoBody=true
27-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeMethod=true
28-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeHost=true
29-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeRequestURI=true
30-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeHeaders=true
31-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyHeaders=["User-Agent]
32-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyMatchAllHeaders=false
23+
# use traefiks built-in maxRequestBodyBytes middleware - there's no need for us to bake this ourselves
24+
- traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=1048576
25+
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.modSecurityUrl=http://waf:8080
26+
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.jailEnabled=true
27+
3328

3429

3530
waf:
36-
image: owasp/modsecurity-crs:3.3.5-apache-alpine-202402140602
31+
image: owasp/modsecurity-crs:4.3.0-apache-alpine-202406090906
3732
environment:
3833
- PARANOIA=1
3934
- ANOMALY_INBOUND=10
4035
- ANOMALY_OUTBOUND=5
4136
- BACKEND=http://dummy
37+
# New in CRS 4
38+
- REPORTING_LEVEL=2
39+
40+
#######################################################
41+
# ModSecurity ENV Variables
42+
#######################################################
43+
44+
- MODSEC_AUDIT_LOG_FORMAT=JSON
45+
- MODSEC_RULE_ENGINE=On
46+
4247

4348
dummy:
4449
image: traefik/whoami

docker-compose.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ services:
1818
labels:
1919
- traefik.enable=true
2020
- traefik.http.services.traefik.loadbalancer.server.port=8080
21-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.modSecurityUrl=http://waf:80
22-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.maxBodySize=10485760
23-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheEnabled=true
24-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheConditionsMethods=["GET"]
25-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheConditionsNoBody=true
26-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeMethod=true
27-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeHost=true
28-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeRequestURI=true
29-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeHeaders=true
30-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyHeaders=["User-Agent]
31-
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.cacheKeyIncludeRemoteAddress=true
21+
# use traefiks built-in maxRequestBodyBytes middleware - there's no need for us to bake this ourselves
22+
- traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=1048576
23+
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.modSecurityUrl=http://waf:8080
24+
- traefik.http.middlewares.waf.plugin.traefik-modsecurity-plugin.jailEnabled=true
3225

3326
waf:
34-
image: owasp/modsecurity-crs:3.3.5-apache-alpine-202402140602
27+
image: owasp/modsecurity-crs:4.3.0-apache-alpine-202406090906
3528
environment:
3629
- PARANOIA=1
3730
- ANOMALY_INBOUND=10
3831
- ANOMALY_OUTBOUND=5
3932
- BACKEND=http://dummy
33+
# New in CRS 4
34+
- REPORTING_LEVEL=2
35+
36+
#######################################################
37+
# ModSecurity ENV Variables
38+
#######################################################
39+
40+
- MODSEC_AUDIT_LOG_FORMAT=JSON
41+
- MODSEC_RULE_ENGINE=On
4042

4143
dummy:
4244
image: traefik/whoami

go.mod

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
module github.com/madebymode/traefik-modsecurity-plugin
22

3-
go 1.17
3+
go 1.22
44

5-
require (
6-
github.com/patrickmn/go-cache v2.1.0+incompatible
7-
github.com/stretchr/testify v1.7.0
8-
)
5+
require github.com/stretchr/testify v1.9.0
96

107
require (
11-
github.com/davecgh/go-spew v1.1.0 // indirect
8+
github.com/davecgh/go-spew v1.1.1 // indirect
129
github.com/pmezard/go-difflib v1.0.0 // indirect
13-
gopkg.in/yaml.v3 v3.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
1411
)

go.sum

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
4-
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
53
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
64
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
9-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
107
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
118
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
14-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

modesecurity_cache.go

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)