Skip to content

fix(router): preserve rewrite-phase query argument changes during servlet URI normalizationΒ #13983

Description

@membphis

Background

#13982 fixes query-string loss when apisix.normalize_uri_like_servlet is enabled by appending the current $is_args$args value to $upstream_uri.

Problem

$upstream_uri is materialized before route rewrite and access plugins run. Some plugins modify the live request arguments later. For example, key-auth and jwt-auth remove a query credential through ngx.req.set_uri_args() when hide_credentials is enabled.

Because $upstream_uri already contains a copy of the earlier query string, those later argument changes are not reflected in the URI sent upstream.

Example:

Incoming request: /echo?auth=secret&foo=1
Early upstream_uri: /echo?auth=secret&foo=1
Arguments after key-auth: foo=1
URI sent upstream: /echo?auth=secret&foo=1
Expected upstream URI: /echo?foo=1

The same ordering can affect other plugins that modify request arguments after servlet URI normalization.

Expected behavior

Servlet-style path normalization should preserve the path parameters while the final upstream URI observes query argument changes made by rewrite or access plugins. A plugin that explicitly sets $upstream_uri should continue to take precedence.

Suggested direction

Keep the servlet path separately, then serialize the current $is_args$args value after the relevant plugin phases have completed. Do not overwrite an $upstream_uri explicitly set by a plugin.

Add a regression test covering:

  • apisix.normalize_uri_like_servlet: true
  • query-based key-auth or jwt-auth
  • hide_credentials: true
  • an unrelated query argument that must still reach the upstream

Related

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions