File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,17 @@ class AesGcm extends Aes {
149
149
150
150
const decipher = crypto . createDecipheriv (
151
151
this . ALGO_AES_256_GCM , key , iv
152
- ) . setAuthTag ( tag ) . setAAD ( Buffer . from ( aad ) )
152
+ )
153
+
154
+ // Restrict valid GCM tag length, patches for Node < 11.0.0
155
+ // more @see https://github.com/nodejs/node/pull/20039
156
+ const tagLen = tag . length
157
+ if ( tagLen > 16 || ( tagLen < 12 && tagLen != 8 && tagLen != 4 ) ) {
158
+ let backport = new TypeError ( `Invalid authentication tag length: ${ tagLen } ` )
159
+ backport . code = 'ERR_CRYPTO_INVALID_AUTH_TAG'
160
+ throw backport
161
+ }
162
+ decipher . setAuthTag ( tag ) . setAAD ( Buffer . from ( aad ) )
153
163
154
164
return Buffer . concat ( [
155
165
decipher . update ( payload , this . hex ) ,
Original file line number Diff line number Diff line change @@ -226,8 +226,8 @@ describe('lib/aes', () => {
226
226
should ( ( ) => {
227
227
aes . decrypt ( mockupIv , mockupKey , '' )
228
228
} ) . throw ( Error , {
229
+ code : 'ERR_CRYPTO_INVALID_AUTH_TAG' ,
229
230
message : 'Invalid authentication tag length: 0' ,
230
- stack : / a t D e c i p h e r i v \. s e t A u t h T a g / ,
231
231
} )
232
232
} )
233
233
You can’t perform that action at this time.
0 commit comments