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>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
ChristophWurst authored and nextcloud-command committed Dec 4, 2023
1 parent 90529e5 commit 32a02b0
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
class LoginController extends Controller {
public const LOGIN_MSG_INVALIDPASSWORD = 'invalidpassword';
public const LOGIN_MSG_USERDISABLED = 'userdisabled';
public const LOGIN_MSG_CSRFCHECKFAILED = 'csrfCheckFailed';

private IUserManager $userManager;
private IConfig $config;
Expand Down Expand Up @@ -311,7 +312,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
Original file line number Diff line number Diff line change
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 @@ -186,6 +191,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
Original file line number Diff line number Diff line change
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 32a02b0

Please sign in to comment.