There might be a potential security issue in ninja-core/src/main/java/ninja/utils/CookieEncryption.java (ninja-core 7.0.0 the latest version) that I want to report and check with you guys.
Security risk:
In the function encrypt(), when AES is specified as the cipher algorithm without any more settings, AES/ECB/PKCS5Padding is used by default
However, ECB as a block cipher mode is not secure, encrypting each block independently without any IV.
Patterns in the plaintext can be easily observed in the ciphertext if similar blocks are present, which is a significant security weakness
In Ninja case the weakness could lead to leakage of sensitive information in session data when encryption mode is used
Proof Of Concept:
I will use the unit test case under src/test/java/ninja/utils/CookieEncryptionTest.java here as an example
We got 16 'a's, 16 'b's, 16 'c's, and another 16 'b's in the end, which's 64 characters in total as a string to encrypt
As said before we'll see the pattern in the ciphertext as well.
Encrypt it and check the cipher text before Base64 encoding:
As we can see, same plaintext block generates identical 16 bytes cipher text block
Recommendation:
Could specify cipher mode explicitly and consider using more secure cipher modes. Only for example which might not apply to this case:
Hi team,
There might be a potential security issue in ninja-core/src/main/java/ninja/utils/CookieEncryption.java (ninja-core 7.0.0 the latest version) that I want to report and check with you guys.
Security risk:
In the function encrypt(), when AES is specified as the cipher algorithm without any more settings, AES/ECB/PKCS5Padding is used by default![image](https://github.com/ninjaframework/ninja/assets/57932150/3d5cf267-ea5b-435f-888b-22fc456dba22)
However, ECB as a block cipher mode is not secure, encrypting each block independently without any IV. Patterns in the plaintext can be easily observed in the ciphertext if similar blocks are present, which is a significant security weakness In Ninja case the weakness could lead to leakage of sensitive information in session data when encryption mode is used
Proof Of Concept:
I will use the unit test case under src/test/java/ninja/utils/CookieEncryptionTest.java here as an example We got 16 'a's, 16 'b's, 16 'c's, and another 16 'b's in the end, which's 64 characters in total as a string to encrypt![image](https://github.com/ninjaframework/ninja/assets/57932150/8b534d15-0986-4058-ae18-df0b00e3d216)
As said before we'll see the pattern in the ciphertext as well. Encrypt it and check the cipher text before Base64 encoding:![image](https://github.com/ninjaframework/ninja/assets/57932150/36405875-70e0-4bd3-b808-013cd98548ff)
As we can see, same plaintext block generates identical 16 bytes cipher text block
Recommendation:
Could specify cipher mode explicitly and consider using more secure cipher modes. Only for example which might not apply to this case:
That's pretty much the security issue I found.