ruanweihong-aaa commented on code in PR #13800:
URL: https://github.com/apache/apisix/pull/13800#discussion_r3755210163


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -225,6 +247,14 @@ function _M.check_schema(conf)
             if not secret.is_secret_ref(pattern) then
                 local test_replacement = secret.is_secret_ref(replacement)
                                          and "" or replacement
+                if test_replacement ~= "" then
+                    local err
+                    test_replacement, err = escape_nginx_vars(test_replacement)
+                    if err then
+                        return false, "invalid regex_uri replacement(" ..
+                            replacement .. "): " .. err
+                    end
+                end

Review Comment:
   This is needed because `check_schema` compiles the replacement with 
`ngx.re.sub` to validate both the regex pattern and replacement syntax.
   
   Without escaping NGINX variables, `$arg_name` is interpreted as a named PCRE 
capture and route creation fails with "failed to compile the replacement 
template", which is the original issue.
   
   Escaping only NGINX variable markers as `$$` allows PCRE to keep validating 
regular captures such as `$1` and invalid replacement syntax, while treating 
`$arg_name` as a literal during schema validation. The existing invalid 
replacement test also depends on this validation.
   
   I can add a comment here to explain this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to