Skip to content

Commit 1e719d7

Browse files
anakinjSideni
andauthored
Merge commit from fork
* Security Fix: Added missing tag length validation * Spec for tag size checking --------- Co-authored-by: Sideni <[email protected]>
1 parent 9e828e2 commit 1e719d7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/jwe/enc/aes_gcm.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def setup_cipher(direction, auth_data)
3838
cipher.send(direction)
3939
cipher.key = cek
4040
cipher.iv = iv
41-
cipher.auth_tag = tag if direction == :decrypt
41+
if direction == :decrypt
42+
raise JWE::InvalidData, 'Invalid ciphertext or authentication tag' unless tag.bytesize == 16
43+
44+
cipher.auth_tag = tag
45+
end
4246
cipher.auth_data = auth_data
4347
end
4448

spec/jwe/enc_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@
130130
end
131131
end
132132

133+
context 'when the tag is not 16 bytes' do
134+
it 'raises an error' do
135+
enc = klass.new(key, group[:iv])
136+
enc.tag = group[:tag][0...-1]
137+
expect { enc.decrypt(group[:helloworld], '') }.to raise_error(JWE::InvalidData)
138+
end
139+
end
140+
133141
context 'when the ciphertext is not valid' do
134142
it 'raises an error' do
135143
enc = klass.new(key, group[:iv])

0 commit comments

Comments
 (0)