Skip to content

lua: add base64Decode() to the stream handle - #46887

Draft
derekargueta wants to merge 2 commits into
envoyproxy:mainfrom
derekargueta:dargueta-lua-base64-decode
Draft

lua: add base64Decode() to the stream handle#46887
derekargueta wants to merge 2 commits into
envoyproxy:mainfrom
derekargueta:dargueta-lua-base64-decode

Conversation

@derekargueta

@derekargueta derekargueta commented Aug 22, 2026

Copy link
Copy Markdown
Member

Commit Message: lua: add base64Decode() to the stream handle

Additional Description:

The HTTP Lua filter has offered base64Escape() but never a decode counterpart, so a script receiving a base64 value — an encoded header claim, a protojson bytes field — has to hand-roll a decoder or depend on a C module that is not in every build. This adds the missing half.

base64Decode() returns nil on malformed input rather than raising. Raising is defensible, but a Lua error skips the filter entirely (StreamHandleWrapper::start() returns Continue on a not-ok coroutine), which for an admission-style script silently turns a deny into an allow. Returning nil lets the script decide.

Behaviour follows absl::Base64Unescape: whitespace is skipped, padding is optional but must be correct if present, and . is accepted alongside =.

Risk Level: low

Testing: unit test covering a known vector, a round trip through base64Escape(), embedded NUL bytes, the empty string decoding to itself rather than nil, and invalid-length and invalid-alphabet inputs returning nil. No integration test, matching base64Escape().

Docs Changes: added a base64Decode() entry to the Lua filter docs, with an example checking the result.

Release Notes: added.

Platform Specific Features: N/A

On the name: base64Encode() does not exist and I would rather not add it as an alias. base64Decode is what #46873 asked for, and Envoy's user-facing vocabulary already leans on encode/decode rather than absl's escape/unescape. Happy to rename to base64Unescape if maintainers prefer.

Fixes #46873

Commit Message: lua: add base64Decode() to the stream handle
Additional Description:
The HTTP Lua filter has offered base64Escape() since envoyproxy#21764 but never a decode
counterpart, so a script receiving a base64 value -- a header carrying an
encoded claim, an upstream body field that protojson encoded as bytes -- had to
either hand-roll a decoder in Lua or reach for a C module that is not present in
every Envoy build.

base64Decode() returns nil on malformed input rather than raising, so a value
that arrived over the wire can be checked instead of trusted. Raising would be
awkward here: the common sources are all attacker-influenced, and a Lua error
means the filter is skipped entirely, which for an admission-style script turns
a deny into an allow.

Risk Level: low
Testing: unit test covering a known vector, a round trip through
base64Escape(), embedded NUL bytes, the empty string, and both invalid-length
and invalid-alphabet inputs.
Docs Changes: added a base64Decode() entry to the Lua filter docs.
Release Notes: added.
Platform Specific Features: N/A
Fixes envoyproxy#46873

Signed-off-by: Derek Argueta <derek.argueta@airbnb.com>
@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #46887 was opened by derekargueta.

see: more, trace.

Picks up test certificate regeneration (envoyproxy#46889); the branch predated it and
every TLS cert-validation test was failing as a result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lua: add base64Decode() to HTTP Lua filter

1 participant