Skip to content

Commit edad332

Browse files
committed
Server - HTTP signature - Enforce extraction pattern extension for hyphen
1 parent 0b98689 commit edad332

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ActivityPhp/Server/Http/HttpSignature.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class HttpSignature
5151

5252
/**
5353
* Inject a server instance
54-
*
55-
* @param \ActivityPhp\Server $server
5654
*/
5755
public function __construct(Server $server)
5856
{
@@ -65,7 +63,7 @@ public function __construct(Server $server)
6563
* @param \Symfony\Component\HttpFoundation\Request $request
6664
* @return bool True if signature has been verified. Otherwise false
6765
*/
68-
public function verify(Request $request)
66+
public function verify(Request $request): bool
6967
{
7068
// Read the Signature header,
7169
$signature = $request->headers->get('signature');

tests/ActivityPhp/Server/HttpSignatureTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ public function testSplittingSignature()
123123
'headers' => ' host date',
124124
'signature' => 'FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg==',
125125
]);
126+
127+
// Split a signature with headers (headers contains hyphens), algorithm.
128+
// For informtion, the following signature is false, no problem here as
129+
// we're only testing split HTTP signature component. Verification is
130+
// made after
131+
$signature = 'keyId="http://localhost:8001/accounts/bob#main-key",algorithm="rsa-sha256",headers="(request-target) host content-type digest date",signature="FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg=="';
132+
133+
$split = $verifier->splitSignature($signature);
134+
135+
$this->assertEquals($split, [
136+
'keyId' => 'http://localhost:8001/accounts/bob#main-key',
137+
'algorithm' => 'rsa-sha256',
138+
'headers' => ' host content-type digest date',
139+
'signature' => 'FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg==',
140+
]);
126141
}
127142

128143
/**

0 commit comments

Comments
 (0)