Skip to content

fix(ai-aliyun-content-moderation): return nil instead of ngx.OK in lua_body_filter#13623

Open
janiussyafiq wants to merge 1 commit into
apache:masterfrom
janiussyafiq:fix/13620-aliyun-final-packet-nonterminal
Open

fix(ai-aliyun-content-moderation): return nil instead of ngx.OK in lua_body_filter#13623
janiussyafiq wants to merge 1 commit into
apache:masterfrom
janiussyafiq:fix/13620-aliyun-final-packet-nonterminal

Conversation

@janiussyafiq

Copy link
Copy Markdown
Contributor

Description

ai-aliyun-content-moderation's lua_body_filter returned ngx.OK on the streaming final_packet path. In apisix/plugin.lua's lua_response_filter, returning a non-nil code prints the body and ngx.exits the whole response filter chain, so any lower-priority response body filter is skipped.

Because ai-aliyun-content-moderation (priority 1029) runs before ai-lakera-guard (priority 1028), a route chaining both terminated the chain before ai-lakera-guard's output scan ran — even though final_packet only annotates risk_level and never blocks. The result was a silent moderation gap: a streamed response that ai-lakera-guard would block could leak through unscanned.

This returns nil (transform-and-continue) instead of ngx.OK on the final_packet path, so the chain keeps running lower-priority response body filters. The paths that genuinely terminate the response (realtime block) still return a code and are unchanged.

A combined-plugin streaming test (t/plugin/ai-lakera-guard-chain.t) is added: it asserts ai-lakera-guard's output scan still runs and blocks a flagged stream when chained after ai-aliyun-content-moderation, and that a clean stream still passes through the chain.

Which issue(s) this PR fixes:

Fixes #13620

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 29, 2026

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review looks good to me. Please make sure CI is green before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ai-lakera-guard streaming output scanning skipped when chained after a higher-priority response-filter plugin

4 participants