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

MaxAge doesn't allow 0 but has code to handle 0 case #11

Closed
jamesgroat opened this issue Sep 16, 2015 · 1 comment
Closed

MaxAge doesn't allow 0 but has code to handle 0 case #11

jamesgroat opened this issue Sep 16, 2015 · 1 comment

Comments

@jamesgroat
Copy link
Contributor

The handling of MaxAge is confusing with respect to 0 or negative ages.

In csrf.go:

if cs.opts.MaxAge < 1 {
     // Default of 12 hours
cs.opts.MaxAge = defaultAge
}

In store.go:

// Set the Expires field on the cookie based on the MaxAge
if cs.maxAge > 0 {
    cookie.Expires = time.Now().Add(
        time.Duration(cs.maxAge) * time.Second)
} else {
    cookie.Expires = time.Unix(1, 0)
}

Perhaps we just remove the if condition in store.go?

@elithrar
Copy link
Contributor

The reason for the second case is to allow expiring cookies. During store initialization we don't want to allow a MaxAge < 1 (which would not be useful), but when saving the store being able to set the MaxAge to -1 (which forces a cookie expiry in normal browser clients) is useful.

The functionality to expire cookies isn't included now but was something I was considering to allow for refreshing the CSRF token.

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

No branches or pull requests

2 participants