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

[stable29] fix(JWTManager): Mark private key as sensitive #808

Merged
merged 1 commit into from
Oct 21, 2024
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: 2 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It is also possible to add links only for a given language, device type or user

More information is available in the External sites documentation.]]></description>

<version>5.4.0</version>
<version>5.4.1</version>
<licence>agpl</licence>

<author>Joas Schilling</author>
Expand Down Expand Up @@ -40,6 +40,7 @@ More information is available in the External sites documentation.]]></descripti
<repair-steps>
<post-migration>
<step>OCA\External\Migration\CopyDefaultIcons</step>
<step>OCA\External\Migration\JWTTokenPrivateKeySensitive</step>
</post-migration>
<install>
<step>OCA\External\Migration\CopyDefaultIcons</step>
Expand Down
2 changes: 1 addition & 1 deletion lib/JWTManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function ensureTokenKeys(string $alg): void {
throw new \Exception('Unsupported algorithm ' . $alg);
}

$this->config->setValueString(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg), $secret);
$this->config->setValueString(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg), $secret, sensitive: true);
$this->config->setValueString(Application::APP_ID, 'jwt_token_pubkey_' . strtolower($alg), $public);
}

Expand Down
37 changes: 37 additions & 0 deletions lib/Migration/JWTTokenPrivateKeySensitive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\External\Migration;

use OCA\External\AppInfo\Application;
use OCP\IAppConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class JWTTokenPrivateKeySensitive implements IRepairStep {
public function __construct(
private IAppConfig $config,
) {
}

public function getName() {
return 'Mark JWT token private key as sensitive';
}

public function run(IOutput $output): void {
foreach ($this->config->getKeys(Application::APP_ID) as $key) {
if (!str_starts_with($key, 'jwt_token_privkey_')) {
continue;
}

$secret = $this->config->getValueString(Application::APP_ID, $key);
$this->config->setValueString(Application::APP_ID, $key, $secret, sensitive: true);
}
}
}
Loading