Skip to content

Commit 47e1b36

Browse files
committed
SPEC-835: Update spec and tests for userinfo percent sign encoding
1 parent c552534 commit 47e1b36

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

source/connection-string/connection-string-spec.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Connection String Spec
1111
:Advisors: \A. Jesse Jiryu Davis, Jeremy Mikola, Anna Herlihy
1212
:Status: Approved
1313
:Type: Standards
14-
:Last Modified: Jul. 22, 2016
14+
:Last Modified: Jan. 09, 2017
1515
:Version: 1.1
1616

1717
.. contents::
@@ -326,12 +326,12 @@ Q: Can the connection string contain non-ASCII characters?
326326
Q: Why does reference implementation check for a ``.sock`` suffix when parsing a socket path and possible auth database?
327327
To simplify parsing of a socket path followed by an auth database, we rely on MongoDB's `naming restrictions <http://docs.mongodb.org/manual/reference/limits/#naming-restrictions>`_), which do not allow database names to contain a dot character, and the fact that socket paths must end with ``.sock``. This allows us to differentiate the last part of a socket path from a database name. While we could immediately rule out an auth database on the basis of the dot alone, this specification is primarily concerned with breaking down the components of a URI (e.g. hosts, auth database, options) in a deterministic manner, rather than applying strict validation to those parts (e.g. host types, database names, allowed values for an option). Additionally, some drivers might allow a namespace (e.g. ``"db.collection"``) for the auth database part, so we do not want to be more strict than is necessary for parsing.
328328

329-
Q: Why throw an exception if the userinfo contains an at-sign ("@") or more than one colon (":")?
329+
Q: Why throw an exception if the userinfo contains a percent sign ("%"), at-sign ("@"), or more than one colon (":")?
330330
This is done to help users format the connection string correctly. Although at-signs ("@") or colons (":") in the username must be URL encoded, users may not be aware of that requirement. Take the following example::
331331

332332
mongodb://anne:bob:pass@localhost:27017
333333

334-
Is the username ``anne`` and the password ``bob:pass`` or is the username ``anne:bob`` and the password ``pass``? Accepting this as the userinfo could cause authentication to fail, causing confusion for the user as to why. By throwing an exception users are made aware and then update the connection string so to be explicit about what forms the username and password.
334+
Is the username ``anne`` and the password ``bob:pass`` or is the username ``anne:bob`` and the password ``pass``? Accepting this as the userinfo could cause authentication to fail, causing confusion for the user as to why. Allowing unescaped at-sign and percent symbols would invite further ambiguity. By throwing an exception users are made aware and then update the connection string so to be explicit about what forms the username and password.
335335

336336
Q: Why must UNIX domain sockets be URL encoded?
337337
This has been done to reduce ambiguity between the socket name and the database name. Take the following example::
@@ -351,4 +351,5 @@ Q: Why must the auth database be URL decoded by the parser?
351351
Changes
352352
-------
353353

354+
- 2017-01-09: In Userinfo section, clarify that percent signs must be encoded.
354355
- 2016-07-22: In Port section, clarify that zero is not an acceptable port.

source/connection-string/tests/invalid-uris.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ tests:
159159
hosts: ~
160160
auth: ~
161161
options: ~
162+
-
163+
description: "Username with password containing an unescaped percent sign"
164+
uri: "mongodb://alice%foo:bar@127.0.0.1"
165+
valid: false
166+
warning: ~
167+
hosts: ~
168+
auth: ~
169+
options: ~
162170
-
163171
description: "Username with password containing an unescaped colon"
164172
uri: "mongodb://alice:foo:bar@127.0.0.1"

0 commit comments

Comments
 (0)