Skip to content

feat(plugin): error-page: support 403 and Nginx variables in body#13741

Open
baiuu wants to merge 2 commits into
apache:masterfrom
baiuu:feat-error-page
Open

feat(plugin): error-page: support 403 and Nginx variables in body#13741
baiuu wants to merge 2 commits into
apache:masterfrom
baiuu:feat-error-page

Conversation

@baiuu

@baiuu baiuu commented Jul 23, 2026

Copy link
Copy Markdown

Description

Fixes #13742

Description

Two enhancements to the error-page plugin:

1. Support custom error pages for 403 responses

  • metadata_schema: add error_403 (same structure as 404/500/502/503)
  • get_metadata: lower status threshold from < 404 to < 400
  • Behavior for unconfigured status codes is unchanged (lookup is still per error_<status> key)

2. Support Nginx variables in the error page body

  • Resolve variables in header_filter via core.utils.resolve_var (same semantics as response-rewrite headers: $var, ${var}, ?? default values, \$ escaping)
  • The rendered body is cached in ctx and emitted by body_filter
  • Content-Length is set from the rendered body to avoid truncation or stalls
  • Fail-open: on resolution error the original body is used and a warning is logged
  • Bodies without $ short-circuit before regex processing — no overhead for existing configurations

Motivation: allow operators to serve unified custom error pages for auth rejections (403) and embed the request ID ($apisix_request_id) so users can report it and admins can correlate the page with logs.

Checklist

  • New feature (non-breaking change which adds functionality)
  • Added test cases in t/plugin/error-page.t:
    • TEST 21–24: custom 403 page via metadata; plugin-injected 403 (fault-injection) is intercepted
    • TEST 25–30: variable resolution ($var, ${var}), ?? default value, \$ escaping
  • Updated documentation (EN + ZH)
  • CI passed

Acknowledgement

This change was developed with the assistance of Kimi K3 (Moonshot AI) — including implementation, test cases, and documentation.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 23, 2026
@baiuu baiuu changed the title feat(plugin): support Nginx variables in error-page body feat(plugin): error-page: support 403 and Nginx variables in body Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(plugin): error-page: support 403 and Nginx variables in body

1 participant