Skip to content

Commit 2603c51

Browse files
blink1073jyemindurrankatcharov
authored
DRIVERS-2915 OIDC: Disallow comma character in authMechanismProperties connection string value (#1588)
* DRIVERS-2915 OIDC: Disallow comma character in authMechanismProperties connection string value * changelog * restore test without comma * Update source/auth/auth.md Co-authored-by: Jeff Yemin <[email protected]> * Update source/auth/tests/legacy/connection-string.json Co-authored-by: Durran Jordan <[email protected]> * update connection string logic * Update source/connection-string/connection-string-spec.md Co-authored-by: Maxim Katcharov <[email protected]> * clarify handling of key-value pairs and add specification test * Update source/connection-string/tests/valid-options.yml Co-authored-by: Maxim Katcharov <[email protected]> * update json test * Add a warning test * address review * Update source/connection-string/connection-string-spec.md Co-authored-by: Maxim Katcharov <[email protected]> * Update source/connection-string/connection-string-spec.md Co-authored-by: Maxim Katcharov <[email protected]> * Update source/connection-string/connection-string-spec.md Co-authored-by: Maxim Katcharov <[email protected]> * formatting --------- Co-authored-by: Jeff Yemin <[email protected]> Co-authored-by: Durran Jordan <[email protected]> Co-authored-by: Maxim Katcharov <[email protected]>
1 parent 71a9118 commit 2603c51

10 files changed

+87
-19
lines changed

source/auth/auth.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -1201,15 +1201,6 @@ in the MONGODB-OIDC specification, including sections or blocks that specificall
12011201

12021202
#### [MongoCredential](#mongocredential) Properties
12031203

1204-
> [!NOTE]
1205-
> Drivers MUST NOT url-decode the entire `authMechanismProperties` given in an connection string when the
1206-
> `authMechanism` is `MONGODB-OIDC`. This is because the `TOKEN_RESOURCE` itself will typically be a URL and may contain
1207-
> a `,` character. The values of the individual `authMechanismProperties` MUST still be url-decoded when given as part
1208-
> of the connection string, and MUST NOT be url-decoded when not given as part of the connection string, such as through
1209-
> a `MongoClient` or `Credential` property. Drivers MUST parse the `TOKEN_RESOURCE` by splitting only on the first `:`
1210-
> character. Drivers MUST document that users must url-encode `TOKEN_RESOURCE` when it is provided in the connection
1211-
> string and it contains and of the special characters in \[`,`, `+`, `&`, `%`\].
1212-
12131204
- username\
12141205
MAY be specified. Its meaning varies depending on the OIDC provider integration used.
12151206

@@ -1233,7 +1224,9 @@ in the MONGODB-OIDC specification, including sections or blocks that specificall
12331224
- TOKEN_RESOURCE\
12341225
The URI of the target resource. If `TOKEN_RESOURCE` is provided and `ENVIRONMENT` is not one of
12351226
`["azure", "gcp"]` or `TOKEN_RESOURCE` is not provided and `ENVIRONMENT` is one of `["azure", "gcp"]`, the driver
1236-
MUST raise an error.
1227+
MUST raise an error. Note: because the `TOKEN_RESOURCE` is often itself a URL, drivers MUST document that a
1228+
`TOKEN_RESOURCE` with a comma `,` must be given as a `MongoClient` configuration and not as part of the connection
1229+
string, and that the `TOKEN_RESOURCE` value can contain a colon `:` character.
12371230

12381231
- OIDC_CALLBACK\
12391232
An [OIDC Callback](#oidc-callback) that returns OIDC credentials. Drivers MAY allow the user to
@@ -2049,6 +2042,8 @@ to EC2 instance metadata in ECS, for security reasons, Amazon states it's best p
20492042

20502043
## Changelog
20512044

2045+
- 2024-05-29: Disallow comma character when `TOKEN_RESOURCE` is given in a connection string.
2046+
20522047
- 2024-05-03: Clarify timeout behavior for OIDC machine callback. Add `serverless:forbid` to OIDC unified tests. Add an
20532048
additional prose test for the behavior of `ALLOWED_HOSTS`.
20542049

source/auth/tests/legacy/connection-string.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/auth/tests/legacy/connection-string.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ tests:
435435
ENVIRONMENT: azure
436436
TOKEN_RESOURCE: 'mongodb://test-cluster'
437437
- description: should handle a complicated url-encoded TOKEN_RESOURCE (MONGODB-OIDC)
438-
uri: mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:abc%2Cd%25ef%3Ag%26hi
438+
uri: mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:abcd%25ef%3Ag%26hi
439439
valid: true
440440
credential:
441441
username: user
@@ -444,7 +444,7 @@ tests:
444444
mechanism: MONGODB-OIDC
445445
mechanism_properties:
446446
ENVIRONMENT: azure
447-
TOKEN_RESOURCE: 'abc,d%ef:g&hi'
447+
TOKEN_RESOURCE: 'abcd%ef:g&hi'
448448
- description: should url-encode a TOKEN_RESOURCE (MONGODB-OIDC)
449449
uri: mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:a$b
450450
valid: true

source/auth/tests/mongodb-oidc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ source the `secrets-export.sh` file and use the associated env variables in your
178178
- Assert that the callback was called 2 times.
179179
- Close the client.
180180

181-
\*\*4.3 Write Commands Fail If Reauthentication Fails
181+
#### 4.3 Write Commands Fail If Reauthentication Fails
182182

183183
- Create a `MongoClient` whose OIDC callback returns one good token and then bad tokens after the first call.
184184
- Perform an `insert` operation that succeeds.

source/connection-string/connection-string-spec.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,26 @@ The values in connection options MUST be URL decoded by the parser. The values c
216216
```
217217

218218
- Key value pairs: A value that represents one or more key and value pairs. Multiple key value pairs are delimited by a
219-
comma (","). The key is everything up to the first colon sign (":") and the value is everything afterwards. If any
220-
keys or values containing a comma (",") or a colon (":") they must be URL encoded. For example:
219+
comma (","). The key is everything up to the first colon sign (":") and the value is everything afterwards.
220+
221+
For example:
221222

222223
```
223224
?readPreferenceTags=dc:ny,rack:1
224225
```
225226

227+
Drivers MUST handle unencoded colon signs (":") within the value. For example, given the connection string:
228+
229+
```
230+
?authMechanismProperties=TOKEN_RESOURCE:mongodb://foo
231+
```
232+
233+
the driver MUST interpret the key as `TOKEN_RESOURCE` and the value as `mongodb://foo`.
234+
235+
For any option key-value pair that may contain a comma (such as `TOKEN_RESOURCE`), drivers MUST document that: a value
236+
containing a comma (",") MUST NOT be provided as part of the connection string. This prevents use of values that would
237+
interfere with parsing.
238+
226239
Any invalid Values for a given key MUST be ignored and MUST log a WARN level message. For example:
227240

228241
```
@@ -444,6 +457,8 @@ many languages treat strings as `x-www-form-urlencoded` data by default.
444457

445458
## Changelog
446459

460+
- 2024-05-29: Clarify handling of key-value pairs and add specification test.
461+
447462
- 2024-02-15: Migrated from reStructuredText to Markdown.
448463

449464
- 2016-07-22: In Port section, clarify that zero is not an acceptable port.

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

-2
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,3 @@ tests:
249249
hosts: ~
250250
auth: ~
251251
options: ~
252-
253-

source/connection-string/tests/valid-options.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/connection-string/tests/valid-options.yml

+14
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ tests:
2828
auth: ~
2929
options:
3030
tls: true
31+
-
32+
description: Colon in a key value pair
33+
uri: mongodb://example.com?authMechanismProperties=TOKEN_RESOURCE:mongodb://test-cluster
34+
valid: true
35+
warning: false
36+
hosts:
37+
-
38+
type: hostname
39+
host: example.com
40+
port: ~
41+
auth: ~
42+
options:
43+
authmechanismProperties:
44+
TOKEN_RESOURCE: 'mongodb://test-cluster'

source/connection-string/tests/valid-warnings.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/connection-string/tests/valid-warnings.yml

+12
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ tests:
7373
port: ~
7474
auth: ~
7575
options: ~
76+
-
77+
description: Comma in a key value pair causes a warning
78+
uri: mongodb://example.com?authMechanismProperties=TOKEN_RESOURCE:mongodb://host1%2Chost2
79+
valid: true
80+
warning: true
81+
hosts:
82+
-
83+
type: "hostname"
84+
host: "localhost"
85+
port: ~
86+
auth: ~
87+
options: ~

0 commit comments

Comments
 (0)