Skip to content

Commit 6d50fd2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into HEAD
2 parents 3e5f848 + 5aa7f65 commit 6d50fd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1290
-919
lines changed

.github/workflows/ci.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ on:
1313

1414
env:
1515
GO_VERSION: '1.20'
16-
TINYGO_VERSION: 0.30.0
16+
TINYGO_VERSION: 0.31.2
1717
# Run e2e tests against latest two releases and latest dev
1818
ENVOY_IMAGES: >
19+
envoyproxy/envoy:v1.30-latest
1920
envoyproxy/envoy:v1.29-latest
20-
envoyproxy/envoy:v1.28-latest
2121
envoyproxy/envoy-dev:latest
22-
istio/proxyv2:1.21.0
23-
istio/proxyv2:1.20.4
22+
istio/proxyv2:1.22.1
23+
istio/proxyv2:1.21.3
2424
2525
jobs:
2626
build:
@@ -30,6 +30,7 @@ jobs:
3030
contents: write
3131
packages: write
3232
strategy:
33+
fail-fast: false # ftw runs are flaky, let's keep the two jobs running reducing re-runs
3334
matrix:
3435
multiphase_eval: ["true","false"]
3536
env:

.github/workflows/nightly-coraza-check.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
GO_VERSION: '1.20'
12-
TINYGO_VERSION: 0.30.0
12+
TINYGO_VERSION: 0.31.2
1313

1414
jobs:
1515
test:

ftw/Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Copyright 2022 The OWASP Coraza contributors
22
# SPDX-License-Identifier: Apache-2.0
33

4+
# Stick with go-ftw:0.6.4 until CRS tests new format is merged (https://github.com/coreruleset/coreruleset/pull/3369)
45
FROM ghcr.io/coreruleset/go-ftw:0.6.4
56

67
RUN apk update && apk add curl
78

89
WORKDIR /workspace
910

10-
# TODO update when new CRS version is tagged: https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0-rc2.tar.gz
11-
ADD https://github.com/coreruleset/coreruleset/tarball/1d95422bb31983a5290720b7fb662ce3dd51f753 /workspace/coreruleset/
12-
RUN cd coreruleset && tar -xf 1d95422bb31983a5290720b7fb662ce3dd51f753 --strip-components 1
11+
# Keep this CRS version aligned with the one embedded in wasmplugin/rules
12+
ADD https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.3.0.tar.gz /workspace/coreruleset/
13+
RUN cd coreruleset && tar -xf v4.3.0.tar.gz --strip-components 1
1314

1415
COPY ftw.yml /workspace/ftw.yml
1516
COPY tests.sh /workspace/tests.sh

ftw/ftw.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ testoverride:
1212
'920100-10': 'Invalid HTTP method. Rejected by Envoy with Error 400'
1313
'920100-14': 'Invalid HTTP method. Rejected by Envoy with Error 400'
1414
'920100-16': 'Invalid HTTP request line. Rejected by Envoy with Error 400'
15+
'920181-1': 'Content-Length with Transfer-Encoding chunked is rejected by Envoy with Error 400'
1516
'920210-2': 'Connection header is stripped out by Envoy'
1617
'920210-3': 'Connection header is stripped out by Envoy'
1718
'920210-4': 'Connection header is stripped out by Envoy'
@@ -35,18 +36,18 @@ testoverride:
3536
'941101-1': 'Referer header is sanitized by Envoy and removed from the request'
3637
'941110-4': 'Referer header is sanitized by Envoy and removed from the request'
3738
'949110-4': 'Related to 920100. Invalid HTTP method. Rejected by Envoy with Error 400'
38-
'920181-1': 'Content-Length with Transfer-Encoding chunked is rejected by Envoy with Error 400'
39-
'932260-28': 'test bug, fixed upstream https://github.com/coreruleset/coreruleset/pull/3580'
39+
40+
# coraza-proxy-wasm not compatible tests
41+
'920280-1': 'Rule 920280 matches missing Host. coraza-proxy-wasm crafts it from :authority'
42+
'920280-3': 'Rule 920280 matches missing Host. coraza-proxy-wasm crafts it from :authority'
43+
'920290-1': 'Rule 920290 matches empty Host. coraza-proxy-wasm crafts it from :authority'
4044

4145
# Rules working, tests excluded for different expected output
4246
'920270-4': 'Log contains 920270. Test has log_contains disabled.'
4347

