Skip to content

Commit 52ca699

Browse files
Check whether secrets are empty and mark them all as sensitive
1 parent 9a1a42e commit 52ca699

File tree

21 files changed

+74
-34
lines changed

21 files changed

+74
-34
lines changed

src/Symfony/Component/HttpFoundation/UriSigner.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation;
1313

1414
/**
15-
* Signs URIs.
16-
*
1715
* @author Fabien Potencier <fabien@symfony.com>
1816
*/
1917
class UriSigner
@@ -22,11 +20,14 @@ class UriSigner
2220
private string $parameter;
2321

2422
/**
25-
* @param string $secret A secret
2623
* @param string $parameter Query string parameter to use
2724
*/
2825
public function __construct(#[\SensitiveParameter] string $secret, string $parameter = '_hash')
2926
{
27+
if (!$secret) {
28+
throw new \InvalidArgumentException('A non-empty secret is required.');
29+
}
30+
3031
$this->secret = $secret;
3132
$this->parameter = $parameter;
3233
}

src/Symfony/Component/Mailer/Bridge/Brevo/Webhook/BrevoRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getRequestMatcher(): RequestMatcherInterface
4141
]);
4242
}
4343

44-
protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
44+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?AbstractMailerEvent
4545
{
4646
$content = $request->toArray();
4747
if (

src/Symfony/Component/Mailer/Bridge/Mailgun/Webhook/MailgunRequestParser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
1818
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
1919
use Symfony\Component\Mailer\Bridge\Mailgun\RemoteEvent\MailgunPayloadConverter;
20+
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
2021
use Symfony\Component\RemoteEvent\Event\Mailer\AbstractMailerEvent;
2122
use Symfony\Component\RemoteEvent\Exception\ParseException;
2223
use Symfony\Component\Webhook\Client\AbstractRequestParser;
@@ -37,8 +38,12 @@ protected function getRequestMatcher(): RequestMatcherInterface
3738
]);
3839
}
3940

40-
protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
41+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?AbstractMailerEvent
4142
{
43+
if (!$secret) {
44+
throw new InvalidArgumentException('A non-empty secret is required.');
45+
}
46+
4247
$content = $request->toArray();
4348
if (
4449
!isset($content['signature']['timestamp'])
@@ -60,7 +65,7 @@ protected function doParse(Request $request, string $secret): ?AbstractMailerEve
6065
}
6166
}
6267

63-
private function validateSignature(array $signature, string $secret): void
68+
private function validateSignature(array $signature, #[\SensitiveParameter] string $secret): void
6469
{
6570
// see https://documentation.mailgun.com/en/latest/user_manual.html#webhooks-1
6671
if (!hash_equals($signature['signature'], hash_hmac('sha256', $signature['timestamp'].$signature['token'], $secret))) {

src/Symfony/Component/Mailer/Bridge/Mailjet/Webhook/MailjetRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function getRequestMatcher(): RequestMatcherInterface
3737
]);
3838
}
3939

40-
protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
40+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?AbstractMailerEvent
4141
{
4242
try {
4343
return $this->converter->convert($request->toArray());

src/Symfony/Component/Mailer/Bridge/Postmark/Webhook/PostmarkRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getRequestMatcher(): RequestMatcherInterface
4141
]);
4242
}
4343

44-
protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
44+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?AbstractMailerEvent
4545
{
4646
$payload = $request->toArray();
4747
if (

src/Symfony/Component/Mailer/Bridge/Sendgrid/Webhook/SendgridRequestParser.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
1818
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
1919
use Symfony\Component\Mailer\Bridge\Sendgrid\RemoteEvent\SendgridPayloadConverter;
20+
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
2021
use Symfony\Component\RemoteEvent\Event\Mailer\AbstractMailerEvent;
2122
use Symfony\Component\RemoteEvent\Exception\ParseException;
2223
use Symfony\Component\Webhook\Client\AbstractRequestParser;
@@ -86,12 +87,12 @@ protected function doParse(Request $request, string $secret): ?AbstractMailerEve
8687
*
8788
* @see https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features
8889
*/
89-
private function validateSignature(
90-
string $signature,
91-
string $timestamp,
92-
string $payload,
93-
string $secret,
94-
): void {
90+
private function validateSignature(string $signature, string $timestamp, string $payload, #[\SensitiveParameter] string $secret): void
91+
{
92+
if (!$secret) {
93+
throw new InvalidArgumentException('A non-empty secret is required.');
94+
}
95+
9596
$timestampedPayload = $timestamp.$payload;
9697

9798
// Sendgrid provides the verification key as base64-encoded DER data. Openssl wants a PEM format, which is a multiline version of the base64 data.

src/Symfony/Component/Mailer/Transport/Smtp/Auth/CramMd5Authenticator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Mailer\Transport\Smtp\Auth;
1313

14+
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
1415
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
1516

1617
/**
@@ -41,6 +42,10 @@ public function authenticate(EsmtpTransport $client): void
4142
*/
4243
private function getResponse(#[\SensitiveParameter] string $secret, string $challenge): string
4344
{
45+
if (!$secret) {
46+
throw new InvalidArgumentException('A non-empty secret is required.');
47+
}
48+
4449
if (\strlen($secret) > 64) {
4550
$secret = pack('H32', md5($secret));
4651
}

src/Symfony/Component/Notifier/Bridge/Twilio/Webhook/TwilioRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function getRequestMatcher(): RequestMatcherInterface
2525
return new MethodRequestMatcher('POST');
2626
}
2727

28-
protected function doParse(Request $request, string $secret): ?SmsEvent
28+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?SmsEvent
2929
{
3030
// Statuses: https://www.twilio.com/docs/sms/api/message-resource#message-status-values
3131
// Payload examples: https://www.twilio.com/docs/sms/outbound-message-logging

src/Symfony/Component/Notifier/Bridge/Vonage/Webhook/VonageRequestParser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;
1717
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
1818
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
19+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1920
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
2021
use Symfony\Component\Webhook\Client\AbstractRequestParser;
2122
use Symfony\Component\Webhook\Exception\RejectWebhookException;
@@ -30,8 +31,12 @@ protected function getRequestMatcher(): RequestMatcherInterface
3031
]);
3132
}
3233

33-
protected function doParse(Request $request, string $secret): ?SmsEvent
34+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?SmsEvent
3435
{
36+
if (!$secret) {
37+
throw new InvalidArgumentException('A non-empty secret is required.');
38+
}
39+
3540
// Signed webhooks: https://developer.vonage.com/en/getting-started/concepts/webhooks#validating-signed-webhooks
3641
if (!$request->headers->has('Authorization')) {
3742
throw new RejectWebhookException(406, 'Missing "Authorization" header.');
@@ -70,7 +75,7 @@ protected function doParse(Request $request, string $secret): ?SmsEvent
7075
return $event;
7176
}
7277

73-
private function validateSignature(string $jwt, string $secret): void
78+
private function validateSignature(string $jwt, #[\SensitiveParameter] string $secret): void
7479
{
7580
$tokenParts = explode('.', $jwt);
7681
if (3 !== \count($tokenParts)) {

src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Core\Authentication\Token;
1313

14+
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1415
use Symfony\Component\Security\Core\User\UserInterface;
1516

1617
/**
@@ -32,12 +33,12 @@ public function __construct(UserInterface $user, string $firewallName, #[\Sensit
3233
{
3334
parent::__construct($user->getRoles());
3435

35-
if (empty($secret)) {
36-
throw new \InvalidArgumentException('$secret must not be empty.');
36+
if (!$secret) {
37+
throw new InvalidArgumentException('A non-empty secret is required.');
3738
}
3839

39-
if ('' === $firewallName) {
40-
throw new \InvalidArgumentException('$firewallName must not be empty.');
40+
if (!$firewallName) {
41+
throw new InvalidArgumentException('$firewallName must not be empty.');
4142
}
4243

4344
$this->firewallName = $firewallName;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy