Repository navigation
fix(csharp): encode httpclient query parameters once without changing RestSharp - #25730
Open
nagabalaji-b wants to merge 28 commits into
Open
nagabalaji-b wants to merge 28 commits into
nagabalaji-b wants to merge 28 commits into
Conversation
…oding on .NET 9+ On .NET 9+, HttpUtility.ParseQueryString() already URL-encodes values internally. The previous fix only checked for '.NET 9' literally, missing .NET 10+ (PowerShell 7.6). Replace the string prefix check with a numeric major version comparison (>= 9) and move the RuntimeInformation check outside the foreach loop to avoid redundant parsing. Fixes: CSCwu08056
fix(csharp): numeric .NET version check to prevent double URL-encoding on .NET 9+ (CSCwu08056)
This reverts commit 6ef74e7.
This reverts commit 5e4b895.
…convention
CI's samples job runs bin/generate-samples.sh twice. On the second pass the generator skips idempotent files (.openapi-generator-ignore and Test/{Api,Model}/*Tests.cs already on disk), so they are omitted from the FILES manifest. Other generichost samples (e.g. ComposedEnum) follow this convention; AnnotatedEnum's FILES was previously committed after a single regen and included 17 stale entries. Regenerated to match CI output.
…aster # Conflicts: # modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/.openapi-generator/FILES # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/.openapi-generator/VERSION # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/api/openapi.yaml # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools.Test/Api/ApiTestsBase.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools.Test/Api/DependencyInjectionTests.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Api/DefaultApi.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Client/HostConfiguration.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Extensions/IHostBuilderExtensions.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Extensions/IServiceCollectionExtensions.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/Number.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/Number2.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/OneOfNullAndRef.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/OneOfNullAndRef2.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/OneOfNullAndRef3.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/Parent.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/ParentWithOneOfProperty.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/SingleAnyOfTest.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/Model/TypeIntegerWithOneOf.cs # samples/client/petstore/csharp/generichost/latest/AnnotatedEnum/src/Org.OpenAPITools/README.md
Syncing openapitools-master with upstream master
… RestSharp Co-authored-by: Cursor <cursoragent@cursor.com>
… RestSharp Regenerate httpclient C# samples (net9, net10, standard2.0, and Petstore-nonPublicApi) so query parameters are encoded once in WebRequestPathBuilder and the request signature matches the sent URL. RestSharp and Unity Web Request samples are unchanged.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
- Build the httpclient query from individual key=value pairs instead of HttpUtility.ParseQueryString, which is case-insensitive and merged keys that differ only by case (e.g. "tag" and "Tag"). - Use the same query string for the HTTP signature and the request URL, so -prefixed and multi-value parameters are no longer double-encoded or signed differently from what is sent. - RestSharp, Unity, and generic host output is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The httpclient C# library encoded query parameters in two different ways. The request URL wrote keys raw and values with
Uri.EscapeDataString, while the HTTP Signature was computed over a query built withHttpUtility.ParseQueryStringandUrlEncode. For keys containing$(for example$filter), the signed(request-target)did not match the URL that was sent, so signed requests failed verification.This PR makes httpclient encode each query parameter once, in both the request URL and the signature, and leaves RestSharp and Unity Web Request output unchanged.
Changes
modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache_skipUrlEncodefield, its constructor assignment, its comments, and the#if (NETCOREAPP)query loop are wrapped in{{^useHttpClient}}. Output for RestSharp is unchanged.{{#useHttpClient}}branch: builds the query withHttpUtility.ParseQueryString(string.Empty)on raw keys, keeps[]for multi-value parameters, and applies.Replace("+", "%20").Replace("%24", "$"). It does not callHttpUtility.UrlEncode.modules/openapi-generator/src/main/resources/csharp/WebRequestPathBuilder.mustacheusing System.Web;is emitted only for httpclient.AddQueryParametersbuilds the query the same way (raw keys, repeated keys without[]), andGetFullUrireturnsnew UriBuilder(_baseUrl + _path) { Query = _query }.Uri.AbsoluteUri.Uri.EscapeDataStringcode.Uri.EscapeDataString.samples/client/petstore/csharp/httpclient/{net9,net10,standard2.0}/Petstore/...(HttpSigningConfiguration.cs,WebRequestPathBuilder.cs)samples/client/petstore/csharp/httpclient/{net9,net10}/Petstore-nonPublicApi/...(WebRequestPathBuilder.cs)No generic host,
ApiClient.mustache, RestSharp, or Unity samples changed.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Fixes the httpclient C# generator so query parameters are encoded once, making the HTTP signature match the URL that is actually sent. Previously, keys containing
$(for example OData's$filter) were encoded differently in the signature than in the request URL, so signed requests failed verification.(request-target)are now built from the same query string of individual key=value pairs, with+/%24normalized and no second encoding pass.HttpUtility.ParseQueryStringavoids its case-insensitive behavior merging keys such astagandTag._skipUrlEncodeworkaround and the[]suffix for multi-value parameters are now RestSharp-only; RestSharp and Unity Web Request output are unchanged, and path parameters still useUri.EscapeDataString.Written for commit 5c20477. Summary will update on new commits.