Add body injection support for Vanta token revocation#38
Merged
Conversation
Implemented InjectBodyProcessor and OAuthBodyProcessor to support delimiter-based token replacement in request bodies. This enables Vanta's suspend API to receive the unsealed OAuth token in the request body without exposing it in the ui-ex application. Features: - ParamDelimiter support for specifying custom placeholders - InjectBodyProcessorConfig for generic body injection - OAuthBodyProcessorConfig for OAuth-specific body injection - Automatic Content-Length header updates after replacement Required for Vanta integration disconnect flow in ui-ex.
timflyio
reviewed
Dec 4, 2025
timflyio
reviewed
Dec 4, 2025
Addressing PR review feedback: - Rename 'delimiter' to 'placeholder' throughout codebase for clarity - Use github.com/icholy/replace for streaming replacement instead of io.ReadAll - Prevents memory exhaustion on large request bodies - Add comprehensive test cases for body injection processors Changes: - Update ParamDelimiter constant to ParamPlaceholder - Convert InjectBodyProcessorConfig to use streaming replace.Chain() - Convert OAuthProcessorConfig body injection to use streaming - Convert OAuthBodyProcessorConfig to use streaming - Add dependency on github.com/icholy/replace v0.6.0 - Add test coverage for: - Simple and multiple placeholder replacements - Custom placeholders from params and config - Large bodies (50KB+) with streaming - OAuth access and refresh tokens - Nil/empty bodies
Enhance test coverage to verify mutual exclusivity of header and body injection: - Body injection: verify Authorization header is NOT set - Header injection: verify body is NOT modified This ensures the dual-mode behavior of OAuthProcessorConfig works correctly: - With placeholder param → only body is modified - Without placeholder param → only Authorization header is set
timflyio
reviewed
Dec 4, 2025
processor.go
Outdated
| chain := replace.Chain(r.Body, replace.String(placeholder, c.Token)) | ||
|
|
||
| // Buffer the replaced content to calculate Content-Length | ||
| var buf bytes.Buffer |
Contributor
There was a problem hiding this comment.
hrm.. we still are reading the whole thing into memory (into buf) to get the content length. I think you can set the r.ContentLength to zero and r.Body to the replacement chain, and it should be able to stream the body using chunked encoding without knowing the content length ahead of time.
Contributor
Author
There was a problem hiding this comment.
Changed to use the 0 contentlength and r.Body = io.NopCloser(chain)
Contributor
There was a problem hiding this comment.
this should do it I think, though I would try it out just to make sure. since this shouldnt break any existing use cases you can test it after deploying.
timflyio
reviewed
Dec 4, 2025
Switch from buffering entire request bodies to using chunked transfer encoding (ContentLength = 0) when performing token replacement. This eliminates memory overhead for large request bodies by streaming through the replace.Chain without needing to calculate content length upfront. Updated processors: - InjectBodyProcessorConfig.Processor() - OAuthBodyProcessorConfig.Processor() - OAuthProcessorConfig.Processor() (when placeholder provided) Removed unused MaxBodySizeForInjection constant.
e3f6b47 to
ceaca72
Compare
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.
Implemented InjectBodyProcessor and OAuthBodyProcessor to support delimiter-based token replacement in request bodies. This enables Vanta's suspend API to receive the unsealed OAuth token in the request body without exposing it in the ui-ex application. Required for Vanta integration disconnect flow in ui-ex (ref: https://developer.vanta.com/docs/oauth-flow#disconnecting-integrations-via-the-suspend-api)