Skip to content

Percent-encode client_secret_basic credentials (RFC 6749 §2.3.1) - #300

Merged
andreyvelich merged 2 commits into
modelcontextprotocol:mainfrom
varun06:client-secret-basic-encoding
Oct 21, 2026
Merged

andreyvelich merged 2 commits into
modelcontextprotocol:mainfrom
varun06:client-secret-basic-encoding

Conversation

@varun06

@varun06 varun06 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

RFC 6749 §2.3.1 requires the client identifier and secret to be encoded with
application/x-www-form-urlencoded before being joined with : and Base64-encoded for
HTTP Basic. They were used verbatim, so secrets containing :, @, %, +, or
non-ASCII characters produced headers that authorization servers decode to the wrong
credentials (a : in the client ID even moves the user/password split).

Both values are now percent-encoded, leaving only RFC 3986 unreserved characters as-is.

How Has This Been Tested?

New OAuthClientSecretBasicTests covering unreserved passthrough, reserved characters,
the : boundary case, and UTF-8 secrets. The encoding tests fail without the fix.
swift test passes.

Breaking Changes

Credentials made only of unreserved characters are unchanged. Credentials with reserved
characters now produce the spec-compliant header.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

alexbull and others added 2 commits October 21, 2026 14:15
RFC 6749 section 2.3.1 requires encoding the client_id and
client_secret with application/x-www-form-urlencoded before forming
the Basic auth header. Credentials containing ':', '@', '%', '+', or
non-ASCII characters were previously included verbatim, which could
produce a header that authorization servers decode to the wrong
credentials.
Covers unreserved passthrough, reserved characters (: @ % + / =), a colon in the client ID not shifting the user/password boundary, and UTF-8 encoding of non-ASCII secrets.
@varun06
varun06 force-pushed the client-secret-basic-encoding branch from 37c42f0 to f2ca733 Compare October 21, 2026 19:17

@andreyvelich andreyvelich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @varun06!

@andreyvelich
andreyvelich merged commit 85078bf into modelcontextprotocol:main Oct 21, 2026
11 of 12 checks passed
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.

3 participants