Skip to content

Commit

Permalink
fix: Show error message when CSRF check fails at login
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Oct 17, 2023
1 parent 106bf6c commit 1fe02f9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/Controller/LoginController.php
Expand Up @@ -64,6 +64,7 @@
class LoginController extends Controller {
public const LOGIN_MSG_INVALIDPASSWORD = 'invalidpassword';
public const LOGIN_MSG_USERDISABLED = 'userdisabled';
public const LOGIN_MSG_CSRFCHECKFAILED = 'csrfCheckFailed';

public function __construct(
?string $appName,
Expand Down Expand Up @@ -291,7 +292,7 @@ public function tryLogin(Chain $loginChain,
$user,
$user,
$redirect_url,
$this->l10n->t('Please try again')
self::LOGIN_MSG_CSRFCHECKFAILED
);
}

Expand Down
8 changes: 8 additions & 0 deletions core/src/components/login/LoginForm.vue
Expand Up @@ -32,6 +32,11 @@
type="warning">
{{ t('core', 'Please contact your administrator.') }}
</NcNoteCard>
<NcNoteCard v-if="csrfCheckFailed"
:heading="t('core', 'Temporary error')"
type="error">
{{ t('core', 'Please try again.') }}
</NcNoteCard>
<NcNoteCard v-if="messages.length > 0">
<div v-for="(message, index) in messages"
:key="index">
Expand Down Expand Up @@ -184,6 +189,9 @@ export default {
apacheAuthFailed() {
return this.errors.indexOf('apacheAuthFailed') !== -1
},
csrfCheckFailed() {
return this.errors.indexOf('csrfCheckFailed') !== -1
},
internalException() {
return this.errors.indexOf('internalexception') !== -1
},
Expand Down
4 changes: 2 additions & 2 deletions dist/core-login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-login.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions lib/private/Authentication/Login/LoginResult.php
Expand Up @@ -25,6 +25,8 @@
*/
namespace OC\Authentication\Login;

use OC\Core\Controller\LoginController;

class LoginResult {
/** @var bool */
private $success;
Expand Down Expand Up @@ -59,6 +61,9 @@ public static function success(LoginData $data, ?string $redirectUrl = null) {
return $result;
}

/**
* @param LoginController::LOGIN_MSG_*|null $msg
*/
public static function failure(LoginData $data, string $msg = null): LoginResult {
$result = new static(false, $data);
if ($msg !== null) {
Expand Down

0 comments on commit 1fe02f9

Please sign in to comment.