apache / apache/shenyu

[BUG] CrossFilter compiles origin regex on every CORS request

Open Beginner friendly
#6,577 1 comment 0 reactions 0 assignees View on GitHub
priority: medium type: performance
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
When `allowedOrigin.originRegex` is configured and the origin is not in the explicit allow-set, `allowCors = Pattern.matches(originRegex.trim(), origin)` recompiles the regex on every request on the WebFilter chain (Netty event loop).

## Location
```
shenyu-web/.../filter/CrossFilter.java:94
```

## Impact
Per-CORS-request regex compile when the regex allow-list path is used. Minor at low RPS, measurable for high-RPS public APIs relying on regex origins.

## Suggested fix
Compile `originRegex` once at config-load time into a `java.util.regex.Pattern` field; call `.matcher(origin).matches()`.

## Related existing issue(s)
None

_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-web/.../filter/CrossFilter.java at line 94, then trace how allowedOrigin is loaded and initialized. Move regex compilation to that configuration path and use the compiled pattern for matching; done means the regex is not compiled for each CORS request while existing origin matching behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.