Skip to content

oauth2: percent-encode '+' in token request body parameters#43693

Open
garimauttam wants to merge 3 commits intoenvoyproxy:mainfrom
garimauttam:fix/oauth2-percent-encode-plus
Open

oauth2: percent-encode '+' in token request body parameters#43693
garimauttam wants to merge 3 commits intoenvoyproxy:mainfrom
garimauttam:fix/oauth2-percent-encode-plus

Conversation

@garimauttam
Copy link
Copy Markdown
Contributor

@garimauttam garimauttam commented Feb 28, 2026

PercentEncoding::encode in oauth_client.cc was missing + from its reserved charset (":/=&?"). In application/x-www-form-urlencoded, an unencoded + is interpreted as a space by the server — so OAuth2 credentials containing + (e.g. Azure AD / Entra ID client secrets) were silently mangled, resulting in 401 AADSTS7000215: Invalid client secret.

Why it matters

Base64-encoded secrets commonly contain +. This caused silent, hard-to-debug auth failures with no indication the secret was being corrupted in transit.

Change

  • ":/=&?"":/=&?+" across all 9 PercentEncoding::encode calls in asyncGetAccessToken and asyncRefreshAccessToken
  • Covers all auth types (UrlEncodedBody, BasicAuth, TlsClientAuth) and all parameters (client_id, client_secret, redirect_uri, code_verifier, refresh_token)

Tests

3 new unit tests in oauth_test.cc assert +%2B for client_secret, client_id, and refresh_token.

Fixes #43686

@garimauttam garimauttam changed the title oauth2: percent-encode '+' in token request body parameters oauth2: Percent-encode '+' in token request body parameters Feb 28, 2026
@garimauttam garimauttam force-pushed the fix/oauth2-percent-encode-plus branch from 2eceec0 to 73530d2 Compare February 28, 2026 14:56
@garimauttam garimauttam changed the title oauth2: Percent-encode '+' in token request body parameters oauth2: percent-encode '+' in token request body parameters Feb 28, 2026
@agrawroh agrawroh assigned zhaohuabing and wbpcode and unassigned mattklein123 Mar 10, 2026
@agrawroh
Copy link
Copy Markdown
Member

cc @zhaohuabing @wbpcode for a review.

@zhaohuabing
Copy link
Copy Markdown
Member

Hi @garimauttam thanks for fixing this! Since the reserved character set appears in multiple places, would it make sense to define it as a constant and reuse it throughout?

@garimauttam garimauttam force-pushed the fix/oauth2-percent-encode-plus branch from 5ce7d5a to 3fc2517 Compare March 18, 2026 11:44
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 20, 2026

gently ping @zhaohuabing

@zhaohuabing
Copy link
Copy Markdown
Member

Hi @garimauttam Could you please fix the format?

https://github.com/envoyproxy/envoy/actions/runs/23315013831/job/67812067258

@rubenceroni
Copy link
Copy Markdown

Hi @garimauttam are you still working on this? can i help get this merged?

Signed-off-by: garima-uttam <garimauttam@ibm.com>
Signed-off-by: garima-uttam <garimauttam@ibm.com>
Signed-off-by: garima-uttam <garimauttam@ibm.com>
@garimauttam garimauttam force-pushed the fix/oauth2-percent-encode-plus branch from 0bf23ab to 5163df4 Compare April 2, 2026 09:32
@garimauttam
Copy link
Copy Markdown
Contributor Author

Hi @garimauttam are you still working on this? can i help get this merged?

@rubenceroni thanks. I’ve fixed the format failure. I’d really appreciate a quick review to help get this merged.

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.

OAuth2 filter: + in client_secret not percent-encoded in token request body

6 participants