Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fixed errors occurring when encrypted cookies has been tampered with #45313

Merged
merged 3 commits into from
Dec 14, 2022
Merged

[9.x] Fixed errors occurring when encrypted cookies has been tampered with #45313

merged 3 commits into from
Dec 14, 2022

Conversation

vbezaras-leasingmarkt
Copy link
Contributor

Dear maintainers,

we have faced several errors, while receiving seemingly malicious requests with tampered cookie data.
ErrorException: hash_equals(): Expected user_string to be a string, array given
ErrorException: base64_decode() expects parameter 1 to be string, array given
ErrorException: Array to string conversion

After investigation, we came to a conclusion, that the validation of encrypted payload is insufficient, i.e. not checking if the value is scalar. In this PR I have extended the validation and added a test to cover the case.

As per requirement I send the PR to 9.x branch, but I would greatly appreciate it the fix would be backported to version 8.x. I can not estimate if this poses a significant security threat, yet I am concerned, that this behavior can be abused in some way.

@vbezaras-leasingmarkt vbezaras-leasingmarkt changed the title Fixed errors occurring when encrypted cookies has been tampered with [9.x] Fixed errors occurring when encrypted cookies has been tampered with Dec 14, 2022
@taylorotwell taylorotwell merged commit 28bd786 into laravel:9.x Dec 14, 2022
@vbezaras-leasingmarkt
Copy link
Contributor Author

Oh sorry, it went so fast :) I forgot to commit a little fix to the test:

diff --git a/tests/Encryption/EncrypterTest.php b/tests/Encryption/EncrypterTest.php
index c989a5d9f1..b31e8584a9 100755
--- a/tests/Encryption/EncrypterTest.php
+++ b/tests/Encryption/EncrypterTest.php
@@ -209,10 +209,9 @@ public function provideTamperedData()
     {
         return [
             [['iv' => ['value_in_array'], 'value' => '', 'mac' => '']],
-            [['iv' => '', 'value' => '', 'mac' => '']],
             [['iv' => '', 'value' => ['value_in_array'], 'mac' => '']],
             [['iv' => '', 'value' => '', 'mac' => ['value_in_array']]],
-            [['iv' => '', 'value' => '', 'mac' => ['value_in_array'], 'tag' => ['value_in_array']]],
+            [['iv' => '', 'value' => '', 'mac' => '', 'tag' => ['value_in_array']]],
         ];
     }

So that each of the 4 values would be tested separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants