Skip to content

Commit 611d914

Browse files
authored
Merge pull request #1091 from lestrrat-go/develop/v2
[v2] merge for v2.0.21
2 parents c3b3a17 + 551073b commit 611d914

File tree

12 files changed

+265
-48
lines changed

12 files changed

+265
-48
lines changed

Changes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Changes
44
v2 has many incompatibilities with v1. To see the full list of differences between
55
v1 and v2, please read the Changes-v2.md file (https://github.com/lestrrat-go/jwx/blob/develop/v2/Changes-v2.md)
66

7+
v2.0.21 07 Mar 2024
8+
[Security]
9+
* [jwe] Added `jwe.Settings(jwe.WithMaxDecompressBufferSize(int64))` to specify the
10+
maximum size of a decompressed JWE payload. The default value is 10MB. If you
11+
are compressing payloads greater than this and want to decompress it during
12+
a call to `jwe.Decrypt`, you need to explicitly set a value large enough to
13+
hold that data.
14+
15+
The same option can be passed to `jwe.Decrypt` to control this behavior on
16+
a per-message basis.
17+
* [jwe] Added documentation stating that `jwe.WithMaxBufferSize` option will be
18+
renamed in future versions, i.e. v3
19+
720
v2.0.20 20 Feb 2024
821
[New Features]
922
* [jwe] Added `jwe.Settings(WithMaxBufferSize(int64))` to set the maximum size of

deps.bzl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def go_dependencies():
4747
name = "com_github_lestrrat_go_httprc",
4848
build_file_proto_mode = "disable_global",
4949
importpath = "github.com/lestrrat-go/httprc",
50-
sum = "h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8=",
51-
version = "v1.0.4",
50+
sum = "h1:bsTfiH8xaKOJPrg1R+E3iE/AWZr/x0Phj9PBTG/OLUk=",
51+
version = "v1.0.5",
5252
)
5353
go_repository(
5454
name = "com_github_lestrrat_go_iter",
@@ -85,15 +85,15 @@ def go_dependencies():
8585
name = "com_github_stretchr_objx",
8686
build_file_proto_mode = "disable_global",
8787
importpath = "github.com/stretchr/objx",
88-
sum = "h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=",
89-
version = "v0.5.0",
88+
sum = "h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=",
89+
version = "v0.5.2",
9090
)
9191
go_repository(
9292
name = "com_github_stretchr_testify",
9393
build_file_proto_mode = "disable_global",
9494
importpath = "github.com/stretchr/testify",
95-
sum = "h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=",
96-
version = "v1.8.4",
95+
sum = "h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=",
96+
version = "v1.9.0",
9797
)
9898

9999
go_repository(
@@ -115,31 +115,31 @@ def go_dependencies():
115115
name = "org_golang_x_crypto",
116116
build_file_proto_mode = "disable_global",
117117
importpath = "golang.org/x/crypto",
118-
sum = "h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=",
119-
version = "v0.19.0",
118+
sum = "h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=",
119+
version = "v0.21.0",
120120
)
121121

122122
go_repository(
123123
name = "org_golang_x_net",
124124
build_file_proto_mode = "disable_global",
125125
importpath = "golang.org/x/net",
126-
sum = "h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=",
127-
version = "v0.10.0",
126+
sum = "h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=",
127+
version = "v0.21.0",
128128
)
129129

130130
go_repository(
131131
name = "org_golang_x_sys",
132132
build_file_proto_mode = "disable_global",
133133
importpath = "golang.org/x/sys",
134-
sum = "h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=",
135-
version = "v0.17.0",
134+
sum = "h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=",
135+
version = "v0.18.0",
136136
)
137137
go_repository(
138138
name = "org_golang_x_term",
139139
build_file_proto_mode = "disable_global",
140140
importpath = "golang.org/x/term",
141-
sum = "h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=",
142-
version = "v0.17.0",
141+
sum = "h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=",
142+
version = "v0.18.0",
143143
)
144144

