Skip to content

Rememberable race condition causing users to be incorrectly logged out #376

@JonRCahill

Description

@JonRCahill

I believe I have found a race condition in the rememberable feature.

I have a pretty straightforward page which has links to 36 images on it. These images are not links to static images but are instead routed through the Phoenix itself (where I look up the image and return it). So my links look something like:

/for/123/image
/for/124/image

The routes for these links are piped through the browser pipeline, set up with the Coherence.Authentication.Session as specified in the docs so everything is being authenticated through Coherence.

When I log into my system for the first time everything is fine, selecting the remember me checkbox. When I close the browser and open the site again I appear to be logged in (the menus show logged in) but I am in fact logged out and if I refresh the page it shows I am logged out (menus show logged out).

It appears that the page request is working correctly and keeping me logged in. However, when processing one of the 36 image requests it is logging me out, I can see in the logs I get an "Invalid token. Potential Fraud." warning.

I believe what is happening is when requesting the images Coherence is validating the series_hash and token_hash to ensure it is valid, then updates these before returning the request. If a second image request starts before the first image request completes then it won't have the updated series_hash and token_hash and when validating it will fail, logging the user out as fraudulent.

I have worked around this for the moment by making another pipeline which doesn't include Coherence.Authentication.Session and piping my images only through this pipeline.

I believe you would also be able to have this same problem is someone refreshed multiple windows/tabs in their browser at the same time as well.

I think there are a couple of issues at the heart of the problem, the first being that the validating of series_hash/token_hash and updating them is not an atomic action. Second being the series_hash/token_hash is being changed when there could be another request being processed which will now have the incorrect keys.

At the moment I don't know where to get started on resolving this issue as I don't know enough detail on how the rememberable feature is implemented.

When I get a chance, I will try and put together an example repo which replicates this issue.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions