Skip to content

🐛 bug: trim only one trailing dot in host normalization#4307

Merged
ReneWerner87 merged 1 commit into
mainfrom
fix-host-authorization-trailing-dot-normalization
May 21, 2026
Merged

🐛 bug: trim only one trailing dot in host normalization#4307
ReneWerner87 merged 1 commit into
mainfrom
fix-host-authorization-trailing-dot-normalization

Conversation

@gaby

@gaby gaby commented May 21, 2026

Copy link
Copy Markdown
Member

Motivation

  • Restore the intended FQDN canonicalization semantics so that only a single trailing root-label dot is removed from hosts, preventing malformed multi-dot authorities (e.g. example.com..) from being silently accepted and matched against allowlist entries.

Description

  • Replace calls to utils.TrimRight(host, '.') with a new trimOneTrailingDot(host string) string helper that removes at most one trailing . from the hostname in middleware/hostauthorization/hostauthorization.go.
  • Update normalizeHost to use trimOneTrailingDot on both the fast path and the general path before lowercasing and punycode conversion.
  • Add focused regression tests in middleware/hostauthorization/hostauthorization_test.go to assert that multiple trailing dots are only trimmed once for both plain hosts and authority strings with ports.

@gaby gaby requested a review from a team as a code owner May 21, 2026 14:03
@gaby gaby added the aardvark label May 21, 2026
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d68839fb-d1a2-4b5f-82af-9da490e66755

📥 Commits

Reviewing files that changed from the base of the PR and between 6a97fe8 and 0963d7b.

📒 Files selected for processing (2)
  • middleware/hostauthorization/hostauthorization.go
  • middleware/hostauthorization/hostauthorization_test.go

Walkthrough

The PR refines host normalization in the authorization middleware by introducing a trimOneTrailingDot helper function that removes only a single trailing dot character. This replaces the previous behavior that removed all trailing dots, while maintaining all other normalization steps: port stripping, lowercasing, and IDN-to-Punycode conversion.

Changes

Trailing dot trimming refinement

Layer / File(s) Summary
Trailing dot normalization with trimOneTrailingDot helper
middleware/hostauthorization/hostauthorization.go, middleware/hostauthorization/hostauthorization_test.go
A new trimOneTrailingDot helper removes at most one trailing dot. Both the fast-path (plain hostnames) and non-fast-path (bracketed/colon-containing hosts) branches of normalizeHost now use this helper. Test cases verify that "example.com.." normalizes to "example.com." and that "api.example.com...:443" parses successfully with one trailing dot trimmed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • gofiber/fiber#4293: Both PRs modify normalizeHost trailing-dot handling in the host authorization middleware with overlapping logic and test expectations.
  • gofiber/fiber#4291: Adds an early rejection guard that triggers when normalizeHost(c.Hostname()) is empty, directly complementing this change to constrained dot trimming.

Suggested labels

☢️ Bug, v3, 📜 RFC Compliance

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

🐰 One dot at a time, we learn to be wise,
Not all at once, but measured and precise.
The hosts now rest with careful trim,
One trailing spark—no more, no whim!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. It lacks required sections like 'Changes introduced' with checkboxes, 'Type of change' selection, and a 'Checklist' confirming compliance with project requirements. Complete the description by adding the required template sections: mark appropriate checkboxes under 'Changes introduced' and 'Type of change', and confirm checklist items to meet repository standards.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: trimming only one trailing dot in host normalization, which directly aligns with the core issue being fixed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-host-authorization-trailing-dot-normalization

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the host normalization logic to ensure only a single trailing dot is removed from hostnames, replacing the previous behavior that stripped all trailing dots. New test cases were added to validate this specific behavior for both plain hostnames and those with ports. The reviewer suggested a more idiomatic implementation for the new trimOneTrailingDot function using strings.TrimSuffix to improve code clarity and safety.

Comment thread middleware/hostauthorization/hostauthorization.go
@gaby gaby removed the aardvark label May 21, 2026
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.33%. Comparing base (6a97fe8) to head (0963d7b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4307      +/-   ##
==========================================
+ Coverage   91.28%   91.33%   +0.04%     
==========================================
  Files         132      132              
  Lines       13036    13040       +4     
==========================================
+ Hits        11900    11910      +10     
+ Misses        718      713       -5     
+ Partials      418      417       -1     
Flag Coverage Δ
unittests 91.33% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adjusts host canonicalization in the hostauthorization middleware to remove only one trailing root-label dot (.), ensuring malformed multi-dot hosts (e.g. example.com..) don’t get normalized into a value that could match allowlisted entries unintentionally.

Changes:

  • Replaced full right-trim of dots with a trimOneTrailingDot helper to remove at most one trailing . during host normalization.
  • Updated normalizeHost to apply the one-dot trim consistently on both the fast path (no port) and general path (SplitHostPort / bracket handling).
  • Added regression tests covering multiple trailing dots for plain hosts and authority strings with ports.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
middleware/hostauthorization/hostauthorization.go Changes host normalization to trim at most one trailing dot via a dedicated helper.
middleware/hostauthorization/hostauthorization_test.go Adds regression coverage ensuring multi-dot inputs only lose one trailing dot (including with ports).

@ReneWerner87 ReneWerner87 merged commit f3a2ddc into main May 21, 2026
32 checks passed
@ReneWerner87 ReneWerner87 deleted the fix-host-authorization-trailing-dot-normalization branch May 21, 2026 14:36
@github-project-automation github-project-automation Bot moved this to Done in v3 May 21, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.3.0 May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants