Skip to content

fix(middleware): harden redirect URL construction in v4 - #3224

Merged
vishr merged 1 commit into
v4from
fix/v4-redirect-host-validation
Nov 12, 2026
Merged

vishr merged 1 commit into
v4from
fix/v4-redirect-host-validation

Conversation

@vishr

@vishr vishr commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Backport of #3220 to v4. Closes #3217 for v4.

  • Returns 400 when the redirect host is empty, starts with : or ., contains %, or becomes empty after removing www..
  • Skips redirects for OPTIONS * requests.
  • Maps ws/wss to http/https in redirect targets.
  • Matches the www. prefix case-insensitively.
  • Validates the host and URI only when a redirect is needed.

HTTPSWWWRedirect keeps its v4 semantics: plain HTTP requests to hosts that already start with www. are not redirected. Changing that in a patch release can cause redirect loops when Scheme() cannot detect HTTPS behind a proxy. v5 redirects these requests.

Tests are adapted to the v4 echo.Context interface.

@vishr
vishr force-pushed the fix/v4-redirect-host-validation branch from d018055 to 2cf7d4d Compare November 12, 2026 06:38
@vishr
vishr merged commit bf9d756 into v4 Nov 12, 2026
8 checks passed
@vishr
vishr deleted the fix/v4-redirect-host-validation branch November 12, 2026 08:41
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