Skip to content

CDRIVER-5580 treat commas in TOKEN_RESOURCE as a client error #1950

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

Merged
merged 8 commits into from
Mar 28, 2025
6 changes: 3 additions & 3 deletions src/libmongoc/doc/mongoc_uri_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Mechanism Properties

The following properties may be specified as key-value pairs for the ``MONGOC_URI_AUTHMECHANISMPROPERTIES`` option.

These properties may only be specified when the corresponding authentication mechanism is also specified.
Invalid or unsupported properties may be reported as a client error when a corresponding authentication mechanism is also specified.

MONGODB-OIDC
^^^^^^^^^^^^
Expand All @@ -147,8 +147,8 @@ TOKEN_RESOURCE The URI of the target resource. ``ENVIRONMENT`` must be one of ["

.. warning::

The value of the ``TOKEN_RESOURCE`` property MUST NOT contain the comma character "," when specified as a connection string query option.
Any commas in the value MUST be percent-encoded (as "%2C") to avoid being interpreted as a key-value pair delimiter.
A ``TOKEN_RESOURCE`` property value MUST NOT contain the comma character "," when specified as a connection string query option, even when percent-encoded.
A value containing a comma character may be set using :symbol:`mongoc_uri_set_mechanism_properties()` instead.
However, the value MAY contain the colon character ":", as only the first colon is interpreted as a key-value delimiter.

GSSAPI
Expand Down
7 changes: 7 additions & 0 deletions src/libmongoc/tests/test-mongoc-connection-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ run_uri_test (const char *uri_string,
if (strstr (uri_string, "CANONICALIZE_HOST_NAME:none") || strstr (uri_string, "CANONICALIZE_HOST_NAME:forward")) {
return;
}

// CDRIVER-5580: commas in TOKEN_RESOURCE are interpreted as a key-value pair delimiter which produces an invalid
// mechanism property that is diagnosed as a client error instead of a warning.
if (strstr (uri_string, "TOKEN_RESOURCE:mongodb://host1%2Chost2")) {
MONGOC_WARNING ("percent-encoded commas in TOKEN_RESOURCE");
return;
}
}

if (uri) {
Expand Down