fix: interpolate variables in pre-serialized form-urlencoded string bodies - #96
Open
MartinYanickGuillemette wants to merge 1 commit into
Conversation
…odies
The send-http-request handler serializes form-urlencoded bodies to a string (qs.stringify) before script execution for @usebruno/js compatibility. interpolateVars only handled array-format form bodies, so string bodies passed through uninterpolated and the literal {{variable}} text (percent-encoded) was sent to the server.
Fixes usebruno#73
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.
Problem
Variables in
application/x-www-form-urlencodedrequest bodies are not interpolated — the literal{{variable}}text (percent-encoded as%7B%7Bvariable%7D%7D) is sent to the server.Fixes #73
Reproduction
{{anyVariable}}(environment var, runtime var,{{process.env.X}}, or even a plain collection var){{anyVariable}}stringVerified with a local echo server: the extension (
bruno-runtime/1.0) sendsclient_secret={{ClientSecret}}literally, while the desktop app (bruno-runtime/3.5.3) interpolates correctly. Real-world impact: Azure AD OAuth2 token requests fail withAADSTS7000215: Invalid client secret provided.Root cause
The
send-http-requesthandler serializes form-urlencoded bodies to a string (qs.stringify/buildFormUrlEncodedPayload) before script execution, for@usebruno/jsBrunoRequestcompatibility.By the time
executeRequestcallsinterpolateVars, the form body is a string — but the form-urlencoded branch ininterpolate-vars.tsonly handles array data:So the stringified body passes through uninterpolated.
Fix
When the form-urlencoded body is a string containing
{{or%7B%7B(braces are percent-encoded byqs.stringify), parse it withURLSearchParams, interpolate each name/value pair, and re-serialize. Bodies without variable placeholders are left untouched.Testing
interpolate-vars.spec.tswith 5 tests: array bodies, pre-serialized string bodies (encoded + unencoded braces),process.envvariables, and passthrough of bodies without variablesnode esbuild.extension.mjsbuild succeeds