Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c9d2c8

Browse filesBrowse files
committed
bug #39871 [Notifier] [OvhCloud] “Invalid signature” for message with slashes (OneT0uch)
This PR was squashed before being merged into the 5.1 branch. Discussion ---------- [Notifier] [OvhCloud] “Invalid signature” for message with slashes | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #39836 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Test to show issue of invalid signature when message contains slash. Commits ------- 9f01fb8 [Notifier] [OvhCloud] “Invalid signature” for message with slashes
2 parents 7e2ac5f + 9f01fb8 commit 1c9d2c8
Copy full SHA for 1c9d2c8

File tree

2 files changed

+41
-2
lines changed
Filter options

2 files changed

+41
-2
lines changed

‎src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ protected function doSend(MessageInterface $message): void
7575
$now = time() + $this->calculateTimeDelta();
7676
$headers['X-Ovh-Application'] = $this->applicationKey;
7777
$headers['X-Ovh-Timestamp'] = $now;
78+
$headers['Content-Type'] = 'application/json';
7879

79-
$toSign = $this->applicationSecret.'+'.$this->consumerKey.'+POST+'.$endpoint.'+'.json_encode($content, \JSON_UNESCAPED_SLASHES).'+'.$now;
80+
$body = json_encode($content, \JSON_UNESCAPED_SLASHES);
81+
$toSign = $this->applicationSecret.'+'.$this->consumerKey.'+POST+'.$endpoint.'+'.$body.'+'.$now;
8082
$headers['X-Ovh-Consumer'] = $this->consumerKey;
8183
$headers['X-Ovh-Signature'] = '$1$'.sha1($toSign);
8284

8385
$response = $this->client->request('POST', $endpoint, [
8486
'headers' => $headers,
85-
'json' => $content,
87+
'body' => $body,
8688
]);
8789

8890
if (200 !== $response->getStatusCode()) {

‎src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
1313

14+
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\HttpClient\Response\MockResponse;
1416
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
1517
use Symfony\Component\Notifier\Message\ChatMessage;
1618
use Symfony\Component\Notifier\Message\MessageInterface;
@@ -44,4 +46,39 @@ public function unsupportedMessagesProvider(): iterable
4446
yield [new ChatMessage('Hello!')];
4547
yield [$this->createMock(MessageInterface::class)];
4648
}
49+
50+
public function validMessagesProvider(): iterable
51+
{
52+
yield 'without a slash' => ['hello'];
53+
yield 'including a slash' => ['hel/lo'];
54+
}
55+
56+
/**
57+
* @group time-sensitive
58+
*
59+
* @dataProvider validMessagesProvider
60+
*/
61+
public function testValidSignature(string $message)
62+
{
63+
$smsMessage = new SmsMessage('0611223344', $message);
64+
65+
$time = time();
66+
67+
$lastResponse = new MockResponse();
68+
$responses = [
69+
new MockResponse((string) $time),
70+
$lastResponse,
71+
];
72+
73+
$transport = $this->createTransport(new MockHttpClient($responses));
74+
$transport->send($smsMessage);
75+
76+
$body = $lastResponse->getRequestOptions()['body'];
77+
$headers = $lastResponse->getRequestOptions()['headers'];
78+
$signature = explode(': ', $headers[4])[1];
79+
80+
$endpoint = 'https://eu.api.ovh.com/1.0/sms/serviceName/jobs';
81+
$toSign = 'applicationSecret+consumerKey+POST+'.$endpoint.'+'.$body.'+'.$time;
82+
$this->assertSame('$1$'.sha1($toSign), $signature);
83+
}
4784
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.