Skip to content

Commit 5bc8329

Browse files
Merge pull request #45290 from nextcloud/backport/44218/stable27
[stable27] feat: Limit email input to 255 chars
2 parents 0f57633 + 572a3c7 commit 5bc8329

7 files changed

Lines changed: 65 additions & 4 deletions

File tree

core/Controller/LoginController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,20 @@ public function tryLogin(Chain $loginChain,
316316
);
317317
}
318318

319+
$user = trim($user);
320+
321+
if (strlen($user) > 255) {
322+
return $this->createLoginFailedResponse(
323+
$user,
324+
$user,
325+
$redirect_url,
326+
$this->l10n->t('Unsupported email length (>255)')
327+
);
328+
}
329+
319330
$data = new LoginData(
320331
$this->request,
321-
trim($user),
332+
$user,
322333
$password,
323334
$redirect_url,
324335
$timezone,

core/Controller/LostController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ public function email(string $user): JSONResponse {
202202

203203
$user = trim($user);
204204

205+
if (strlen($user) > 255) {
206+
return new JSONResponse($this->error($this->l10n->t('Unsupported email length (>255)')));
207+
}
208+
205209
\OCP\Util::emitHook(
206210
'\OCA\Files_Sharing\API\Server2Server',
207211
'preLoginNameUsedAsUserName',

core/src/components/login/LoginForm.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@
6363
:label="t('core', 'Account name or email')"
6464
:label-visible="true"
6565
name="user"
66+
:maxlength="255"
6667
:value.sync="user"
6768
:class="{shake: invalidPassword}"
6869
autocapitalize="none"
6970
:spellchecking="false"
7071
:autocomplete="autoCompleteAllowed ? 'username' : 'off'"
7172
required
73+
:error="userNameInputLengthIs255"
74+
:helper-text="userInputHelperText"
7275
data-login-form-input-user
7376
@change="updateUsername" />
7477

@@ -119,6 +122,8 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
119122
120123
import LoginButton from './LoginButton.vue'
121124
125+
import AuthMixin from '../../mixins/auth.js'
126+
122127
export default {
123128
name: 'LoginForm',
124129
@@ -128,6 +133,7 @@ export default {
128133
NcTextField,
129134
NcNoteCard,
130135
},
136+
mixins: [AuthMixin],
131137
132138
props: {
133139
username: {

core/src/components/login/ResetPassword.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<NcTextField id="user"
2626
:value.sync="user"
2727
name="user"
28+
:maxlength="255"
2829
autocapitalize="off"
2930
:label="t('core', 'Account name or email')"
3031
:label-visible="true"
@@ -61,13 +62,16 @@ import LoginButton from './LoginButton.vue'
6162
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
6263
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
6364
65+
import AuthMixin from '../../mixins/auth.js'
66+
6467
export default {
6568
name: 'ResetPassword',
6669
components: {
6770
LoginButton,
6871
NcNoteCard,
6972
NcTextField,
7073
},
74+
mixins: [AuthMixin],
7175
props: {
7276
username: {
7377
type: String,

core/src/mixins/auth.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @copyright Copyright (c) 2024 Fon E. Noel NFEBE <opensource@nfebe.com>
3+
*
4+
* @author Fon E. Noel NFEBE <opensource@nfebe.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
export default {
24+
25+
computed: {
26+
userNameInputLengthIs255() {
27+
return this.user.length >= 255
28+
},
29+
userInputHelperText() {
30+
if (this.userNameInputLengthIs255) {
31+
return t('core', 'Email length is at max (255)')
32+
}
33+
return undefined
34+
},
35+
},
36+
}

dist/core-login.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-login.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)