Skip to content

Commit c287443

Browse files
minor symfony#61737 [Lock] do not support sensitive option entries (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [Lock] do not support sensitive option entries | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- b165fb7 do not support sensitive option entries
2 parents 55f242e + b165fb7 commit c287443

File tree

2 files changed

+14
-48
lines changed

2 files changed

+14
-48
lines changed

src/Symfony/Component/Lock/Bridge/DynamoDb/Store/DynamoDbStore.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class DynamoDbStore implements PersistingStoreInterface
3636
use ExpiringStoreTrait;
3737

3838
private const DEFAULT_OPTIONS = [
39-
'access_key' => null,
40-
'secret_key' => null,
4139
'session_token' => null,
4240
'endpoint' => null,
4341
'region' => null,
@@ -60,7 +58,7 @@ class DynamoDbStore implements PersistingStoreInterface
6058
private int $writeCapacityUnits;
6159

6260
public function __construct(
63-
DynamoDbClient|string $clientOrDsn,
61+
#[\SensitiveParameter] DynamoDbClient|string $clientOrDsn,
6462
array $options = [],
6563
private readonly int $initialTtl = 300,
6664
) {
@@ -96,8 +94,8 @@ public function __construct(
9694

9795
$clientConfiguration = [
9896
'region' => $options['region'],
99-
'accessKeyId' => rawurldecode($params['user'] ?? '') ?: $options['access_key'] ?? self::DEFAULT_OPTIONS['access_key'],
100-
'accessKeySecret' => rawurldecode($params['pass'] ?? '') ?: $options['secret_key'] ?? self::DEFAULT_OPTIONS['secret_key'],
97+
'accessKeyId' => rawurldecode($params['user'] ?? '') ?: null,
98+
'accessKeySecret' => rawurldecode($params['pass'] ?? '') ?: null,
10199
];
102100
if (null !== $options['session_token']) {
103101
$clientConfiguration['sessionToken'] = $options['session_token'];
@@ -141,15 +139,15 @@ public function save(Key $key): void
141139
'Item' => [
142140
$this->idAttr => new AttributeValue(['S' => $this->getHashedKey($key)]),
143141
$this->tokenAttr => new AttributeValue(['S' => $this->getUniqueToken($key)]),
144-
$this->expirationAttr => new AttributeValue(['N' => (string) (\microtime(true) + $this->initialTtl)]),
142+
$this->expirationAttr => new AttributeValue(['N' => (string) (microtime(true) + $this->initialTtl)]),
145143
],
146144
'ConditionExpression' => 'attribute_not_exists(#key) OR #expires_at < :now',
147145
'ExpressionAttributeNames' => [
148146
'#key' => $this->idAttr,
149147
'#expires_at' => $this->expirationAttr,
150148
],
151149
'ExpressionAttributeValues' => [
152-
':now' => new AttributeValue(['N' => (string) \microtime(true)]),
150+
':now' => new AttributeValue(['N' => (string) microtime(true)]),
153151
],
154152
]);
155153

@@ -196,7 +194,7 @@ public function exists(Key $key): bool
196194
$item = $existingLock->getItem();
197195

198196
// Item not found at all
199-
if ($item === []) {
197+
if (!$item) {
200198
return false;
201199
}
202200

@@ -206,7 +204,7 @@ public function exists(Key $key): bool
206204
}
207205

208206
// If item is expired, consider it doesn't exist
209-
return isset($item[$this->expirationAttr]) && ((float) $item[$this->expirationAttr]->getN()) > \microtime(true);
207+
return isset($item[$this->expirationAttr]) && ((float) $item[$this->expirationAttr]->getN()) > microtime(true);
210208
}
211209

212210
public function putOffExpiration(Key $key, float $ttl): void
@@ -225,7 +223,7 @@ public function putOffExpiration(Key $key, float $ttl): void
225223
'Item' => [
226224
$this->idAttr => new AttributeValue(['S' => $this->getHashedKey($key)]),
227225
$this->tokenAttr => new AttributeValue(['S' => $uniqueToken]),
228-
$this->expirationAttr => new AttributeValue(['N' => (string) (\microtime(true) + $ttl)]),
226+
$this->expirationAttr => new AttributeValue(['N' => (string) (microtime(true) + $ttl)]),
229227
],
230228
'ConditionExpression' => 'attribute_exists(#key) AND (#token = :token OR #expires_at <= :now)',
231229
'ExpressionAttributeNames' => [
@@ -234,7 +232,7 @@ public function putOffExpiration(Key $key, float $ttl): void
234232
'#token' => $this->tokenAttr,
235233
],
236234
'ExpressionAttributeValues' => [
237-
':now' => new AttributeValue(['N' => (string) \microtime(true)]),
235+
':now' => new AttributeValue(['N' => (string) microtime(true)]),
238236
':token' => new AttributeValue(['S' => $uniqueToken]),
239237
],
240238
]));
@@ -248,7 +246,7 @@ public function putOffExpiration(Key $key, float $ttl): void
248246
$this->checkNotExpired($key);
249247
}
250248

