Repository navigation
fix(preprocess): JSON objects in calls outside a variable stay text (VTL templates) - #82
Merged
Merged
Conversation
…VTL #set($m = {...}))
encodeJsonArgObjects encoded every name(... {json} ...) in a string, but decoding only
happens when a variable resolves. A JSON object in a call outside any variable — an API
Gateway VTL template's #set($mfaMap = { "SMS_MFA": "SMS" }) — became
__JSON_B64__...__ in the resolved config. Now only calls inside a ${...} are encoded
(brace-aware depth scan, so ${merge({"a":1})} still counts).
Tests: encodeJsonArgObjects unit cases; serverlessGoldens apigw-vtl fixture (its leak
check failed before the fix). Golden harness can keep backslashes so \n and \" in config
values are compared exactly; BuildSpec goldens regenerated (backslashes only).
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.
Bug
In an API Gateway VTL mapping template like this:
the object resolved to
#set($mfaMap = __JSON_B64__…__), which shipped a broken template. Present in 1.4.1 through 1.4.8. The golden suite's leak detector (#81) catches it.Cause
encodeJsonArgObjects(preprocess) encodes a JSON object passed as a call argument, so that its{ }don't break variable matching. It ran on everyname(… {…} …)in a string, but the decode only happens when a variable resolves. A call outside any variable was encoded and never decoded.Fix
Only calls inside a
${…}are encoded. The newisInsideVariableis a brace-aware depth scan: inside a variable every{/}counts, so${merge({"a":1})}still qualifies.Tests
encodeJsonArgObjectsunit cases: a VTL#setstays text, and when both appear only the in-variable call is encoded.serverlessGoldensfixtureapigw-vtl: a realistic request/response template underFn::If. It failed with the leak before the fix.keepBackslashes), so\nand\"in config values are compared exactly rather than folded to/. The BuildSpec goldens were regenerated; the diff is backslashes only.