fix: correct JSON serialization and error handling in VaultHttp#10
Open
spbsoluble wants to merge 6 commits intorelease-1.0from
Open
fix: correct JSON serialization and error handling in VaultHttp#10spbsoluble wants to merge 6 commits intorelease-1.0from
spbsoluble wants to merge 6 commits intorelease-1.0from
Conversation
Merge 1.0.0 to main
AddJsonBody(string) in RestSharp re-serializes the argument, wrapping a pre-serialized JSON string in quotes and escaping it. Vault receives a JSON string literal instead of a JSON object and returns HTTP 400. Fixed by using AddStringBody(string, ContentType.Json) which sends the raw body without re-encoding. ThrowOnAnyError = true caused RestSharp to throw before the explicit BadRequest handler ran, hiding the Vault error body from logs. Removed ThrowOnAnyError and added response.ThrowIfError() after the BadRequest block so all other non-2xx responses still surface as exceptions. Also drops the EOL net6.0 target; project now multi-targets net8.0 and net10.0.
…nd ValidateProductInfo Direct Dictionary.get_Item calls throw KeyNotFoundException when the gateway does not populate all parameter keys before calling validation (observed on PUT/POST config/configuration). Replace with TryGetValue throughout. Also relaxes the ValidateProductInfo RoleName check: RoleName is optional since the Enroll path already falls back to ProductID when RoleName is absent, so the validator no longer rejects configs that omit it.
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
Fixes two bugs in
VaultHttpthat together prevented certificate enrollment from succeeding when the gateway called into Vault/OpenBao.Bug 1:
AddJsonBody(string)double-encodes pre-serialized JSON → HTTP 400PostAsyncserialized the request body to a JSON string withJsonSerializer.Serialize, then passed that string torequest.AddJsonBody(). In RestSharp ≥ 106,AddJsonBodyre-serializes whatever object it receives. When the argument is already astring, RestSharp encodes it as a JSON string literal — wrapping the content in quotes and escaping the inner characters.Vault/OpenBao received
"{\"csr\":\"...\"}"(a JSON-encoded string) instead of{"csr":"..."}(a JSON object) and returned HTTP 400 "error parsing JSON".Fix: Replaced
request.AddJsonBody(serializedParams)withrequest.AddStringBody(serializedParams, ContentType.Json).AddStringBodytreats its first argument as the raw body and does not re-serialize it.Bug 2:
ThrowOnAnyError = truemade theBadRequesterror-parsing block dead codeRestClientOptionswas constructed withThrowOnAnyError = true. This causes RestSharp to throw an exception on any non-2xx response before returning to the caller.PostAsynchad explicit handling forHttpStatusCode.BadRequestthat deserialized the Vault error list and produced a descriptive exception message — but that block was unreachable because RestSharp always threw first, and the actual Vault error body was swallowed.Fix: Removed
ThrowOnAnyError = truefromRestClientOptions. Addedresponse.ThrowIfError()after the explicitBadRequesthandler so that non-2xx responses that are notBadRequeststill surface as exceptions, whileBadRequestresponses go through the Vault error-body parsing path.Multi-target: dropped EOL net6.0, added net8.0 and net10.0
The project previously targeted
net6.0, which reached end-of-life in November 2024. Updated to multi-targetnet8.0(LTS) andnet10.0(current).AppendTargetFrameworkToOutputPath=Falseis preserved from the original project configuration.How to reproduce Bug 1
Test plan
net8.0andnet10.0— both should compile cleanly