251-
public function createTable(): void
249+
private function createTable(): void
252250
{
253251
$this->client->createTable(new CreateTableInput([
254252
'TableName' => $this->tableName,

src/Symfony/Component/Lock/Bridge/DynamoDb/Tests/Store/DynamoDbStoreTest.php

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,6 @@ public function testExtraParamsInQuery()
3131
new DynamoDbStore('dynamodb://default/lock_keys?extra_param=some_value');
3232
}
3333

34-
public function testConfigureWithCredentials()
35-
{
36-
$awsKey = 'some_aws_access_key_value';
37-
$awsSecret = 'some_aws_secret_value';
38-
$region = 'us-east-1';
39-
$this->assertEquals(
40-
new DynamoDbStore(new DynamoDbClient(['region' => $region, 'accessKeyId' => $awsKey, 'accessKeySecret' => $awsSecret]), ['table_name' => 'lock_keys']),
41-
new DynamoDbStore('dynamodb://default/lock_keys', [
42-
'access_key' => $awsKey,
43-
'secret_key' => $awsSecret,
44-
'region' => $region,
45-
])
46-
);
47-
}
48-
49-
public function testConfigureWithTemporaryCredentials()
50-
{
51-
$awsKey = 'some_aws_access_key_value';
52-
$awsSecret = 'some_aws_secret_value';
53-
$sessionToken = 'some_aws_sessionToken';
54-
$region = 'us-east-1';
55-
$this->assertEquals(
56-
new DynamoDbStore(new DynamoDbClient(['region' => $region, 'accessKeyId' => $awsKey, 'accessKeySecret' => $awsSecret, 'sessionToken' => $sessionToken]), ['table_name' => 'table']),
57-
new DynamoDbStore('dynamodb://default/table', [
58-
'access_key' => $awsKey,
59-
'secret_key' => $awsSecret,
60-
'session_token' => $sessionToken,
61-
'region' => $region,
62-
])
63-
);
64-
}
65-
6634
public function testFromInvalidDsn()
6735
{
6836
$this->expectException(\InvalidArgumentException::class);
@@ -91,7 +59,7 @@ public function testDsnPrecedence()
9159
{
9260
$this->assertEquals(
9361
new DynamoDbStore(new DynamoDbClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn']), ['table_name' => 'table_dsn']),
94-
new DynamoDbStore('dynamodb://key_dsn:secret_dsn@default/table_dsn?region=us-east-2', ['region' => 'eu-west-3', 'table_name' => 'table_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'])
62+
new DynamoDbStore('dynamodb://key_dsn:secret_dsn@default/table_dsn?region=us-east-2', ['region' => 'eu-west-3', 'table_name' => 'table_options'])
9563
);
9664
}
9765

@@ -159,23 +127,23 @@ public function testFromDsnWithTableNameOption()
159127
public function testFromDsnWithInvalidQueryString()
160128
{
161129
$this->expectException(\InvalidArgumentException::class);
162-
$this->expectExceptionMessageMatches('|Unknown option found in DSN: \[foo\]\. Allowed options are \[access_key, |');
130+
$this->expectExceptionMessageMatches('|Unknown option found in DSN: \[foo\]\. Allowed options are \[session_token, |');
163131

164132
new DynamoDbStore('dynamodb://default?foo=foo');
165133
}
166134

167135
public function testFromDsnWithInvalidOption()
168136
{
169137
$this->expectException(\InvalidArgumentException::class);
170-
$this->expectExceptionMessageMatches('|Unknown option found: \[bar\]\. Allowed options are \[access_key, |');
138+
$this->expectExceptionMessageMatches('|Unknown option found: \[bar\]\. Allowed options are \[session_token, |');
171139

172140
new DynamoDbStore('dynamodb://default', ['bar' => 'bar']);
173141
}
174142

175143
public function testFromDsnWithInvalidQueryStringAndOption()
176144
{
177145
$this->expectException(\InvalidArgumentException::class);
178-
$this->expectExceptionMessageMatches('|Unknown option found: \[bar\]\. Allowed options are \[access_key, |');
146+
$this->expectExceptionMessageMatches('|Unknown option found: \[bar\]\. Allowed options are \[session_token, |');
179147

180148
new DynamoDbStore('dynamodb://default?foo=foo', ['bar' => 'bar']);
181149
}

0 commit comments

Comments
 (0)