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

[6.x] Fix the value generated when setting encrypted cookies #857

Merged
merged 2 commits into from
Jan 26, 2021
Merged

[6.x] Fix the value generated when setting encrypted cookies #857

merged 2 commits into from
Jan 26, 2021

Conversation

code-distortion
Copy link
Contributor

This PR updates the Dusk Browser object so that it sets encrypted cookies to match the way laravel/framework does.

Without this, setting an encrypted cookie results in an invalid value that Laravel ignores:

$browser->addCookie($name, $value, $expiry = null, array $options = [], $encrypt = true);

For reference, this is where Laravel/Framework encrypts and decrypts cookies:
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Cookie/Middleware/EncryptCookies.php#L147
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Cookie/Middleware/EncryptCookies.php#L86


I'm not sure how to go about testing this within this package, as some of the functionality that's used to set cookies isn't available. (eg. the encrypt helper, Laravel's app object, etc).

I have tested this separately in a Laravel installation by using addCookie to set an encrypted cookie, and then make a request to a page that spits out the cookies that were decrypted by the EncryptsCookies middleware.

@code-distortion
Copy link
Contributor Author

laravel/framework includes the hashed cookie name as a prefix. When reading a cookie value, it ignores it if this prefix is missing.

But it didn't always. Older versions didn't use the prefix at all.

When Dusk reads a cookie's value, it doesn't care if the prefix was added or not. I imagine this is for compatibility reasons: https://github.com/laravel/dusk/blob/6.x/src/Concerns/InteractsWithCookies.php#L38

When Dusk sets a cookie, technically should choose to add the prefix depending on the version of Laravel being used.

Should care be taken here to selectively add the prefix, or is the Laravel change so old that it doesn't matter?

@driesvints driesvints changed the title Fix the value generated when setting encrypted cookies [6.x] Fix the value generated when setting encrypted cookies Jan 25, 2021
@driesvints
Copy link
Member

@code-distortion let's leave the prefix be for now.

@taylorotwell taylorotwell merged commit c4ddce9 into laravel:6.x Jan 26, 2021
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.

3 participants