Skip to content

Commit 143b691

Browse files
authored
Merge pull request #30966 from nextcloud/backport/30235/stable22
[stable22] Add primary key for ratelimit table
2 parents b7f192f + c818ac6 commit 143b691

File tree

7 files changed

+144
-24
lines changed

7 files changed

+144
-24
lines changed

core/Migrations/Version23000Date20210906132259.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,36 @@
1111
use OCP\Migration\SimpleMigrationStep;
1212

1313
class Version23000Date20210906132259 extends SimpleMigrationStep {
14-
private const TABLE_NAME = 'ratelimit_entries';
15-
1614
/**
1715
* @param IOutput $output
1816
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
1917
* @param array $options
2018
* @return null|ISchemaWrapper
2119
*/
2220
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
23-
/** @var ISchemaWrapper $schema */
24-
$schema = $schemaClosure();
25-
26-
$hasTable = $schema->hasTable(self::TABLE_NAME);
27-
28-
if (!$hasTable) {
29-
$table = $schema->createTable(self::TABLE_NAME);
30-
$table->addColumn('hash', Types::STRING, [
31-
'notnull' => true,
32-
'length' => 128,
33-
]);
34-
$table->addColumn('delete_after', Types::DATETIME, [
35-
'notnull' => true,
36-
]);
37-
$table->addIndex(['hash'], 'ratelimit_hash');
38-
$table->addIndex(['delete_after'], 'ratelimit_delete_after');
39-
return $schema;
40-
}
21+
/**
22+
* Table was missing a primary key
23+
* Therefore it was dropped with Version24000Date20211213081506
24+
* and then recreated with a primary key in Version24000Date20211213081604
25+
*/
26+
// /** @var ISchemaWrapper $schema */
27+
// $schema = $schemaClosure();
28+
//
29+
// $hasTable = $schema->hasTable(self::TABLE_NAME);
30+
//
31+
// if (!$hasTable) {
32+
// $table = $schema->createTable(self::TABLE_NAME);
33+
// $table->addColumn('hash', Types::STRING, [
34+
// 'notnull' => true,
35+
// 'length' => 128,
36+
// ]);
37+
// $table->addColumn('delete_after', Types::DATETIME, [
38+
// 'notnull' => true,
39+
// ]);
40+
// $table->addIndex(['hash'], 'ratelimit_hash');
41+
// $table->addIndex(['delete_after'], 'ratelimit_delete_after');
42+
// return $schema;
43+
// }
4144

4245
return null;
4346
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OC\Core\Migrations;
25+
26+
use Closure;
27+
use OCP\DB\ISchemaWrapper;
28+
use OCP\Migration\IOutput;
29+
use OCP\Migration\SimpleMigrationStep;
30+
31+
class Version24000Date20211213081506 extends SimpleMigrationStep {
32+
/**
33+
* @param IOutput $output
34+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
35+
* @param array $options
36+
* @return null|ISchemaWrapper
37+
*/
38+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
39+
/** @var ISchemaWrapper $schema */
40+
$schema = $schemaClosure();
41+
42+
$hasTable = $schema->hasTable('ratelimit_entries');
43+
if ($hasTable) {
44+
$schema->dropTable('ratelimit_entries');
45+
return $schema;
46+
}
47+
48+
return null;
49+
}
50+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OC\Core\Migrations;
25+
26+
use Closure;
27+
use OCP\DB\ISchemaWrapper;
28+
use OCP\DB\Types;
29+
use OCP\Migration\IOutput;
30+
use OCP\Migration\SimpleMigrationStep;
31+
32+
class Version24000Date20211213081604 extends SimpleMigrationStep {
33+
/**
34+
* @param IOutput $output
35+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
36+
* @param array $options
37+
* @return null|ISchemaWrapper
38+
*/
39+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
40+
/** @var ISchemaWrapper $schema */
41+
$schema = $schemaClosure();
42+
43+
$hasTable = $schema->hasTable('ratelimit_entries');
44+
45+
if (!$hasTable) {
46+
$table = $schema->createTable('ratelimit_entries');
47+
$table->addColumn('id', Types::BIGINT, [
48+
'autoincrement' => true,
49+
'notnull' => true,
50+
]);
51+
$table->addColumn('hash', Types::STRING, [
52+
'notnull' => true,
53+
'length' => 128,
54+
]);
55+
$table->addColumn('delete_after', Types::DATETIME, [
56+
'notnull' => true,
57+
]);
58+
$table->setPrimaryKey(['id']);
59+
$table->addIndex(['hash'], 'ratelimit_hash');
60+
$table->addIndex(['delete_after'], 'ratelimit_delete_after');
61+
return $schema;
62+
}
63+
64+
return null;
65+
}
66+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,8 @@
971971
'OC\\Core\\Migrations\\Version21000Date20210309185127' => $baseDir . '/core/Migrations/Version21000Date20210309185127.php',
972972
'OC\\Core\\Migrations\\Version22000Date20210216080825' => $baseDir . '/core/Migrations/Version22000Date20210216080825.php',
973973
'OC\\Core\\Migrations\\Version23000Date20210906132259' => $baseDir . '/core/Migrations/Version23000Date20210906132259.php',
974+
'OC\\Core\\Migrations\\Version24000Date20211213081506' => $baseDir . '/core/Migrations/Version24000Date20211213081506.php',
975+
'OC\\Core\\Migrations\\Version24000Date20211213081604' => $baseDir . '/core/Migrations/Version24000Date20211213081604.php',
974976
'OC\\Core\\Migrations\\Version24000Date20211230140012' => $baseDir . '/core/Migrations/Version24000Date20211230140012.php',
975977
'OC\\Core\\Migrations\\Version24000Date20220131153041' => $baseDir . '/core/Migrations/Version24000Date20220131153041.php',
976978
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
10001000
'OC\\Core\\Migrations\\Version21000Date20210309185127' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185127.php',
10011001
'OC\\Core\\Migrations\\Version22000Date20210216080825' => __DIR__ . '/../../..' . '/core/Migrations/Version22000Date20210216080825.php',
10021002
'OC\\Core\\Migrations\\Version23000Date20210906132259' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20210906132259.php',
1003+
'OC\\Core\\Migrations\\Version24000Date20211213081506' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211213081506.php',
1004+
'OC\\Core\\Migrations\\Version24000Date20211213081604' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211213081604.php',
10031005
'OC\\Core\\Migrations\\Version24000Date20211230140012' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211230140012.php',
10041006
'OC\\Core\\Migrations\\Version24000Date20220131153041' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20220131153041.php',
10051007
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',

lib/private/Security/RateLimiting/Backend/DatabaseBackend.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ private function getExistingAttemptCount(
8282
->from(self::TABLE_NAME)
8383
->where(
8484
$qb->expr()->eq('hash', $qb->createNamedParameter($identifier, IQueryBuilder::PARAM_STR))
85-
)
86-
->andWhere(
87-
$qb->expr()->gte('delete_after', $qb->createNamedParameter($currentTime, IQueryBuilder::PARAM_DATE))
8885
);
8986

9087
$cursor = $qb->executeQuery();

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
3131
// when updating major/minor version number.
3232

33-
$OC_Version = [22, 2, 5, 1];
33+
$OC_Version = [22, 2, 5, 2];
3434

3535
// The human readable string
3636
$OC_VersionString = '22.2.5';

0 commit comments

Comments
 (0)