Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added encoding to user name and password #148

Merged
merged 3 commits into from
Feb 2, 2016

Conversation

taylorstine
Copy link
Contributor

I have an @ symbol in my mongo password. I realize that I can specify a custom class for the DatabaseAdapter, but I believe the decoding of a username and password should be built in to the default implementation.

var lastAtIndex = this.mongoURI.lastIndexOf('@');
var encodedMongoURI = this.mongoURI;
var username = null;
var password = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like username or password are used... and it looks like the database uri is being somewhat validated here, so how about we throw an error if it's not?

@taylorstine
Copy link
Contributor Author

@gfosco sorry for that, I've removed old references. I've added a regex validation for the mongo URI. It won't capture all invalid URIs, but it will at least validate the monogURI to be in the form we expect, as specified here. Also, not sure what your policy is on Regex, but I usually add a comment with a link to the tester. If this is against your standards, let me know and I'll remove it.

gfosco added a commit that referenced this pull request Feb 2, 2016
Added encoding to user name and password
@gfosco gfosco merged commit 15edb0c into parse-community:master Feb 2, 2016
@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

Thanks for adding the regxr link.. very cool. 👍

@themichael123
Copy link

This causes MongoDB Replica Sets to no longer work.

@taylorstine
Copy link
Contributor Author

@themichael123 can you provide an example URI?

@themichael123
Copy link

@taylorstine Have a look here: https://docs.mongodb.org/manual/reference/connection-string/

I wouldn't use regex for this task.

@adamontherun
Copy link

@taylorstine @gfosco here's an example of a paid MongoLabs URI that isn't working: mongodb://test:[email protected]:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415

here's an example of a free sandbox MongoLabs URI that is working:
mongodb://test:[email protected]:59145/mytestserver

@adamontherun
Copy link

I confirmed that the MongoLabs replica set URI worked fine in Parse Server 2.0.4, the breaking change was in 2.0.5

@gfosco
Copy link
Contributor

gfosco commented Feb 6, 2016

Let's get a fix PR sent in to parse-server to address this... @taylorstine are you interested in doing it?

@taylorstine
Copy link
Contributor Author

@gfosco sure, but I could use a second opinion on the regex. My aptitude for regex has kind of reached it's limit, maybe it should just be removed?

@adamontherun
Copy link

@gfosco @taylorstine I'd vote for removing the regex until we can be very confident in it. this bug breaks most parse server deployments that aren't running in the sandbox.

@drew-gross
Copy link
Contributor

The approach we used on hosted parse was to remove one character at a time from the end of the connection string until it looked like a regular URI, and then we could use a regular URI parsing library on it, modify the contents as needed, and then rebuild the connection string that includes all the replica sets. That approach might work here as well. Make sure to add tests if you use that approach though.

@jpgupta
Copy link

jpgupta commented Feb 8, 2016

In my case it's moving from a sandbox to a production environment on MongoLabs that breaks it.

It appears to be that the additional ?replicaSet argument added onto the URI fails the regex expression, I'd suggest taking it out as it's a little over-engineered. Testing the Mongo connection success/failure is probably worth while but it seems better to just trust people that they've entered a valid uri and will preserve future changes to the URI structure / arguments

@taylorstine taylorstine mentioned this pull request Feb 8, 2016
@taylorstine
Copy link
Contributor Author

#297 I'm not confident in this approach, I don't want to break anything just because my password has a @ sign

@flovilmart
Copy link
Contributor

So could we split the full host on "@", then take the last part as the 'real' host and join the [0, n-1] parts together? Then from that, we split on ":" to get the username / password.

montymxb pushed a commit to montymxb/parse-server that referenced this pull request Feb 14, 2016
bgw added a commit that referenced this pull request Mar 12, 2016
The mongodb driver requires auth values be URI encoded:
mongodb/node-mongodb-native@0440630

This uses node's built-in url module to encode the auth portion, by
parsing and re-formatting it, which causes special characters to get URI
encoded properly:
https://nodejs.org/api/url.html#url_escaped_characters

This is all a bit silly since mongodb just takes our passed uri, and
runs it through the same url parser again, but not before explicitly
erroring on '@' characters in the uri.

This is similiar to #148 (reverted by #297), but with much less code,
and hopefully less breakage. Also, note that `uri_decode_auth` is no
longer needed. That was removed in the above referenced
node-mongodb-native commit.

I've tested this on usernames and passwords with @, !, +, and a space.

Presumably this would also work with usernames and passwords that are
already URI encoded (since parseUrl will simply unescape it, and
formatUrl will escape it again).
bgw added a commit that referenced this pull request Mar 16, 2016
The mongodb driver requires auth values be URI encoded:
mongodb/node-mongodb-native@0440630

This uses node's built-in url module to encode the auth portion, by
parsing and re-formatting it, which causes special characters to get URI
encoded properly:
https://nodejs.org/api/url.html#url_escaped_characters

This is all a bit silly since mongodb just takes our passed uri, and
runs it through the same url parser again, but not before explicitly
erroring on '@' characters in the uri.

This is similiar to #148 (reverted by #297), but with much less code,
and hopefully less breakage. Also, note that `uri_decode_auth` is no
longer needed. That was removed in the above referenced
node-mongodb-native commit.

I've tested this on usernames and passwords with @, !, +, and a space.

Presumably this would also work with usernames and passwords that are
already URI encoded (since parseUrl will simply unescape it, and
formatUrl will escape it again).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants