[SERVER-27997] mongo connection URI cannot connect when there's "@" character in password Created: 14/Feb/17  Updated: 31/May/17  Resolved: 16/Feb/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: tracy Assignee: Spencer Jackson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-25059 URL support needs to support percent-... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

There is a "@" character in my password and I tried to use connection string URI to connect MongoDB

mongo 'mongodb://user:abc@123@localhost:27017'

And I get this error:

~➜ ~ mongo 'mongodb://da:abc@123@localhost:27017'
MongoDB shell version v3.4.0
connecting to: mongodb://da:abc@123@localhost:27017
2017-02-14T15:02:59.061+0800 I NETWORK [main] getaddrinfo("123@localhost") failed: nodename nor servname provided, or not known
2017-02-14T15:02:59.063+0800 E QUERY [main] Error: couldn't initialize connection to host 123@localhost, address is invalid :
connect@src/mongo/shell/mongo.js:234:13
@(connect):1:6
exception: connect failed~

But mongo admin -u da -p 'abc@123' works well.So I read the mongo shell and mongo-cxx-driver code and I found this:

~namespace

{ const char kMongoDBURL[] = // scheme: non-capturing "mongodb://" // credentials: two inner captures for user and password "(?:([^:]+)(?::([^@]+))?@)?" // servers: grabs all host:port or UNIX socket names "((?:(?:[^\\/]+|/.+.sock?),?)+)" // database: matches anything but the chars that cannot // be part of a MongoDB database name. "(?:/([^/\\.\\ \"*<>:\\|\\?]*))?" // options "(?:\\?(?:(.+=.+)&?)+)*"; }

// namespace~

So it means that if my connection URI is

mongo 'mongodb://user:abc@123@localhost:27017'

it will return mongodb://da1:abc@ rather than mongodb://da1:abc@123@ ,is it a bug or I missed something?

Thanks.



 Comments   
Comment by Spencer Jackson [ 16/Feb/17 ]

Hi! You are correct, and this isn't something you can do right now in a connection URI. In general, it's not possible to stick an '@' there given the URI format, so you're supposed to percent encode the '@' into '%40'. Unfortunately, the shell doesn't currently support percent encoding. SERVER-25059 is tracking that bug. I'm going to direct this ticket there, so please be sure to follow SERVER-25059 for further updates on this issue. Thanks!

Generated at Thu Feb 08 04:16:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.