Skip to content

fix(middleware): isolate rewrite rules between router instances - #3246

Open
Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/isolate-rewrite-regex-rules
Open

Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/isolate-rewrite-regex-rules

Conversation

@Twiink

@Twiink Twiink commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Two Echo routers can share a map of regex rewrite rules while defining different string rules. Building the second middleware currently inserts its string rules into the caller's map, including the rules the first router already uses. The first router can then start rewriting paths configured only for the second one.

Compile the string rules into a fresh map and copy the regex rules into it. The regression starts two middleware configurations from the same map and checks the first router's responses as well as the original map.

Focused rewrite tests, the full race-enabled suite with coverage, Go vet, and formatting passed locally.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Rewrite Rule Isolation

Layer / File(s) Summary
Local rule map and regression coverage
middleware/rewrite.go, middleware/rewrite_test.go
ToMiddleware merges converted rules and regex rules in a local map. Regex rules take precedence for matching keys. The test checks both middleware routing and confirms the shared map remains unchanged.

Suggested reviewers: lammel, vishr, kumapower17

Change: Bug fix

Merge Risk: Minimal · up to 1bdd1

This change stops rewrite middleware construction from modifying a shared regex-rule map, so one router no longer picks up rules meant for another. A regression test covers the case, and no merge-blocking risk remains.

Security architecture risk: Minimal · up to 1bdd1

Building rewrite middleware no longer changes the rules used by another instance. Requests still go through the same rewrite checks, and the change does not introduce a new route or grant new access.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The prior path for unintended rule inheritance was limited to middleware instances sharing the same in-process map. The head removes that shared-map path; the evidence does not establish that the affected instances served different tenants.

Trust Boundaries and Controls

  • observed — Application configuration supplies the rules at construction. Requests can affect matching and capture values, but the request handler does not write rule entries. The existing distinction between pre-routing URL parsing and post-routing literal application remains in place.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ce1a5fe2-4af7-4e82-8486-0d4786d79c16
Commits

Reviewing files that changed from the base of the PR and between 59aacdd and 1bdd1c0.

Files selected for processing: 2

  • middleware/rewrite.go
  • middleware/rewrite_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.22%. Comparing base (dcb05f0) to head (1bdd1c0).
⚠️ Report is 64 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3246      +/-   ##
==========================================
+ Coverage   93.34%   96.22%   +2.88%     
==========================================
  Files          43       46       +3     
  Lines        4735     4429     -306     
==========================================
- Hits         4420     4262     -158     
+ Misses        192      167      -25     
+ Partials      123        0     -123     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant