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

+4-3
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

+1-1
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

+7-2
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

+1-1
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

+1-1
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

+7-6
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

+5
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

+1-1
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

+7-2
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

+5-4
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;

src/Symfony/Component/Security/Core/Signature/SignatureHasher.php

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Signature;
1313

1414
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
15+
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1516
use Symfony\Component\Security\Core\Signature\Exception\ExpiredSignatureException;
1617
use Symfony\Component\Security\Core\Signature\Exception\InvalidSignatureException;
1718
use Symfony\Component\Security\Core\User\UserInterface;
@@ -37,6 +38,10 @@ class SignatureHasher
3738
*/
3839
public function __construct(PropertyAccessorInterface $propertyAccessor, array $signatureProperties, #[\SensitiveParameter] string $secret, ExpiredSignatureStorage $expiredSignaturesStorage = null, int $maxUses = null)
3940
{
41+
if (!$secret) {
42+
throw new InvalidArgumentException('A non-empty secret is required.');
43+
}
44+
4045
$this->propertyAccessor = $propertyAccessor;
4146
$this->signatureProperties = $signatureProperties;
4247
$this->secret = $secret;

src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2020
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2121
use Symfony\Component\Security\Core\Exception\CookieTheftException;
22+
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
2223
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
2324
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2425
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
@@ -51,6 +52,10 @@ class RememberMeAuthenticator implements InteractiveAuthenticatorInterface
5152

5253
public function __construct(RememberMeHandlerInterface $rememberMeHandler, #[\SensitiveParameter] string $secret, TokenStorageInterface $tokenStorage, string $cookieName, LoggerInterface $logger = null)
5354
{
55+
if (!$secret) {
56+
throw new InvalidArgumentException('A non-empty secret is required.');
57+
}
58+
5459
$this->rememberMeHandler = $rememberMeHandler;
5560
$this->secret = $secret;
5661
$this->tokenStorage = $tokenStorage;

src/Symfony/Component/Security/Http/RateLimiter/DefaultLoginRateLimiter.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\RateLimiter\AbstractRequestRateLimiter;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\RateLimiter\RateLimiterFactory;
17+
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1718
use Symfony\Component\Security\Http\SecurityRequestAttributes;
1819

1920
/**
@@ -35,10 +36,10 @@ final class DefaultLoginRateLimiter extends AbstractRequestRateLimiter
3536
*/
3637
public function __construct(RateLimiterFactory $globalFactory, RateLimiterFactory $localFactory, #[\SensitiveParameter] string $secret = '')
3738
{
38-
if ('' === $secret) {
39-
trigger_deprecation('symfony/security-http', '6.4', 'Calling "%s()" with an empty secret is deprecated. A non-empty secret will be mandatory in version 7.0.', __METHOD__);
40-
// throw new \Symfony\Component\Security\Core\Exception\InvalidArgumentException('A non-empty secret is required.');
39+
if (!$secret) {
40+
throw new InvalidArgumentException('A non-empty secret is required.');
4141
}
42+
4243
$this->globalFactory = $globalFactory;
4344
$this->localFactory = $localFactory;
4445
$this->secret = $secret;

src/Symfony/Component/Webhook/Client/AbstractRequestParser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
abstract class AbstractRequestParser implements RequestParserInterface
2424
{
25-
public function parse(Request $request, string $secret): ?RemoteEvent
25+
public function parse(Request $request, #[\SensitiveParameter] string $secret): ?RemoteEvent
2626
{
2727
$this->validate($request);
2828

@@ -41,7 +41,7 @@ public function createRejectedResponse(string $reason): Response
4141

4242
abstract protected function getRequestMatcher(): RequestMatcherInterface;
4343

44-
abstract protected function doParse(Request $request, string $secret): ?RemoteEvent;
44+
abstract protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?RemoteEvent;
4545

4646
protected function validate(Request $request): void
4747
{

src/Symfony/Component/Webhook/Client/RequestParser.php

+2-2
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): RemoteEvent
44+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): RemoteEvent
4545
{
4646
$body = $request->toArray();
4747

@@ -60,7 +60,7 @@ protected function doParse(Request $request, string $secret): RemoteEvent
6060
);
6161
}
6262

63-
private function validateSignature(HeaderBag $headers, string $body, $secret): void
63+
private function validateSignature(HeaderBag $headers, string $body, #[\SensitiveParameter] string $secret): void
6464
{
6565
$signature = $headers->get($this->signatureHeaderName);
6666
$event = $headers->get($this->eventHeaderName);

src/Symfony/Component/Webhook/Client/RequestParserInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface RequestParserInterface
2828
*
2929
* @throws RejectWebhookException When the payload is rejected (signature issue, parse issue, ...)
3030
*/
31-
public function parse(Request $request, string $secret): ?RemoteEvent;
31+
public function parse(Request $request, #[\SensitiveParameter] string $secret): ?RemoteEvent;
3232

3333
public function createSuccessfulResponse(): Response;
3434

src/Symfony/Component/Webhook/Server/HeaderSignatureConfigurator.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\HttpClient\HttpOptions;
1515
use Symfony\Component\RemoteEvent\RemoteEvent;
16+
use Symfony\Component\Webhook\Exception\InvalidArgumentException;
1617
use Symfony\Component\Webhook\Exception\LogicException;
1718

1819
/**
@@ -26,8 +27,12 @@ public function __construct(
2627
) {
2728
}
2829

29-
public function configure(RemoteEvent $event, string $secret, HttpOptions $options): void
30+
public function configure(RemoteEvent $event, #[\SensitiveParameter] string $secret, HttpOptions $options): void
3031
{
32+
if (!$secret) {
33+
throw new InvalidArgumentException('A non-empty secret is required.');
34+
}
35+
3136
$opts = $options->toArray();
3237
$headers = $opts['headers'];
3338
if (!isset($opts['body'])) {

src/Symfony/Component/Webhook/Server/HeadersConfigurator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28-
public function configure(RemoteEvent $event, string $secret, HttpOptions $options): void
28+
public function configure(RemoteEvent $event, #[\SensitiveParameter] string $secret, HttpOptions $options): void
2929
{
3030
$options->setHeaders([
3131
$this->eventHeaderName => $event->getName(),

src/Symfony/Component/Webhook/Server/JsonBodyConfigurator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28-
public function configure(RemoteEvent $event, string $secret, HttpOptions $options): void
28+
public function configure(RemoteEvent $event, #[\SensitiveParameter] string $secret, HttpOptions $options): void
2929
{
3030
$body = $this->serializer->serialize($event->getPayload(), 'json');
3131
$options->setBody($body);

src/Symfony/Component/Webhook/Server/RequestConfiguratorInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
*/
2020
interface RequestConfiguratorInterface
2121
{
22-
public function configure(RemoteEvent $event, string $secret, HttpOptions $options): void;
22+
public function configure(RemoteEvent $event, #[\SensitiveParameter] string $secret, HttpOptions $options): void;
2323
}

src/Symfony/Component/Webhook/Subscriber.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111

1212
namespace Symfony\Component\Webhook;
1313

14+
use Symfony\Component\Webhook\Exception\InvalidArgumentException;
15+
1416
class Subscriber
1517
{
1618
public function __construct(
1719
private readonly string $url,
18-
#[\SensitiveParameter] private readonly string $secret,
20+
#[\SensitiveParameter]
21+
private readonly string $secret,
1922
) {
23+
if (!$secret) {
24+
throw new InvalidArgumentException('A non-empty secret is required.');
25+
}
2026
}
2127

2228
public function getUrl(): string

0 commit comments

Comments
 (0)