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

Renewing sessions #22

Open
watercraft opened this issue Dec 12, 2016 · 4 comments
Open

Renewing sessions #22

watercraft opened this issue Dec 12, 2016 · 4 comments

Comments

@watercraft
Copy link

It is typical for a session token to be renewed on every API call.
What strategy would we use to do this with the sessionauth package?
It looks to me like the SessionUser() function that is inserted into the flow could do this whenever a user is successfully matched by calling Save() on the martini-contrib session.
Any thoughts?

@watercraft
Copy link
Author

The mechanism I came up with for renewing sessions is to call AuthenticateSession() from my LoginRequired() function; i.e. no change needed to martini-contrib.
However, in my testing I noticed that the first call to IsAuthenticated() after a session has expired on the server is succeeding; exposing a security hole.
To address this I expose the IsNew value from gorilla/sessions as a function on martini-contrib/sessions.
Let me know if you want this change.

func SessionUser(newUser func() User) martini.Handler {
        return func(s sessions.Session, c martini.Context, l *log.Logger) {
                userId := s.Get(SessionKey)
                user := newUser()

                if userId != nil {
                        err := user.GetById(userId)
                        if err != nil {
                                l.Printf("Login Error: %v\n", err)
                        } else if !s.IsNew() {
                                user.Login()
                        }
...

@rday
Copy link
Member

rday commented Dec 30, 2016

It's been too long since I've looked at this to be a good judge. But if it's a security concern then we should certainly merge it. Could you send in a PR?

Thanks!!

@watercraft
Copy link
Author

Note, the change in sessionauth requires the change in sessions.
The security concern is that after the session expires exactly one API call is authenticated.
When calls are coming all the time this is not an issues; session expires and calls begin to fail soon after.
However, if the user leave a window open and goes to lunch some other person can come and make a single change without authenticating.

@watercraft
Copy link
Author

Unfortunately the automated checks are failing for something unrelated to my changes.
I don't have the environment to reproduce and debug these failures.
The code compiles just fine for me both before and after my changes.

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