From 60985e37ab101131937c0cf32d71871588f37eed Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Mon, 13 May 2019 14:01:52 +0200 Subject: [PATCH] (mongodb) fix: encode username & password (#1506) * url-encode user/pwd in MongoDB driver * fix double declaration --- database/mongodb/custom/driver.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/database/mongodb/custom/driver.pm b/database/mongodb/custom/driver.pm index 5760e89c4..913cd1616 100644 --- a/database/mongodb/custom/driver.pm +++ b/database/mongodb/custom/driver.pm @@ -25,6 +25,7 @@ use warnings; use DateTime; use MongoDB; use Hash::Ordered; +use URI::Encode; sub new { my ($class, %options) = @_; @@ -106,8 +107,12 @@ sub get_port { sub connect { my ($self, %options) = @_; - my $uri = 'mongodb://'; - $uri .= $self->{username} . ':' . $self->{password} . '@' if ($self->{username} ne '' && $self->{password} ne ''); + my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_username = $uri->encode($self->{username}); + my $encoded_password = $uri->encode($self->{password}); + + $uri = 'mongodb://'; + $uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne ''); $uri .= $self->{hostname} if ($self->{hostname} ne ''); $uri .= ':' . $self->{port} if ($self->{port} ne '');