Skip to content

webhook: use regexp.QuoteMeta for hostname and path#5153

Open
p-se wants to merge 1 commit into
rancher:mainfrom
p-se:webhook
Open

webhook: use regexp.QuoteMeta for hostname and path#5153
p-se wants to merge 1 commit into
rancher:mainfrom
p-se:webhook

Conversation

@p-se
Copy link
Copy Markdown
Contributor

@p-se p-se commented May 19, 2026

Additional Information

Checklist

  • I have updated the documentation via a pull request in the fleet-product-docs repository.

@p-se p-se requested a review from a team as a code owner May 19, 2026 12:19
Copilot AI review requested due to automatic review settings May 19, 2026 12:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens webhook GitRepo URL matching by escaping user-controlled hostname/path segments before building the matching regexp, preventing regexp metacharacters in webhook payload URLs from matching unintended GitRepos.

Changes:

  • Escape webhook payload URL hostname and path with regexp.QuoteMeta() when constructing the repo-matching regexp.
  • Add a regression test ensuring wildcard-like webhook URLs (e.g. .*) do not match unrelated GitRepo URLs.

Reviewed changes

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

File Description
pkg/webhook/webhook.go Escapes hostname/path components before regexp compilation to avoid regexp metacharacter injection in URL matching.
pkg/webhook/webhook_test.go Adds a regression test covering “wildcard” hostname/path inputs in webhook payload repo URLs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("X-GitHub-Event", "push")
Comment on lines +972 to +981
rr := httptest.NewRecorder()
w.ServeHTTP(rr, req)

updated := &v1alpha1.GitRepo{}
if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitRepo.Name, Namespace: gitRepo.Namespace}, updated); err != nil {
t.Fatalf("failed to get gitrepo: %v", err)
}
if updated.Status.WebhookCommit != "" {
t.Errorf("expected WebhookCommit to remain empty (no match), but got %q", updated.Status.WebhookCommit)
}
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