Skip to content

fix: encoding issues for forecastle.stakater.com/url annotation - #558

Merged
msafwankarim merged 2 commits into
masterfrom
SA-8185-encoding-issues-for-forecastle-url-annotation
Apr 8, 2026
Merged

msafwankarim merged 2 commits into
masterfrom
SA-8185-encoding-issues-for-forecastle-url-annotation

Conversation

@SyedaFatimaKazmi

Copy link
Copy Markdown
Contributor

@SyedaFatimaKazmi SyedaFatimaKazmi added the ok-to-test Label for running e2e tests label Apr 8, 2026
@github-actions github-actions Bot removed the ok-to-test Label for running e2e tests label Apr 8, 2026
@msafwankarim
msafwankarim requested a review from Copilot April 8, 2026 08:19
@msafwankarim msafwankarim linked an issue Apr 8, 2026 that may be closed by this pull request
@msafwankarim
msafwankarim enabled auto-merge (squash) April 8, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes handling of forecastle.stakater.com/url annotations so URLs containing fragments (e.g., #...) are parsed/returned correctly instead of being rewritten/encoded unexpectedly.

Changes:

  • Switch URL parsing from url.ParseRequestURI to url.Parse for the forecastle URL annotation path.
  • Add/adjust validation to reject URLs missing a scheme.
  • Add unit tests covering fragment-containing URLs for Ingress and the shared URL-annotation validator.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/kube/wrappers/map.go Updates shared URL-annotation parsing/validation logic.
pkg/kube/wrappers/ingress.go Updates Ingress URL override parsing/validation to accept fragments.
pkg/kube/wrappers/ingress_test.go Adds a test case asserting fragment URLs are preserved for Ingress.
pkg/kube/wrappers/httproute_test.go Adds tests asserting fragment URLs are preserved for shared validation helper.
Comments suppressed due to low confidence (3)

pkg/kube/wrappers/map.go:42

  • getAndValidateURLAnnotation returns parsedURL.String(), which canonicalizes/escapes the URL and may still modify the annotation value (e.g., escaping characters or normalizing case). Since the goal is to preserve the URL exactly as provided in the annotation, consider returning the original urlValue after validation instead of re-serializing the parsed URL.
	parsedURL, err := url.Parse(urlValue)
	if err != nil || parsedURL.Scheme == "" {
		logger.Warn(err)
		return ""
	}

	return parsedURL.String()
}

pkg/kube/wrappers/map.go:41

  • Validation is currently too permissive: checking only parsedURL.Scheme != "" will treat values like http:example.com (scheme set, host empty / opaque URL) as valid. README docs indicate the value must be an http:// or https:// URL, so it would be safer to enforce Scheme in {http,https} and require a non-empty Host (and typically Opaque == "") before accepting the annotation.
	parsedURL, err := url.Parse(urlValue)
	if err != nil || parsedURL.Scheme == "" {
		logger.Warn(err)
		return ""
	}

	return parsedURL.String()

pkg/kube/wrappers/ingress.go:71

  • This block duplicates URL validation logic that already exists in getAndValidateURLAnnotation and has the same issues (possible <nil> logging when scheme is missing, and reliance on parsedURL.String() which can re-encode/canonicalize). Consider delegating to getAndValidateURLAnnotation here so validation/normalization behavior stays consistent across wrappers and fixes only need to be made in one place.
	if urlFromAnnotation := iw.GetAnnotationValue(annotations.ForecastleURLAnnotation); urlFromAnnotation != "" {
		parsedURL, err := url.Parse(urlFromAnnotation)
		if err != nil || parsedURL.Scheme == "" {
			logger.Warn(err)
			return ""
		}
		return parsedURL.String()
	}

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

Comment thread pkg/kube/wrappers/map.go Resolved
@msafwankarim
msafwankarim merged commit 5920343 into master Apr 8, 2026
8 checks passed
@msafwankarim
msafwankarim deleted the SA-8185-encoding-issues-for-forecastle-url-annotation branch April 8, 2026 08:29
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.

[BUG] Encoding issues for forecastle.stakater.com/url annotation?

3 participants