Skip to content

Commit 6344e9c

Browse files
authored
Merge pull request #108 from /issues/107-use-shorter-database-url-field
Change the JtiReplayDetector to use a hash rather than a full URL.
2 parents 7162a2c + a15400e commit 6344e9c

File tree

3 files changed

+62
-57
lines changed

3 files changed

+62
-57
lines changed

solid/lib/JtiReplayDetector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ public function __construct(private DateInterval $interval, private IDBConnectio
2222

2323
public function detect(string $jti, string $targetUri): bool
2424
{
25+
$hash = sha1($targetUri);
26+
2527
// @TODO: $this->rotateBuckets();
26-
$has = $this->has($jti, $targetUri);
28+
$has = $this->has($jti, $hash);
2729

2830
if ($has === false) {
29-
$this->store($jti, $targetUri);
31+
$this->store($jti, $hash);
3032
}
3133

3234
return $has;

solid/lib/Migration/Version000000Date20220923134100.php

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Solid\Migration;
6+
7+
use Closure;
8+
use OCP\DB\ISchemaWrapper;
9+
use OCP\DB\Types;
10+
use OCP\Migration\SimpleMigrationStep;
11+
use OCP\Migration\IOutput;
12+
13+
class Version000000Date20221020145600 extends SimpleMigrationStep {
14+
/**
15+
* @param IOutput $output
16+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
17+
* @param array $options
18+
*
19+
* @return null|ISchemaWrapper
20+
*/
21+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper
22+
{
23+
/** @var ISchemaWrapper $schema */
24+
$schema = $schemaClosure();
25+
26+
// As the JTI table should only contain short-lived data anyway, it can safely be dropped
27+
if ($schema->hasTable('solid_jti') === true) {
28+
$schema->dropTable('solid_jti');
29+
}
30+
31+
$table = $schema->createTable('solid_jti');
32+
33+
$table->addColumn('id', Types::INTEGER, [
34+
'autoincrement' => true,
35+
'notnull' => true,
36+
]);
37+
38+
$table->addColumn('jti', Types::STRING, [
39+
'length' => 255,
40+
'notnull' => true,
41+
]);
42+
43+
$table->addColumn('uri', Types::STRING, [
44+
'length' => 40,
45+
'notnull' => true,
46+
]);
47+
48+
$table->addColumn('request_time', Types::DATETIME, [
49+
'default' => 'CURRENT_TIMESTAMP',
50+
'notnull' => true,
51+
]);
52+
53+
$table->setPrimaryKey(['id']);
54+
$table->addIndex(['jti', 'uri']);
55+
56+
return $schema;
57+
}
58+
}

0 commit comments

Comments
 (0)