Skip to content

Redisplay login page in case of CSRF error #29462

Closed

Description

@PVince81

A CSRF token can expire if one leaves the login page open for several days.

The PHP session containing the old token would expire, so logging in there would cause a token mismatch.

Currently the page is a full page error with no easy way to go back.

We should change this and detect whenever the CSRF error is from the login page, then simply redisplay the login page with a more user friendly message like "You took too long to login, please try again now".

The "CSRF error" page can be kept for other kinds of errors.

cc @pmaier1 @settermjd

Activity

  1. added this to the triage milestone on Nov 6, 2017
  2. cdamken commented on Nov 23, 2017

    @cdamken
    Contributor

    We should change this and detect whenever the CSRF error is from the login page, then simply redisplay the login page with a more user friendly message like "You took too long to login, please try again now".

    We could also add when the csrf error appears where to manually redirect to the login webpage by clicking somewhere in the message.

  3. pmaier1 commented on Nov 23, 2017

    @pmaier1
    Contributor

    Yes, I also run into this issue all the time. We should improve this. I like @PVince81's approach to automatically redirect a lot. Why should it be one more click with a button? @cdamken

  4. added
    p2-high
    p3-medium
    and removed
    p2-high
    on Nov 23, 2017
  5. cdamken commented on Nov 23, 2017

    @cdamken
    Contributor

    Why should it be one more click with a button? @cdamken

    in case the redirect does not work, users could always force it.

  6. pmaier1 commented on Nov 28, 2017

    @pmaier1
    Contributor

    in case the redirect does not work, users could always force it.

    Ok good point. Other pages have a text saying: "Redirecting to login page in 5 sec. If it does not work, click here"

  7. cdamken commented on Nov 29, 2017

    @cdamken
    Contributor

    and now that we all agree... when would be that done?

  8. modified the milestones: triage, development on Nov 30, 2017
  9. PVince81 commented on Nov 30, 2017

    @PVince81
    ContributorAuthor

    Assigning to @VicDeo for 10.0.5. Let's hope it's not too complicated as it might require editing or hacking the base templates...

  10. VicDeo commented on Dec 21, 2017

    @VicDeo
    Contributor

    @PVince81
    There is no specific "CSRF error" page. This is just a generic 403 page with the respective message.
    It comes from the AppFramework.
    https://github.com/owncloud/core/blob/master/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php#L196

    Would it be enough to redisplay the login page with "You took too long to login, please try again now" at once without any kind of redirect as this is much simpler?

    if($exception instanceof NotLoggedInException) {
    	$url = $this->urlGenerator->linkToRoute(
    		'core.login.showLoginForm',
    		[
    			'redirect_url' => urlencode($this->request->server['REQUEST_URI']),
    		]
    	);
    	$response = new RedirectResponse($url);
    
    + // basically checking $exception/$controller/$methodName
    +} elseif (
    +		$methodName === 'tryLogin'
    +		&& $exception instanceof CrossSiteRequestForgeryException
    +		&& $controller instanceof LoginController
    +	) {
    +         // render a login template 
    +         ....
    +// the code below - 403 page that includes  CSRF in the current state
    } else {
    	$response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
    	$response->setStatus($exception->getCode());
    }
    

    Otherwise I need to write a JS code with redirect and pass it to the template using the same conditions as above, but it could be slightly more tricky.

  11. PVince81 commented on Dec 21, 2017

    @PVince81
    ContributorAuthor

    I like your PHP approach better than JS hackery.

  12. VicDeo commented on Jan 9, 2018

    @VicDeo
    Contributor

    Done for 10.0.5

  13. lock commented on Jul 31, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  14. locked as resolved and limited conversation to collaborators on Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions