Skip to content

Commit ad8c29d

Browse files
merge develop/v1 (#747)
* Bump github.com/goccy/go-json from 0.9.6 to 0.9.7 (#710) * Bump github.com/goccy/go-json from 0.9.6 to 0.9.7 Bumps [github.com/goccy/go-json](https://github.com/goccy/go-json) from 0.9.6 to 0.9.7. - [Release notes](https://github.com/goccy/go-json/releases) - [Changelog](https://github.com/goccy/go-json/blob/master/CHANGELOG.md) - [Commits](goccy/go-json@v0.9.6...v0.9.7) --- updated-dependencies: - dependency-name: github.com/goccy/go-json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * make tidy Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Daisuke Maki <lestrrat+github@gmail.com> * Update golang.org/x/crypto (#726) * Update Changes * [jwe/v1] Fix possible excessive unpadding for AESCBC (#746) * Fix possible excessive unpadding for AESCBC * Update Changes * Update Changes * Update Changes Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e38f677 commit ad8c29d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Changes

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changes
22
=======
33

4+
v1.2.25 23 May 2022
5+
[Bug Fixes][Security]
6+
* [jwe] An old bug from at least 7 years ago existed in handling AES-CBC unpadding,
7+
where the unpad operation might remove more bytes than necessary (#744)
8+
This affects all jwx code that is available before v2.0.2 and v1.2.25.
9+
410
v1.2.24 05 May 2022
511
[Security]
612
* Upgrade golang.org/x/crypto (#724)

jwe/internal/aescbc/aescbc.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,36 @@ func pad(buf []byte, n int) []byte {
3535
func unpad(buf []byte, n int) ([]byte, error) {
3636
lbuf := len(buf)
3737
rem := lbuf % n
38+
39+
// First, `buf` must be a multiple of `n`
3840
if rem != 0 {
3941
return nil, errors.Errorf("input buffer must be multiple of block size %d", n)
4042
}
4143

42-
count := 0
44+
// Find the last byte, which is the encoded padding
45+
// i.e. 0x1 == 1 byte worth of padding
4346
last := buf[lbuf-1]
44-
for i := lbuf - 1; i >= 0; i-- {
45-
if buf[i] != last {
46-
break
47-
}
48-
count++
47+
48+
// This is the number of padding bytes that we expect
49+
expected := int(last)
50+
51+
if expected == 0 || /* we _have_ to have padding here. therefore, 0x0 is not an option */
52+
expected > n || /* we also must make sure that we don't go over the block size (n) */
53+
expected > lbuf /* finally, it can't be more than the buffer itself. unlikely, but could happen */ {
54+
return nil, fmt.Errorf(`invalid padding byte at the end of buffer`)
4955
}
50-
if count != int(last) {
51-
return nil, errors.New("invalid padding")
56+
57+
// start i = 1 because we have already established that expected == int(last) where
58+
// last = buf[lbuf-1].
59+
//
60+
// we also don't check against lbuf-i in range, because we have established expected <= lbuf
61+
for i := 1; i < expected; i++ {
62+
if buf[lbuf-i] != last {
63+
return nil, errors.New(`invalid padding`)
64+
}
5265
}
5366

54-
return buf[:lbuf-int(last)], nil
67+
return buf[:lbuf-expected], nil
5568
}
5669

5770
type Hmac struct {

0 commit comments

Comments
 (0)