klT45 opened a new issue, #7873:
URL: https://github.com/apache/shenyu/issues/7873
### Current Behavior
Since #7854 a rewrite rule whose handle cannot be applied no longer breaks
matching requests: `RewritePluginDataHandler` rejects it when the rule is
published and the plugin forwards the original URI. The rejection is only
visible in the gateway log:
```
invalid rewrite rule [<rule id>] is ignored, regex: test, replace: /new/$1,
reason: invalid replacement template: No group 1
```
`shenyu-admin` still stores the rule as enabled, so the dashboard shows a
healthy rewrite rule while requests are not rewritten, and nothing at
configuration time tells the operator that the handle is wrong.
The admin write boundary already validates `agentGateway` rule handles
(`AgentGatewayRuleHandleValidator`), but handles of the `rewrite` plugin are
stored as-is.
### Expected Behavior
The handle is rejected when the rule is created, updated or imported, with a
message that names the problem, for example:
```
rewrite rule handle can not be applied, invalid replacement template: No
group 1
```
so the configuration cannot reach a state that the gateway is going to
ignore. The runtime fail-safe from #7854 stays as the last line of defence, for
example for rules already stored in the database.
### Steps To Reproduce
1. Start `shenyu-admin` (9095) and `shenyu-bootstrap` (9195) with the
`rewrite` plugin enabled.
2. Create a rule for the `rewrite` plugin with the handle
`{"regex":"test","replace":"/new/$1"}`; the replacement references group 1
while the regex defines no capturing group.
3. The rule is created and enabled. The gateway logs `invalid rewrite rule
[...] is ignored` and the request URI is not rewritten.
The same happens for handles that are not valid JSON, and for invalid
regular expressions such as `{"regex":"(test","replace":"/new"}`.
### Environment
ShenYu version(s): master (277762010), Java 17, H2/MySQL.
### Anything else?
- Related: #7853, fixed by #7854. This is the configuration-time half of the
same problem.
- Suggested direction: reuse the runtime applicability check from
`RewritePluginDataHandler` in a shared util, add a `RewriteRuleHandleValidator`
next to the existing `AgentGatewayRuleHandleValidator`, and call it from
`RuleServiceImpl#validateRuleHandle`.
--
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]