8000 bug #42707 [Messenger] [AMQP] Do not leak any credentials when conne… · symfony/symfony@d336926 · GitHub
[go: up one dir, main page]

Skip to content

Commit d336926

Browse files
committed
bug #42707 [Messenger] [AMQP] Do not leak any credentials when connection fails (ruudk)
This PR was submitted for the 5.4 branch but it was merged into the 5.3 branch instead. Discussion ---------- [Messenger] [AMQP] Do not leak any credentials when connection fails | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? |no | Deprecations? | no | Tickets | | License | MIT | Doc PR | I noticed that when the connection to AMQP fails for whatever reason all the DSN credentials are leaked. ``` Aug 24 15:58:40 CRITICAL: Error thrown while running command "messenger:consume async". Message: "Could not connect to the AMQP server. Please verify the provided DSN. ({"host":my-hostname-on-some-server","port":my-port,"vhost":"the-real-vhost", "login":"the-real-username","password":"********"}) ``` Yes, the password is masked. But it still leaks the server, port, username and vhost. I think these things should be private and not be logged to a logger server or error capture service. Commits ------- 5812a49 [AMQP] [Messenger] Do not leak any credentials when connection fails
2 parents 8a33e05 + 5812a49 commit d336926

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,10 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
559559
$connection->publish('{}', [], 120000);
560560
}
561561

562-
public function testObfuscatePasswordInDsn()
562+
public function testNoCredentialLeakageWhenConnectionFails()
563563
{
564564
$this->expectException(\AMQPException::class);
565-
$this->expectExceptionMessage('Could not connect to the AMQP server. Please verify the provided DSN. ({"host":"localhost","port":5672,"vhost":"/","login":"user","password":"********"})');
565+
$this->expectExceptionMessage('Could not connect to the AMQP server. Please verify the provided DSN.');
566566
$factory = new TestAmqpFactory(
567567
$amqpConnection = $this->createMock(\AMQPConnection::class),
568568
$amqpChannel = $this->createMock(\AMQPChannel::class),

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,7 @@ public function channel(): \AMQPChannel
495495
try {
496496
$connection->{$connectMethod}();
497497
} catch (\AMQPConnectionException $e) {
498-
$credentials = $this->connectionOptions;
499-
$credentials['password'] = '********';
500-
unset($credentials['delay']);
501-
502-
throw new \AMQPException(sprintf('Could not connect to the AMQP server. Please verify the provided DSN. (%s).', json_encode($credentials, \JSON_UNESCAPED_SLASHES)), 0, $e);
498+
throw new \AMQPException('Could not connect to the AMQP server. Please verify the provided DSN.', 0, $e);
503499
}
504500
$this->amqpChannel = $this->amqpFactory->createChannel($connection);
505501

0 commit comments

Comments
 (0)
0