From 5812a4959926384b3cffd05054360ba556d665bd Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Tue, 24 Aug 2021 16:49:35 +0200 Subject: [PATCH] [AMQP] [Messenger] Do not leak any credentials when connection fails I noticed that when the connection to AMQP fails for whatever reason all the DSK credentials are leaked. Yes, the password is masked. But it still leaks the server, port and username. I think these things should be private and not be logged to a logger server or error capture service. --- .../Bridge/Amqp/Tests/Transport/ConnectionTest.php | 4 ++-- .../Messenger/Bridge/Amqp/Transport/Connection.php | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php index c37d89676b2c2..c2a70639e9526 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php @@ -559,10 +559,10 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs() $connection->publish('{}', [], 120000); } - public function testObfuscatePasswordInDsn() + public function testNoCredentialLeakageWhenConnectionFails() { $this->expectException(\AMQPException::class); - $this->expectExceptionMessage('Could not connect to the AMQP server. Please verify the provided DSN. ({"host":"localhost","port":5672,"vhost":"/","login":"user","password":"********"})'); + $this->expectExceptionMessage('Could not connect to the AMQP server. Please verify the provided DSN.'); $factory = new TestAmqpFactory( $amqpConnection = $this->createMock(\AMQPConnection::class), $amqpChannel = $this->createMock(\AMQPChannel::class), diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php index e03dc72a472c6..1dead1503ade4 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php @@ -495,11 +495,7 @@ public function channel(): \AMQPChannel try { $connection->{$connectMethod}(); } catch (\AMQPConnectionException $e) { - $credentials = $this->connectionOptions; - $credentials['password'] = '********'; - unset($credentials['delay']); - - 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); + throw new \AMQPException('Could not connect to the AMQP server. Please verify the provided DSN.', 0, $e); } $this->amqpChannel = $this->amqpFactory->createChannel($connection);