-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix OAuth1 double-encoding of RFC 3986 special characters in URL paths #2341
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
Conversation
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Deploying restsharp with
|
| Latest commit: |
fa6c0d4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://03763a0e.restsharp.pages.dev |
| Branch Preview URL: | https://copilot-fix-oauth1-auth-erro.restsharp.pages.dev |
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
User description
OAuth1 signature calculation was double-encoding special characters (!, *, ', (, )) in URL paths, causing 401 authentication failures. When URL segments containing these characters were added via
AddUrlSegment(), they were encoded byUri.EscapeDataString()during URL construction, then encoded again during signature base generation.Changes
OAuthTools.ConstructRequestUrl: Decodeurl.AbsolutePathwithUri.UnescapeDataString()before returning. This prevents double-encoding sinceUrlEncodeRelaxedwill encode the decoded path once correctly.Tests: Added coverage for RFC 3986 special characters in both direct paths and URL segment parameters to verify single encoding.
Example
The fix applies to all RFC 3986 special characters:
!,*,',(,).Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
PR Type
Bug fix
Description
Fix OAuth1 double-encoding of RFC 3986 special characters in URL paths
Decode path before signature calculation to prevent double-encoding
Add comprehensive test coverage for special characters in paths
Ensure single encoding of characters like !, *, ', (, )
Diagram Walkthrough
File Walkthrough
OAuthTools.cs
Decode path to prevent double-encoding in OAuth1src/RestSharp/Authenticators/OAuth/OAuthTools.cs
url.AbsolutePathusingUri.UnescapeDataString()inConstructRequestUrlmethodcharacters
UrlEncodeRelaxedbefore useOAuth1SignatureTests.cs
Add tests for RFC 3986 special characters in pathstest/RestSharp.Tests/Auth/OAuth1SignatureTests.cs
(, ))
double-encoding
%25 (double-encoded %)