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

Redisplay login page in case of CSRF error #29462

Closed
PVince81 opened this issue Nov 6, 2017 · 10 comments
Closed

Redisplay login page in case of CSRF error #29462

PVince81 opened this issue Nov 6, 2017 · 10 comments
Assignees
Milestone

Comments

@PVince81
Copy link
Contributor

PVince81 commented Nov 6, 2017

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

@cdamken
Copy link
Contributor

cdamken commented Nov 23, 2017

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.

@pmaier1
Copy link
Contributor

pmaier1 commented Nov 23, 2017

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

@pmaier1 pmaier1 added p2-high Escalation, on top of current planning, release blocker p3-medium Normal priority and removed p2-high Escalation, on top of current planning, release blocker labels Nov 23, 2017
@cdamken
Copy link
Contributor

cdamken commented Nov 23, 2017

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

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

@pmaier1
Copy link
Contributor

pmaier1 commented Nov 28, 2017

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"

@cdamken
Copy link
Contributor

cdamken commented Nov 29, 2017

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

@PVince81 PVince81 modified the milestones: triage, development Nov 30, 2017
@PVince81
Copy link
Contributor Author

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...

@VicDeo
Copy link
Member

VicDeo commented Dec 21, 2017

@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.

@PVince81
Copy link
Contributor Author

I like your PHP approach better than JS hackery.

@VicDeo
Copy link
Member

VicDeo commented Jan 9, 2018

Done for 10.0.5

@lock
Copy link

lock bot commented Jul 31, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants