Skip to content

util/git: add domain suffix host matching and fix trailing slash handling - #407

Merged
cuixq merged 4 commits into
google:mainfrom
cuixq:fix
Oct 13, 2026
Merged

cuixq merged 4 commits into
google:mainfrom
cuixq:fix

Conversation

@cuixq

@cuixq cuixq commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator
  • Support domain-suffix matching in RegisterHostHandler and getHostHandler when the registered host starts with ., and register a StandardHostHandler for .googlesource.com.
  • Strip trailing slashes from res.Path at the start of StandardHostHandler.Canon() before segment counting and .git suffix checks, and re-add the slash at the end only when HasTrailingSlash is true.

Signed-off-by: Xueqin Cui <cuixq@google.com>
@cuixq
cuixq marked this pull request as ready for review October 9, 2026 04:26
@cuixq
cuixq requested a review from calebbrown October 9, 2026 04:26
@calebbrown

Copy link
Copy Markdown
Collaborator

Hi @cuixq,

Trailing slash support is already in the host handler. Did you consider adding a host handler for chromium.googlesource.com?

@cuixq

cuixq commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

@calebbrown Adding a host handler for chromium.googlesource.com alone doesn't quite fix .git/ URLs, because StandardHostHandler.Canon handles .git before stripping the trailing /.

Also, since RegisterHostHandler only matches exact hostnames, registering chromium.googlesource.com wouldn't cover other *.googlesource.com subdomains.

Do you prefer keeping this in canon.go, or should I instead fix the / and .git ordering in hosts.go/repo.go and add a handler for chromium.googlesource.com?

@calebbrown

calebbrown commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

So my prior take on this in https://github.com/ossf/malicious-packages/blob/main/internal/gitname/hosts.go had support for domain suffix mapping. This is definitely worth adding.

I didn't add it here originally since it made the code more complex.

I think the right thing to do is:

  1. add the domain-suffix based matching; and
  2. fix the .git code in StandardHostHandler so that it strips any trailing slashes before adding the .git suffix is checked. This probably should be done independently of HasTrailingSlash. So example.com/path/to/repo/ becomes example.com/path/to/repo.git (or example.com/path/to/repo.git/ if HasTrailingSlash is true)

…ling

Signed-off-by: Xueqin Cui <cuixq@google.com>
@cuixq cuixq changed the title util/git: strip trailing slashes in canon util/git: add domain suffix host matching and fix trailing slash handling Oct 13, 2026
Comment thread util/git/hosts.go
@cuixq
cuixq merged commit 7bac2db into google:main Oct 13, 2026
13 checks passed
@cuixq
cuixq deleted the fix branch October 13, 2026 10:01
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.

2 participants