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

Automatically cut the token name on the first level #31688

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/Controller/AppPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ public function getAppPassword(): DataResponse {
}

$userAgent = $this->request->getHeader('USER_AGENT');
if (mb_strlen($userAgent) > 128) {
$userAgent = mb_substr($userAgent, 0, 120) . '…';
}

$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);

Expand Down
4 changes: 0 additions & 4 deletions core/Controller/ClientFlowLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ public function generateAppPassword($stateToken,
$clientName = $client->getName();
}

if (mb_strlen($clientName) > 128) {
$clientName = mb_substr($clientName, 0, 120) . '…';
}

$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
$uid = $this->userSession->getUser()->getUID();
$generatedToken = $this->tokenProvider->generateToken(
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Authentication/Token/IProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IProvider {
* @param string $uid
* @param string $loginName
* @param string|null $password
* @param string $name
* @param string $name Name will be trimmed to 120 chars when longer
* @param int $type token type
* @param int $remember whether the session token should be used for remember-me
* @return IToken
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Authentication/Token/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(PublicKeyTokenProvider $publicKeyTokenProvider) {
* @param string $uid
* @param string $loginName
* @param string|null $password
* @param string $name
* @param string $name Name will be trimmed to 120 chars when longer
* @param int $type token type
* @param int $remember whether the session token should be used for remember-me
* @return IToken
Expand All @@ -62,7 +62,7 @@ public function generateToken(string $token,
int $type = IToken::TEMPORARY_TOKEN,
int $remember = IToken::DO_NOT_REMEMBER): IToken {
if (mb_strlen($name) > 128) {
throw new InvalidTokenException('The given name is too long');
$name = mb_substr($name, 0, 120) . '…';
}

try {
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/Authentication/Token/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ public function testGenerateConflictingToken() {
$this->assertSame($token, $actual);
}

public function testGenerateTokenTooLongName() {
$token = $this->createMock(IToken::class);
$token->method('getName')
->willReturn(str_repeat('a', 120) . '…');


$this->publicKeyTokenProvider->expects($this->once())
->method('generateToken')
->with(
'token',
'uid',
'loginName',
'password',
str_repeat('a', 120) . '…',
IToken::TEMPORARY_TOKEN,
IToken::REMEMBER
)->willReturn($token);

$actual = $this->manager->generateToken(
'token',
'uid',
'loginName',
'password',
str_repeat('a', 200),
IToken::TEMPORARY_TOKEN,
IToken::REMEMBER
);

$this->assertSame(121, mb_strlen($actual->getName()));
}

public function tokenData(): array {
return [
[new PublicKeyToken()],
Expand Down