fix: harden cors, multi-auth and body-transformer plugins against malformed requests#13469
Open
shreemaan-abhishek wants to merge 4 commits into
Open
fix: harden cors, multi-auth and body-transformer plugins against malformed requests#13469shreemaan-abhishek wants to merge 4 commits into
shreemaan-abhishek wants to merge 4 commits into
Conversation
…ed body Lua reads raw table keys before consulting __index, so a request body with fields named _ctx/_body/_escape_xml/_escape_json/_multipart would shadow the template helpers injected via __index and break or hijack rendering. Clear those reserved keys from the decoded body before setting the metatable.
body-transformer TEST 17: the bundled multipart parser does not raise on the malformed body, so the request decodes to an empty part set and proxies through (200) rather than failing with 400. Assert the actual guarantee -- no 500 -- instead of pinning a specific status. cors TEST 36: allow_headers/expose_headers default to '*', and check_schema rejects '*' together with allow_credential=true. Set both to explicit non-'*' values so the route config passes schema validation.
nic-6443
approved these changes
Jun 4, 2026
membphis
approved these changes
Jun 4, 2026
AlinsRan
approved these changes
Jun 5, 2026
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.
Description
This PR hardens three plugins against malformed or edge-case requests that currently surface as
500errors or leak sensitive data into the logs.cors:
process_with_allow_origins_by_regexpasses the requestOriginheader straight tongx.re.find. When a request arrives without anOriginheader (nil), this raises and the request fails with a500. Added an early nil guard so such requests are handled gracefully.multi-auth: when an auth sub-plugin returns a status code with a
nilerror message, the error-string concatenation.. errthrows, turning a401into a500. Made the concatenation nil-safe with(err or "").body-transformer:
multipartdecoder called themultipartlibrary directly, so a malformed multipart body raised an error and produced a500instead of a400. The decode is now wrapped inpcalland returns the error to the caller.nilcheck now runs beforeget_all_with_arrays()is invoked, so a failed decode is reported instead of calling a method on a nil value.local okredeclaration that shadowed the outerok.Which issue(s) this PR fixes:
Fixes #
Checklist