feat(forward-auth): support attaching consumer by response header#13268
Open
panxiaoquan wants to merge 1 commit intoapache:masterfrom
Open
feat(forward-auth): support attaching consumer by response header#13268panxiaoquan wants to merge 1 commit intoapache:masterfrom
panxiaoquan wants to merge 1 commit intoapache:masterfrom
Conversation
2dd4fe9 to
7721b19
Compare
Baoyuantop
reviewed
Apr 22, 2026
| -- if header_value is nil, the client header's value will be removed if it exists | ||
| core.request.set_header(ctx, header, header_value) | ||
| if header_value then | ||
| core.request.set_header(ctx, header, header_value) |
Contributor
There was a problem hiding this comment.
upstream_headers security regression: The original code intentionally clears client-supplied headers when the auth response does not include a configured upstream header (prevents header spoofing). The new if header_value then guard in the loop breaks this behavior — a malicious client can now inject headers that the upstream trusts (e.g., X-User-Id). Please revert to the original unconditional set_header logic.
703c48c to
a307236
Compare
a307236 to
cbc1c12
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.
Description
This PR extends the
forward-authplugin to support attaching an existing APISIX Consumer from asuccessful authorization response header.
Today,
forward-authcan forward request headers to the auth service and propagate selected responseheaders back to the upstream or client, but it cannot turn a successful auth response into APISIX
Consumer context. That means Consumer-scoped plugins and Consumer Group plugins cannot participate in
requests authenticated by an external auth service.
This change adds an opt-in
consumer_headerattribute toforward-auth. When it is configured and theauth service returns a
2xxresponse, APISIX reads the configured response header as a Consumerusername, looks up the existing Consumer locally, and attaches it to the current request. This allows
downstream Consumer-related plugins to work with
forward-auth-authenticated traffic.The implementation also moves the auth execution into
rewriteand usesctx.forward_auth_processedtoavoid running the auth flow twice in
access. This keeps the request authenticated once while making theattached Consumer available early enough for Consumer plugins to take effect.
Behavior on invalid auth-to-consumer mapping is explicit:
403.403.Additional changes included in this PR:
apisix.consumerto fetch an existing Consumer by name from local cache.consumer_headerattribute and example usage.plugins after attachment, missing header, and unknown Consumer.
.luarc.jsonworkspace config to improve local LuaLS path/global resolution for development.Checklist
mailing list first)