Skip to content

Commit 7eacb2c

Browse files
williamdesDeepSeek
andcommitted
security: Stop storing the GitHub token in the database
saveFromGithub() has written the token of the login in plain text since 5dbb657 created the model, and nothing reads it back: the controllers use the token of the session, and the command that runs without a session reads the one of the configuration. f8759cf moved the write to patch() without touching it. Stop writing it, and clear the values that are already in the column with a migration that keeps the column, so an installation can be migrated without a schema change. Signed-off-by: William Desportes <williamdes@wdes.fr> Co-Authored-By: DeepSeek <noreply@deepseek.com>
1 parent 271b4f4 commit 7eacb2c

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Migrations\BaseMigration;
4+
5+
/**
6+
* Clear the GitHub access tokens that were stored in plain text.
7+
*
8+
* The application only keeps the token in the session, so the column values are
9+
* no longer needed.
10+
*/
11+
class ClearDevelopersAccessToken extends BaseMigration
12+
{
13+
public function up(): void
14+
{
15+
$this->getQueryBuilder('update')
16+
->update('developers')
17+
->set(['access_token' => null])
18+
->execute();
19+
}
20+
21+
public function down(): void
22+
{
23+
// The tokens cannot be restored: they were stored in plain text and must
24+
// not be written back.
25+
}
26+
}

‎src/Model/Table/DevelopersTable.php‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@
2929
class DevelopersTable extends Table
3030
{
3131
/**
32-
* creates a developer record given his github info and his access token.
32+
* creates a developer record given his github info.
3333
*
34-
* @param array $githubInfo the data gitub has on this developer
35-
* @param string $accessToken this developer's access token
36-
* @param EntityInterface $developer the developper
34+
* The GitHub access token is not stored: it is only kept in the session
35+
* for the current login and never written in plain text in the database.
36+
*
37+
* @param array $githubInfo the data gitub has on this developer
38+
* @param EntityInterface $developer the developper
3739
*
3840
* @return int|null The developer Id
3941
*/
40-
public function saveFromGithub(array $githubInfo, string $accessToken, EntityInterface $developer): int|null
42+
public function saveFromGithub(array $githubInfo, EntityInterface $developer): int|null
4143
{
4244
$developer->patch([
4345
'full_name' => $githubInfo['name'],
@@ -46,7 +48,6 @@ public function saveFromGithub(array $githubInfo, string $accessToken, EntityInt
4648
// the address when the developer made it public.
4749
'email' => $githubInfo['email'] ?? null,
4850
'github_id' => $githubInfo['id'],
49-
'access_token' => $accessToken,
5051
'has_commit_access' => $githubInfo['has_commit_access'] ? 1 : 0,
5152
]);
5253
if ($this->save($developer)) {

‎tests/TestCase/Model/Table/DevelopersTableTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ public function testSaveFromGithub(): void
8888
'has_commit_access' => 0,
8989
];
9090
$developer = $this->Developers->newEmptyEntity();
91-
$access_token = 'abc';
9291

93-
$this->Developers->saveFromGithub($githubInfo, $access_token, $developer);
92+
$this->Developers->saveFromGithub($githubInfo, $developer);
9493

9594
$savedDeveloper = $this->Developers->get($nextId);
9695
$this->assertNotEquals(null, $savedDeveloper);
9796
$this->assertEquals(1231231, $savedDeveloper->github_id);
9897
$this->assertEquals('PMA BOT', $savedDeveloper->full_name);
9998
$this->assertEquals('pma-bot@phpmyadmin.net', $savedDeveloper->email);
10099
$this->assertEquals(false, $savedDeveloper->has_commit_access);
100+
$this->assertNull($savedDeveloper->access_token, 'The access token must not be stored in plain text.');
101101

102102
$updatedGithubInfo = [
103103
'login' => 'pma-bot',
@@ -109,7 +109,7 @@ public function testSaveFromGithub(): void
109109
'has_commit_access' => 1,// changed
110110
];
111111

112-
$this->Developers->saveFromGithub($updatedGithubInfo, $access_token, $developer);
112+
$this->Developers->saveFromGithub($updatedGithubInfo, $developer);
113113

114114
$savedDeveloper = $this->Developers->get($nextId);
115115
$this->assertNotEquals(null, $savedDeveloper);

0 commit comments

Comments
 (0)