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

[5.2] Allow XSRF (CSRF) cookie lifetime to be set from configuration #14080

Merged
merged 1 commit into from Jun 21, 2016
Merged

[5.2] Allow XSRF (CSRF) cookie lifetime to be set from configuration #14080

merged 1 commit into from Jun 21, 2016

Conversation

ghost
Copy link

@ghost ghost commented Jun 20, 2016

Currently you are unable to set the lifetime of the xsrf cookie. It is currently hard coded at 120 minutes here

This change will allow it to pull the value from the session configuration. Since the default value for 'lifetime' in the session config is also 120, this should be backwards compatible.

@ghost ghost changed the title Allow XSRF (CSRF) cookie lifetime to be set from configuration [5.2] Allow XSRF (CSRF) cookie lifetime to be set from configuration Jun 20, 2016
@vlakoff
Copy link
Contributor

vlakoff commented Jun 20, 2016

Unlike the session duration, we just need the CSRF token to be valid across two requests.

@vlakoff
Copy link
Contributor

vlakoff commented Jun 20, 2016

On a related note, refs #6518.

@ghost
Copy link
Author

ghost commented Jun 20, 2016

That is true. However, the issue I was running into was if the difference in time between those two requests is larger than 120 minutes, a token mismatch exception will be thrown on the next request. There is no way to control that margin since it hard coded in.

@vlakoff
Copy link
Contributor

vlakoff commented Jun 20, 2016

You could extend the VerifyCsrfToken middleware and reimplement the addCookieToResponse method.

Maybe better, the cookie duration could be moved to a class property or method, so you would just have to redefine this, instead of the whole addCookieToResponse method.

@ghost
Copy link
Author

ghost commented Jun 20, 2016

Extending the middleware is exactly how I solved it for myself, but I figured someone could run into this problem in the future, hence the pr.

I considered implementing the property way that you suggest, but it seemed a simpler fix to just use the configuration since it was already there. I can adjust the pr to utilize a property instead if its ultimately decided that this is worth doing.

@taylorotwell taylorotwell merged commit 002de78 into laravel:5.2 Jun 21, 2016
@ghost ghost deleted the xsrf-cookie-expiration-config branch June 21, 2016 17:07
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