Skip to content

Commit ea4514e

Browse files
committed
Address brakeman warnings.
1 parent f75b9bf commit ea4514e

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

config/brakeman.ignore

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,58 @@
1818
},
1919
"user_input": "value_column",
2020
"confidence": "Medium",
21+
"cwe_id": [
22+
89
23+
],
2124
"note": ""
25+
},
26+
{
27+
"warning_type": "Weak Cryptography",
28+
"warning_code": 126,
29+
"fingerprint": "824aa359c33e8b9c417a2e439e75839c4ef84ca2b5aa759d2c1f4f20175266f5",
30+
"check_name": "WeakRSAKey",
31+
"message": "Use of padding mode PKCS1 (default if not specified), which is known to be insecure. Use OAEP instead",
32+
"file": "lib/sensitive_recoverable_data.rb",
33+
"line": 49,
34+
"link": "https://brakemanscanner.org/docs/warning_types/weak_cryptography/",
35+
"code": "OpenSSL::PKey::RSA.new(public_key_data).public_encrypt((OpenSSL::Cipher.new(\"aes-256-cbc\").random_key or Digest::SHA1.hexdigest(temporary_password)[0, OpenSSL::Cipher.new(\"aes-256-cbc\").key_len]))",
36+
"render_path": null,
37+
"location": {
38+
"type": "method",
39+
"class": "SensitiveRecoverableData",
40+
"method": "s(:self).encrypt_sensitive_data"
41+
},
42+
"user_input": null,
43+
"confidence": "High",
44+
"cwe_id": [
45+
780
46+
],
47+
"note": "Timing attacks in our scenario are impossible. We would ideally move to OAEP instead, but accept the risk in this limited context."
48+
},
49+
{
50+
"warning_type": "Weak Cryptography",
51+
"warning_code": 126,
52+
"fingerprint": "c7d0e19b03e814ca34b7b53fe5b33b89351a087a3104fed643424337bfbd382b",
53+
"check_name": "WeakRSAKey",
54+
"message": "Use of padding mode PKCS1 (default if not specified), which is known to be insecure. Use OAEP instead",
55+
"file": "lib/sensitive_recoverable_data.rb",
56+
"line": 21,
57+
"link": "https://brakemanscanner.org/docs/warning_types/weak_cryptography/",
58+
"code": "OpenSSL::PKey::RSA.new(private_key_data, password).private_decrypt(rawdata[(0..511)])",
59+
"render_path": null,
60+
"location": {
61+
"type": "method",
62+
"class": "SensitiveRecoverableData",
63+
"method": "s(:self).decrypt_sensitive_data"
64+
},
65+
"user_input": null,
66+
"confidence": "High",
67+
"cwe_id": [
68+
780
69+
],
70+
"note": "Timing attacks in our scenario are impossible. We would ideally move to OAEP instead, but accept the risk in this limited context."
2271
}
2372
],
24-
"updated": "2020-04-15 15:09:55 +0100",
25-
"brakeman_version": "4.8.1"
73+
"updated": "2024-11-05 15:15:35 +0000",
74+
"brakeman_version": "6.2.2"
2675
}

lib/sensitive_recoverable_data.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def self.decrypt_sensitive_data(password, temporary_password, rawdata, private_k
1515
cipher.decrypt
1616
if temporary_password.nil? || temporary_password.eql?('ADMIN')
1717
private_key = OpenSSL::PKey::RSA.new(private_key_data, password)
18+
# TODO: we should ideally re-encrypt all our data, and switch to OAEP padding instead
19+
# Brakeman warning: "Use of padding mode PKCS1 (default if not specified), which is known to be insecure. Use OAEP instead"
1820
# cipher.key = private_key.private_decrypt(rawdata[0..255])
1921
cipher.key = private_key.private_decrypt(rawdata[0..511])
2022
else
@@ -42,6 +44,8 @@ def self.encrypt_sensitive_data(secret_data, temporary_password, public_key_data
4244
rawdata = cipher.update(secret_data)
4345
rawdata << cipher.final
4446
public_key = OpenSSL::PKey::RSA.new(public_key_data)
47+
# TODO: we should ideally re-encrypt all our data, and switch to OAEP padding instead
48+
# Brakeman warning: "Use of padding mode PKCS1 (default if not specified), which is known to be insecure. Use OAEP instead"
4549
public_key.public_encrypt(random_key) + random_iv + rawdata
4650
end
4751
end

0 commit comments

Comments
 (0)