Skip to content

Commit c611c74

Browse files
committed
fix: Sanitize all http request fields to avoid XSS injection in templates
Related to CVE-2025-27088
1 parent 01f0c92 commit c611c74

22 files changed

+910
-223
lines changed

.golangci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ issues:
433433
- tagliatelle
434434
- lll
435435
path: pkg/.*/config/config\.go
436+
- linters:
437+
- dupl
438+
path: pkg/.*/response-handler/handler\.go
436439
# issues:
437440
# # List of regexps of issue texts to exclude, empty list by default.
438441
# # But independently from this option we use default exclude patterns,

.mise.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ gotestsum = "v1.12.0"
99
"go:go.uber.org/mock/mockgen" = "v0.5.0"
1010
# renovate: datasource=go depName=golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment
1111
# "go:golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment" = "v0.30.0"
12+
# renovate: datasource=github-tags depName=jmattheis/goverter
13+
"go:github.com/jmattheis/goverter/cmd/goverter" = "v1.7.0"

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ HAS_CURL:=$(shell command -v curl;)
3333
HAS_MOCKGEN:=$(shell command -v mockgen;)
3434
HAS_GOTESTSUM:=$(shell command -v gotestsum;)
3535
HAS_FIELDALIGNMENT:=$(shell command -v fieldalignment;)
36+
HAS_GOVERTER := $(shell command -v goverter;)
3637

3738
#
3839
## Tool versions
@@ -200,6 +201,10 @@ endif
200201
ifndef HAS_FIELDALIGNMENT
201202
@echo "=> Installing fieldalignment tool"
202203
$(GO) install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/[email protected]
204+
endif
205+
ifndef HAS_GOVERTER
206+
@echo "=> Installing goverter tool"
207+
$(GO) install github.com/jmattheis/goverter/cmd/[email protected]
203208
endif
204209
go mod download all
205210
go mod tidy

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/go-resty/resty/v2 v2.16.5
1818
github.com/gobwas/glob v0.2.3
1919
github.com/johannesboyne/gofakes3 v0.0.0-20240701191259-edd0227ffc37
20+
github.com/microcosm-cc/bluemonday v1.0.27
2021
github.com/opentracing/opentracing-go v1.2.0
2122
github.com/prometheus/client_golang v1.20.5
2223
github.com/sirupsen/logrus v1.9.3
@@ -38,6 +39,7 @@ require (
3839
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
3940
github.com/Masterminds/goutils v1.1.1 // indirect
4041
github.com/Masterminds/semver/v3 v3.3.1 // indirect
42+
github.com/aymerick/douceur v0.2.0 // indirect
4143
github.com/beorn7/perks v1.0.1 // indirect
4244
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4345
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -46,6 +48,7 @@ require (
4648
github.com/go-playground/locales v0.14.1 // indirect
4749
github.com/go-playground/universal-translator v0.18.1 // indirect
4850
github.com/google/uuid v1.6.0 // indirect
51+
github.com/gorilla/css v1.0.1 // indirect
4952
github.com/hashicorp/hcl v1.0.0 // indirect
5053
github.com/huandu/xstrings v1.5.0 // indirect
5154
github.com/inconshreveable/mousetrap v1.1.0 // indirect

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3
1717
github.com/aws/aws-sdk-go v1.44.256/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
1818
github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk=
1919
github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
20+
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
21+
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
2022
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
2123
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
2224
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -70,6 +72,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
7072
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
7173
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
7274
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
75+
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
76+
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
7377
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
7478
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
7579
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
@@ -97,6 +101,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
97101
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
98102
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
99103
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
104+
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
105+
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
100106
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
101107
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
102108
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=

pkg/s3-proxy/bucket/bucket-req-impl.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/config"
1515
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/log"
1616
responsehandler "github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/response-handler"
17+
responsehandlermodels "github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/response-handler/models"
1718
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/s3client"
1819
utils "github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/utils/generalutils"
1920
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/utils/templateutils"
@@ -310,7 +311,7 @@ func (bri *bucketReqImpl) manageGetFolder(ctx context.Context, key string, input
310311
// Answer directly
311312
resHan.FoldersFilesList(
312313
bri.LoadFileContent,
313-
make([]*responsehandler.Entry, 0),
314+
make([]*responsehandlermodels.Entry, 0),
314315
)
315316

316317
// Stop
@@ -604,7 +605,7 @@ func (bri *bucketReqImpl) Put(ctx context.Context, inp *PutInput) {
604605
// Answer
605606
resHan.Put(
606607
bri.LoadFileContent,
607-
&responsehandler.PutInput{
608+
&responsehandlermodels.PutInput{
608609
Key: key,
609610
ContentType: inp.ContentType,
610611
ContentSize: inp.ContentSize,
@@ -692,7 +693,7 @@ func (bri *bucketReqImpl) Delete(ctx context.Context, requestPath string) {
692693
// Answer
693694
resHan.Delete(
694695
bri.LoadFileContent,
695-
&responsehandler.DeleteInput{
696+
&responsehandlermodels.DeleteInput{
696697
Key: key,
697698
},
698699
)
@@ -702,9 +703,9 @@ func transformS3Entries(
702703
s3Entries []*s3client.ListElementOutput,
703704
rctx *bucketReqImpl,
704705
bucketRootPrefixKey string,
705-
) []*responsehandler.Entry {
706+
) []*responsehandlermodels.Entry {
706707
// Prepare result
707-
entries := make([]*responsehandler.Entry, 0)
708+
entries := make([]*responsehandlermodels.Entry, 0)
708709
// Loop over s3 entries
709710
for _, item := range s3Entries {
710711
// Store path
@@ -715,7 +716,7 @@ func transformS3Entries(
715716
ePath += "/"
716717
}
717718
// Save new entry
718-
entries = append(entries, &responsehandler.Entry{
719+
entries = append(entries, &responsehandlermodels.Entry{
719720
Type: item.Type,
720721
ETag: item.ETag,
721722
Name: item.Name,
@@ -807,7 +808,7 @@ func (bri *bucketReqImpl) answerHead(
807808
)
808809

809810
// Transform input
810-
inp := &responsehandler.StreamInput{
811+
inp := &responsehandlermodels.StreamInput{
811812
CacheControl: hOutput.CacheControl,
812813
Expires: hOutput.Expires,
813814
ContentDisposition: hOutput.ContentDisposition,
@@ -848,7 +849,7 @@ func (bri *bucketReqImpl) streamFileForResponse(ctx context.Context, key string,
848849
defer objOutput.Body.Close()
849850

850851
// Transform input
851-
inp := &responsehandler.StreamInput{
852+
inp := &responsehandlermodels.StreamInput{
852853
Body: objOutput.Body,
853854
CacheControl: objOutput.CacheControl,
854855
Expires: objOutput.Expires,

0 commit comments

Comments
 (0)