4448
# Coraza related issues
4549
'920171-2': 'Rule 920171 not detected. GET/HEAD with body. Coraza side'
4650
'920171-3': 'Rule 920171 not detected. GET/HEAD with body. Coraza side'
47-
'920280-1': 'Rule 920280 not detected. Host not present. Coraza side'
48-
'920280-3': 'Rule 920280 not detected. Host not present. Coraza side'
49-
'920290-1': 'Rule 920290 not detected. Empty Host. Coraza side'
5051
'920430-3': 'Rule 920430 not detected. Proto version. Coraza side'
5152
'920430-8': 'Rule 920430 not detected. Proto version. Coraza side'
5253
'920430-9': 'Rule 920430 not detected. Proto version. Coraza side'
@@ -56,5 +57,4 @@ testoverride:
5657
'934120-26': 'Rule 934120 partially detected. With HTTP/1.1 Envoy return 400. With HTTP/2 Enclosed alphanumerics not detected. Coraza Side'
5758
'934120-39': 'Rule 934120 partially detected. With HTTP/1.1 Envoy return 400. With HTTP/2 Enclosed alphanumerics not detected. Coraza Side'
5859
'932200-13': 'Unfortunate match inside logs against a different rule log. wip'
59-
'942440-19': 'Coraza side: Seems like ARGS is not splitted in _GET and _POST in ruleRemoveTargetById. Further investigation needed.'
60-
'942440-20': 'Coraza side: Seems like ARGS is not splitted in _GET and _POST in ruleRemoveTargetById. Further investigation needed.'
60+
'930110-7': 'Coraza/CRS side: See https://github.com/corazawaf/coraza/pull/1081'

go.mod

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@ module github.com/corazawaf/coraza-proxy-wasm
33
go 1.20
44

55
require (
6-
github.com/corazawaf/coraza-wasilibs v0.1.0
7-
github.com/corazawaf/coraza/v3 v3.1.0
8-
github.com/stretchr/testify v1.8.4
6+
github.com/corazawaf/coraza-wasilibs v0.2.0
7+
github.com/corazawaf/coraza/v3 v3.2.2-0.20240718151026-8ebb4a82ce41
8+
github.com/stretchr/testify v1.9.0
99
github.com/tetratelabs/proxy-wasm-go-sdk v0.23.0
1010
github.com/tidwall/gjson v1.17.1
1111
github.com/wasilibs/nottinygc v0.7.1
1212
)
1313

