Skip to content

Commit 46fac92

Browse files
committed
fix(files_external): guard optional S3 key in storage id computation
S3 external mounts that authenticate via the AWS SDK default credential chain (env vars, EC2 instance profile, ECS task role) carry no static `key` param. AmazonS3::__construct() read $this->params['key'] unconditionally when deriving the storage id, emitting an "Undefined array key" warning on every storage construction for such mounts. Guard the access with `?? ''`. This aligns the id computation with paramCredentialProvider(), which already treats `key` as optional and falls through to the SDK default provider chain when it is absent. The value only feeds an md5() hash, so keyless mounts keep a stable id. Fixes #63564 Assisted-by: Kiro:claude-opus-4.8 Signed-off-by: Sebastian Cruz <default50@gmail.com>
1 parent a17770e commit 46fac92

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(array $parameters) {
4949
parent::__construct($parameters);
5050
$this->parseParams($parameters);
5151
// @todo: using `key` here may be problematic with different authentication methods and/or key rotation...
52-
$this->id = 'amazon::external::' . md5($this->params['hostname'] . ':' . $this->params['bucket'] . ':' . $this->params['key']);
52+
$this->id = 'amazon::external::' . md5($this->params['hostname'] . ':' . $this->params['bucket'] . ':' . ($this->params['key'] ?? ''));
5353
$this->initCaches();
5454
$this->mimeDetector = Server::get(IMimeTypeDetector::class);
5555
/** @var ICacheFactory $cacheFactory */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files_External\Tests\Storage;
10+
11+
use OCA\Files_External\Lib\Storage\AmazonS3;
12+
use Test\TestCase;
13+
14+
/**
15+
* Regression test for the storage id computation in AmazonS3::__construct().
16+
*
17+
* Constructs the storage directly (no live S3 backend) to exercise only the id
18+
* derivation, which runs unconditionally in the constructor.
19+
*/
20+
#[\PHPUnit\Framework\Attributes\Group('S3')]
21+
class Amazons3IdTest extends TestCase {
22+
/**
23+
* Mounts authenticating via the AWS SDK default credential chain (env, EC2
24+
* instance profile, ECS task role) carry no static `key` param. The id must
25+
* still be derivable without emitting an "Undefined array key" warning
26+
* (PHPUnit fails the test on any emitted warning).
27+
*/
28+
public function testConstructWithoutKey(): void {
29+
$storage = new AmazonS3(['bucket' => 'test-bucket']);
30+
$this->assertNotEmpty($storage->getId());
31+
}
32+
}

0 commit comments

Comments
 (0)