145145
go_repository(

examples/go.sum

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N
1313
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
1414
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
1515
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
16-
github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8=
17-
github.com/lestrrat-go/httprc v1.0.4/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
16+
github.com/lestrrat-go/httprc v1.0.5 h1:bsTfiH8xaKOJPrg1R+E3iE/AWZr/x0Phj9PBTG/OLUk=
17+
github.com/lestrrat-go/httprc v1.0.5/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
1818
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
1919
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
2020
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
@@ -27,24 +27,28 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr
2727
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2828
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
2929
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
30+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
3031
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3132
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3233
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
33-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
3434
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
35+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
36+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3537
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
3638
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3739
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
3840
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
39-
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
4041
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
42+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
43+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
4144
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
4245
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
4346
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
4447
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
4548
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
4649
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
4750
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
51+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
4852
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4953
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5054
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -57,14 +61,16 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
5761
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5862
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5963
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
60-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
6164
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
65+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
66+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6267
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
6368
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
6469
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
6570
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
6671
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
6772
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
73+
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
6874
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6975
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
7076
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ require (
66
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
77
github.com/goccy/go-json v0.10.2
88
github.com/lestrrat-go/blackmagic v1.0.2
9-
github.com/lestrrat-go/httprc v1.0.4
9+
github.com/lestrrat-go/httprc v1.0.5
1010
github.com/lestrrat-go/iter v1.0.2
1111
github.com/lestrrat-go/option v1.0.1
1212
github.com/segmentio/asm v1.2.0
13-
github.com/stretchr/testify v1.8.4
14-
golang.org/x/crypto v0.19.0
13+
github.com/stretchr/testify v1.9.0
14+
golang.org/x/crypto v0.21.0
1515
)
1616

1717
require (
1818
github.com/davecgh/go-spew v1.1.1 // indirect
1919
github.com/lestrrat-go/httpcc v1.0.1 // indirect
2020
github.com/pmezard/go-difflib v1.0.0 // indirect
21-
golang.org/x/sys v0.17.0 // indirect
21+
golang.org/x/sys v0.18.0 // indirect
2222
gopkg.in/yaml.v3 v3.0.1 // indirect
2323
)

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N
99
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
1010
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
1111
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
12-
github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8=
13-
github.com/lestrrat-go/httprc v1.0.4/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
12+
github.com/lestrrat-go/httprc v1.0.5 h1:bsTfiH8xaKOJPrg1R+E3iE/AWZr/x0Phj9PBTG/OLUk=
13+
github.com/lestrrat-go/httprc v1.0.5/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
1414
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
1515
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
1616
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
@@ -22,12 +22,12 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr
2222
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2323
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2424
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
25-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
26-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
27-
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
28-
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
29-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
30-
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
25+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
26+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
27+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
28+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
29+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
30+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3131
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3232
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3333
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

jwe/compress.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,35 @@ import (
99
"github.com/lestrrat-go/jwx/v2/internal/pool"
1010
)
1111

12-
func uncompress(plaintext []byte) ([]byte, error) {
13-
return io.ReadAll(flate.NewReader(bytes.NewReader(plaintext)))
12+
func uncompress(src []byte, maxBufferSize int64) ([]byte, error) {
13+
var dst bytes.Buffer
14+
r := flate.NewReader(bytes.NewReader(src))
15+
defer r.Close()
16+
var buf [16384]byte
17+
var sofar int64
18+
for {
19+
n, readErr := r.Read(buf[:])
20+
sofar += int64(n)
21+
if sofar > maxBufferSize {
22+
return nil, fmt.Errorf(`compressed payload exceeds maximum allowed size`)
23+
}
24+
if readErr != nil {
25+
// if we have a read error, and it's not EOF, then we need to stop
26+
if readErr != io.EOF {
27+
return nil, fmt.Errorf(`failed to read inflated data: %w`, readErr)
28+
}
29+
}
30+
31+
if _, err := dst.Write(buf[:n]); err != nil {
32+
return nil, fmt.Errorf(`failed to write inflated data: %w`, err)
33+
}
34+
35+
if readErr != nil {
36+
// if it got here, then readErr == io.EOF, we're done
37+
//nolint:nilerr
38+
return dst.Bytes(), nil
39+
}
40+
}
1441
}
1542

1643
func compress(plaintext []byte) ([]byte, error) {

jwe/jwe.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
var muSettings sync.RWMutex
3030
var maxPBES2Count = 10000
31+
var maxDecompressBufferSize int64 = 10 * 1024 * 1024 // 10MB
3132

3233
func Settings(options ...GlobalOption) {
3334
muSettings.Lock()
@@ -37,6 +38,8 @@ func Settings(options ...GlobalOption) {
3738
switch option.Ident() {
3839
case identMaxPBES2Count{}:
3940
maxPBES2Count = option.Value().(int)
41+
case identMaxDecompressBufferSize{}:
42+
maxDecompressBufferSize = option.Value().(int64)
4043
case identMaxBufferSize{}:
4144
aescbc.SetMaxBufferSize(option.Value().(int64))
4245
}
@@ -463,28 +466,50 @@ func encrypt(payload, cek []byte, options ...EncryptOption) ([]byte, error) {
463466
}
464467

465468
type decryptCtx struct {
466-
msg *Message
467-
aad []byte
468-
cek *[]byte
469-
computedAad []byte
470-
keyProviders []KeyProvider
471-
protectedHeaders Headers
469+
msg *Message
470+
aad []byte
471+
cek *[]byte
472+
computedAad []byte
473+
keyProviders []KeyProvider
474+
protectedHeaders Headers
475+
maxDecompressBufferSize int64
472476
}
473477

474-
// Decrypt takes the key encryption algorithm and the corresponding
475-
// key to decrypt the JWE message, and returns the decrypted payload.
478+
// Decrypt takes encrypted payload, and information required to decrypt the
479+
// payload (e.g. the key encryption algorithm and the corresponding
480+
// key to decrypt the JWE message) in its optional arguments. See
481+
// the examples and list of options that return a DecryptOption for possible
482+
// values. Upon successful decryptiond returns the decrypted payload.
483+
//
476484
// The JWE message can be either compact or full JSON format.
477485
//
478-
// `alg` accepts a `jwa.KeyAlgorithm` for convenience so you can directly pass
479-
// the result of `(jwk.Key).Algorithm()`, but in practice it must be of type
486+
// When using `jwe.WithKeyEncryptionAlgorithm()`, you can pass a `jwa.KeyAlgorithm`
487+
// for convenience: this is mainly to allow you to directly pass the result of `(jwk.Key).Algorithm()`.
488+
// However, do note that while `(jwk.Key).Algorithm()` could very well contain key encryption
489+
// algorithms, it could also contain other types of values, such as _signature algorithms_.
490+
// In order for `jwe.Decrypt` to work properly, the `alg` parameter must be of type
480491
// `jwa.KeyEncryptionAlgorithm` or otherwise it will cause an error.
481492
//
482-
// `key` must be a private key. It can be either in its raw format (e.g. *rsa.PrivateKey) or a jwk.Key
493+
// When using `jwe.WithKey()`, the value must be a private key.
494+
// It can be either in its raw format (e.g. *rsa.PrivateKey) or a jwk.Key
495+
//
496+
// When the encrypted message is also compressed, the decompressed payload must be
497+
// smaller than the size specified by the `jwe.WithMaxDecompressBufferSize` setting,
498+
// which defaults to 10MB. If the decompressed payload is larger than this size,
499+
// an error is returned.
500+
//
501+
// You can opt to change the MaxDecompressBufferSize setting globally, or on a
502+
// per-call basis by passing the `jwe.WithMaxDecompressBufferSize` option to
503+
// either `jwe.Settings()` or `jwe.Decrypt()`:
504+
//
505+
// jwe.Settings(jwe.WithMaxDecompressBufferSize(10*1024*1024)) // changes value globally
506+
// jwe.Decrypt(..., jwe.WithMaxDecompressBufferSize(250*1024)) // changes just for this call
483507
func Decrypt(buf []byte, options ...DecryptOption) ([]byte, error) {
484508
var keyProviders []KeyProvider
485509
var keyUsed interface{}
486510
var cek *[]byte
487511
var dst *Message
512+
perCallMaxDecompressBufferSize := maxDecompressBufferSize
488513
//nolint:forcetypeassert
489514
for _, option := range options {
490515
switch option.Ident() {
@@ -506,6 +531,8 @@ func Decrypt(buf []byte, options ...DecryptOption) ([]byte, error) {
506531
})
507532
case identCEK{}:
508533
cek = option.Value().(*[]byte)
534+
case identMaxDecompressBufferSize{}:
535+
perCallMaxDecompressBufferSize = option.Value().(int64)
509536
}
510537
}
511538

@@ -565,6 +592,7 @@ func Decrypt(buf []byte, options ...DecryptOption) ([]byte, error) {
565592
dctx.keyProviders = keyProviders
566593
dctx.protectedHeaders = h
567594
dctx.cek = cek
595+
dctx.maxDecompressBufferSize = perCallMaxDecompressBufferSize
568596

569597
var lastError error
570598
for _, recipient := range recipients {
@@ -741,7 +769,7 @@ func (dctx *decryptCtx) decryptContent(ctx context.Context, alg jwa.KeyEncryptio
741769
}
742770

743771
if h2.Compression() == jwa.Deflate {
744-
buf, err := uncompress(plaintext)
772+
buf, err := uncompress(plaintext, dctx.maxDecompressBufferSize)
745773
if err != nil {
746774
return nil, fmt.Errorf(`jwe.Derypt: failed to uncompress payload: %w`, err)
747775
}

0 commit comments

Comments
 (0)