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

fix: disallow pre-signed url access if the signing key is not initialized #40962

Merged
merged 1 commit into from
Sep 5, 2023
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
5 changes: 5 additions & 0 deletions changelog/unreleased/40962
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Disallow pre-signed URL access when the signing key is not initialized

Disallow pre-signed URL access when the signing key is not initialized.

https://github.com/owncloud/core/pull/40962
5 changes: 5 additions & 0 deletions lib/private/Security/SignedUrl/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ protected function computeHash(string $algo, string $url, $signingKey) {
private function verifySignature(array $params, $urlCredential, $algo, $urlSignature): bool {
$trustedList = $this->config->getSystemValue('trusted_domains', []);
$signingKey = $this->config->getUserValue($urlCredential, 'core', 'signing-key');
// in case the signing key is not initialized, no signature can ever be verified
if ($signingKey === '') {
\OC::$server->getLogger()->error("No signing key available for the user $urlCredential. Access via pre-signed URL denied.", ['app' => 'signed-url']);
return false;
}
$qp = \preg_replace('/%5B\d+%5D/', '%5B%5D', \http_build_query($params));

foreach ($trustedList as $trustedDomain) {
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/Security/SignedUrl/VerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
use Test\TestCase;

class VerifierTest extends TestCase {
public function testNoSigningKey(): void {
$url = 'http://cloud.example.net/?OC-Credential=alice&OC-Date=2019-05-14T11%3A01%3A58.135Z&OC-Expires=1200&OC-Verb=GET&OC-Signature=f9e53a1ee23caef10f72ec392c1b537317491b687bfdd224c782be197d9ca2b6';
$r = new Request('GET', $url);
$r->setAbsoluteUrl($url);
$config = $this->createMock(IConfig::class);
# signing key for the user was never initialized
$config->method('getUserValue')->willReturn('');
$now = new \DateTime('2019-05-14T11:01:58.135Z', null);
$v = new Verifier($r, $config, $now);

self::assertTrue($v->isSignedRequest());
self::assertEquals('alice', $v->getUrlCredential());
self::assertFalse($v->signedRequestIsValid());
}

/**
* @dataProvider provider
* @param bool $isSignedUrl
Expand Down