1414
require (
15-
github.com/corazawaf/libinjection-go v0.1.3 // indirect
15+
github.com/corazawaf/libinjection-go v0.2.1 // indirect
1616
github.com/davecgh/go-spew v1.1.1 // indirect
1717
github.com/kr/pretty v0.1.0 // indirect
18-
github.com/magefile/mage v1.15.0 // indirect
19-
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e // indirect
18+
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a // indirect
19+
github.com/petar-dambovaliev/aho-corasick v0.0.0-20240411101913-e07a1f0e8eb4 // indirect
2020
github.com/pmezard/go-difflib v1.0.0 // indirect
21-
github.com/tetratelabs/wazero v1.6.0 // indirect
21+
github.com/tetratelabs/wazero v1.7.2 // indirect
2222
github.com/tidwall/match v1.1.1 // indirect
2323
github.com/tidwall/pretty v1.2.1 // indirect
24-
github.com/wasilibs/go-aho-corasick v0.5.0 // indirect
25-
github.com/wasilibs/go-libinjection v0.4.0 // indirect
26-
github.com/wasilibs/go-re2 v1.4.0 // indirect
27-
golang.org/x/net v0.21.0 // indirect
28-
golang.org/x/sync v0.6.0 // indirect
24+
github.com/wasilibs/go-aho-corasick v0.6.0 // indirect
25+
github.com/wasilibs/go-libinjection v0.5.0 // indirect
26+
github.com/wasilibs/go-re2 v1.6.0 // indirect
27+
golang.org/x/net v0.26.0 // indirect
28+
golang.org/x/sync v0.7.0 // indirect
29+
golang.org/x/sys v0.21.0 // indirect
2930
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
3031
gopkg.in/yaml.v3 v3.0.1 // indirect
3132
rsc.io/binaryregexp v0.2.0 // indirect

go.sum

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
github.com/corazawaf/coraza-wasilibs v0.1.0 h1:cYsblr346P5cA49g6YQwhS1ygUQg5egwAywwsAbsUIo=
2-
github.com/corazawaf/coraza-wasilibs v0.1.0/go.mod h1:aMVO6E4TFAxXnPmyrrEoXVYeMDovq3IsKwuetAR38JE=
3-
github.com/corazawaf/coraza/v3 v3.1.0 h1:CB6YxNXdbZjUJS/0FVFoFvS8eOVFbIvlNuHNC5dh88c=
4-
github.com/corazawaf/coraza/v3 v3.1.0/go.mod h1:S0bhYQfTu1Ew3YKdI37X1WWu6t4En4Tvw28aKyQFJaU=
5-
github.com/corazawaf/libinjection-go v0.1.3 h1:PUplAYho1BBl0tIVbhDsNRuVGIeUYSiCEc9oQpb2rJU=
6-
github.com/corazawaf/libinjection-go v0.1.3/go.mod h1:OP4TM7xdJ2skyXqNX1AN1wN5nNZEmJNuWbNPOItn7aw=
1+
github.com/corazawaf/coraza-wasilibs v0.2.0 h1:BT8x2pks6Xk7Oi1cUS9BPO+hi3QWQyQAtBkC3IR3Mt8=
2+
github.com/corazawaf/coraza-wasilibs v0.2.0/go.mod h1:jmUPQdndtPfMzKPn0a8BqdikXjuT3wY+6zDx5NvKshI=
3+
github.com/corazawaf/coraza/v3 v3.2.2-0.20240718151026-8ebb4a82ce41 h1:BVk6PUP8RsYtSAGlpGH3w0Bnjyjd2nADCy7ZkjXC0MQ=
4+
github.com/corazawaf/coraza/v3 v3.2.2-0.20240718151026-8ebb4a82ce41/go.mod h1:fVndCGdUHJWl9c26VZPcORQRzUYwMPnRkC6TyTkhbUg=
5+
github.com/corazawaf/libinjection-go v0.2.1 h1:vNJ7L6c4xkhRgYU6sIO0Tl54TmeCQv/yfxBma30Dy/Y=
6+
github.com/corazawaf/libinjection-go v0.2.1/go.mod h1:OP4TM7xdJ2skyXqNX1AN1wN5nNZEmJNuWbNPOItn7aw=
77
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99
github.com/foxcpp/go-mockdns v1.1.0 h1:jI0rD8M0wuYAxL7r/ynTrCQQq0BVqfB99Vgk7DlmewI=
@@ -12,41 +12,42 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
1212
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1313
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1414
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
15-
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
16-
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
15+
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho=
16+
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
1717
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
18-
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e h1:POJco99aNgosh92lGqmx7L1ei+kCymivB/419SD15PQ=
19-
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e/go.mod h1:EHPiTAKtiFmrMldLUNswFwfZ2eJIYBHktdaUTZxYWRw=
18+
github.com/petar-dambovaliev/aho-corasick v0.0.0-20240411101913-e07a1f0e8eb4 h1:1Kw2vDBXmjop+LclnzCb/fFy+sgb3gYARwfmoUcQe6o=
19+
github.com/petar-dambovaliev/aho-corasick v0.0.0-20240411101913-e07a1f0e8eb4/go.mod h1:EHPiTAKtiFmrMldLUNswFwfZ2eJIYBHktdaUTZxYWRw=
2020
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2121
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
22-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
23-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
22+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
23+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2424
github.com/tetratelabs/proxy-wasm-go-sdk v0.23.0 h1:e0dm/ypyd1xudIrg8VTsd8dawuYaSy2gqewH5zD4rU8=
2525
github.com/tetratelabs/proxy-wasm-go-sdk v0.23.0/go.mod h1:YqR8JZaY3Ev9ihXgjzAQAMkXEzPKKmy4Q5rsVWt4XGk=
26-
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
27-
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
26+
github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc=
27+
github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
2828
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
2929
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
3030
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
3131
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
3232
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
3333
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
3434
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
35-
github.com/wasilibs/go-aho-corasick v0.5.0 h1:Y8G8eJ7usuC14sd93IxxnZH43K5Bz5C90a6LsAYGjmY=
36-
github.com/wasilibs/go-aho-corasick v0.5.0/go.mod h1:1XPgz4lvFZA+Ytd8vfeCoqnwy4CSe0MxnLfRQJVqpJM=
37-
github.com/wasilibs/go-libinjection v0.4.0 h1:dr1Y/kM/gmoA7eSfdf+CvCcmzwsz2jVYjNdakgladDU=
38-
github.com/wasilibs/go-libinjection v0.4.0/go.mod h1:zD7fNXKSaTKoSTmrfuP9Gc16alNEgwkZaHIeDDk3WWM=
39-
github.com/wasilibs/go-re2 v1.4.0 h1:Jp6BM8G/zajgY1BCQUm3i7oGMdR1gA5EBv87wGd2ysc=
40-
github.com/wasilibs/go-re2 v1.4.0/go.mod h1:hLzlKjEgON+17hWjikLx8hJBkikyjQH/lsqCy9t6tIY=
35+
github.com/wasilibs/go-aho-corasick v0.6.0 h1:/usYKOljcc+264yq7jzq1tsgyuS1F/cUzLE75TJIgsQ=
36+
github.com/wasilibs/go-aho-corasick v0.6.0/go.mod h1:juBo/POXN3BapT9Bw93oxRQyyPha7AEu5SPUicPfLn4=
37+
github.com/wasilibs/go-libinjection v0.5.0 h1:ef+xIy0vLkZgvsyZevGDOFH3sq1aIrQI/8ImaCGDqDU=
38+
github.com/wasilibs/go-libinjection v0.5.0/go.mod h1:i1Va/vm/PFDYZS1JHUd3Ab2bNk7Qol3W70bEWz7I3b4=
39+
github.com/wasilibs/go-re2 v1.6.0 h1:CLlhDebt38wtl/zz4ww+hkXBMcxjrKFvTDXzFW2VOz8=
40+
github.com/wasilibs/go-re2 v1.6.0/go.mod h1:prArCyErsypRBI/jFAFJEbzyHzjABKqkzlidF0SNA04=
4141
github.com/wasilibs/nottinygc v0.7.1 h1:rKu19+SFniRNuSo5NX7/wxpSpXmMUmkcyt/YiWLJg8w=
4242
github.com/wasilibs/nottinygc v0.7.1/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo=
43-
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
44-
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
45-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
46-
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
47-
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
48-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
49-
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
43+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
44+
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
45+
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
46+
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
47+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
48+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
49+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
50+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
5051
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5152
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
5253
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/auditlog/serial_writer.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright The OWASP Coraza contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package auditlog
5+
6+
import (
7+
"io"
8+
9+
"github.com/corazawaf/coraza/v3/experimental/plugins"
10+
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes"
11+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
12+
)
13+
14+
// RegisterProxyWasmSerialWriter overrides the default "Serial" audit log writer (see https://github.com/corazawaf/coraza/blob/main/internal/auditlog/init_tinygo.go)
15+
// in order to print audit logs to the proxy-wasm log as info messages with a prefix to differentiate them from other logs.
16+
func RegisterProxyWasmSerialWriter() {
17+
plugins.RegisterAuditLogWriter("serial", func() plugintypes.AuditLogWriter {
18+
return &wasmSerial{}
19+
})
20+
}
21+
22+
type wasmSerial struct {
23+
io.Closer
24+
formatter plugintypes.AuditLogFormatter
25+
}
26+
27+
func (s *wasmSerial) Init(cfg plugintypes.AuditLogConfig) error {
28+
s.formatter = cfg.Formatter
29+
return nil
30+
}
31+
32+
func (s *wasmSerial) Write(al plugintypes.AuditLog) error {
33+
if s.formatter == nil {
34+
return nil
35+
}
36+
37+
bts, err := s.formatter.Format(al)
38+
if err != nil {
39+
return err
40+
}
41+
42+
if len(bts) == 0 {
43+
return nil
44+
}
45+
// Print the audit log to the proxy-wasm log as an info message adding an "AuditLog:" prefix.
46+
proxywasm.LogInfo("AuditLog:" + string(bts))
47+
return nil
48+
}
49+
50+
func (s *wasmSerial) Close() error { return nil }

magefiles/magefile.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
var minGoVersion = "1.20"
23-
var minTinygoVersion = "0.30"
23+
var minTinygoVersion = "0.31.2"
2424
var addLicenseVersion = "04bfe4ee9ca5764577b029acc6a1957fd1997153" // https://github.com/google/addlicense
2525
var golangCILintVer = "v1.54.2" // https://github.com/golangci/golangci-lint/releases
2626
var gosImportsVer = "v0.3.1" // https://github.com/rinchsan/gosimports/releases/tag/v0.3.1
@@ -216,6 +216,7 @@ func Build() error {
216216
}
217217
}
218218

219+
// TODO: from tinygo 0.32.0 -target=wasi is replaced by GOOS=wasip1. See https://github.com/tinygo-org/tinygo/pull/3861
219220
if err := sh.RunV("tinygo", "build", "-gc=custom", "-opt=2", "-o", filepath.Join("build", "mainraw.wasm"), "-scheduler=none", "-target=wasi", buildTagArg); err != nil {
220221
return err
221222
}

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ package main
66
import (
77
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
88

9+
"github.com/corazawaf/coraza-proxy-wasm/internal/auditlog"
910
"github.com/corazawaf/coraza-proxy-wasm/internal/operators"
1011
"github.com/corazawaf/coraza-proxy-wasm/wasmplugin"
1112
)
1213

1314
func main() {
1415
operators.Register()
16+
auditlog.RegisterProxyWasmSerialWriter()
1517
proxywasm.SetVMContext(wasmplugin.NewVMContext())
1618
}

0 commit comments

Comments
 (0)