Skip to content

hack/releaser: preserve query string on CloudFront redirects#25393

Open
dvdksn wants to merge 1 commit into
docker:mainfrom
dvdksn:lambda-redirects-preserve-query
Open

hack/releaser: preserve query string on CloudFront redirects#25393
dvdksn wants to merge 1 commit into
docker:mainfrom
dvdksn:lambda-redirects-preserve-query

Conversation

@dvdksn

@dvdksn dvdksn commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

The CloudFront redirect Lambda (cloudfront-lambda-redirects.js) dropped the request query string when issuing 301 responses, so UTM tags and other params were lost on redirected URLs. This appends the query string to the Location header of both the exact-match and prefix redirects (the directory/markdown rewrite branch already forwards the request, so params survive there).

Adds unit tests (node --test, zero dependencies) that render the Go template the same way aws.go does and exercise the handler. The tests run in CI via a new releaser-test Dockerfile stage / bake target, baked alongside releaser-build in the existing releaser job.

Learnings

  • The redirect Lambda source is a Go text/template ({{.RedirectsJSON}} / {{.RedirectsPrefixesJSON}}), rendered and zipped by hack/releaser/aws.go. To unit-test it, substitute the placeholders the same way aws.go does, then evaluate the result as a CommonJS module.
  • test-go-redirects validates redirect data against the built public/ site, so it's the wrong host for a fast pure-JS test — the releaser job, which already builds from hack/releaser, is the natural home and has no Hugo dependency.

Generated by Claude Code

The CloudFront redirect Lambda dropped the request query string when
issuing 301 responses, so UTM tags and other params were lost on
redirected URLs. Append the query string to both the exact and prefix
redirect Location headers, and add unit tests wired into the releaser
CI job.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit 07ba036
🔍 Latest deploy log https://app.netlify.com/projects/docsdocker/deploys/6a33f7c8f6a3c6000859c964
😎 Deploy Preview https://deploy-preview-25393--docsdocker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dvdksn dvdksn added the status/review Pull requests that are ready for review label Jun 18, 2026
@github-actions github-actions Bot added area/release Relates to CI or deployment area/config ci ci updates labels Jun 18, 2026
@dvdksn dvdksn requested a review from a team June 18, 2026 13:51

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

This PR modifies only infrastructure and build tooling files:

  • .github/workflows/build.yml
  • docker-bake.hcl
  • hack/releaser/Dockerfile
  • hack/releaser/cloudfront-lambda-redirects.js
  • hack/releaser/cloudfront-lambda-redirects.test.js

No user-facing documentation pages, Markdown files, front matter, or style guide concerns were found. No vendored/generated files were edited. No redirects are needed (no pages were removed or moved).

The change correctly preserves query strings (UTM parameters, etc.) on CloudFront 301 redirects and adds CI-wired unit tests. Nothing to flag from a documentation quality perspective.

@thaJeztah thaJeztah requested a review from mark-dr June 18, 2026 14:37

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

No documentation quality issues found. This PR is entirely infrastructure/tooling changes (JavaScript, Dockerfile, HCL, GitHub Actions YAML) with no documentation content modified. The query-string preservation logic and unit tests look correct.

Comment on lines +9 to +15
const withQuery = (location) => {
if (!request.querystring) {
return location;
}
const separator = location.includes('?') ? '&' : '?';
return location + separator + request.querystring;
};

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.

thought: I'd personally default to allow-listing this (e.g. just support UTM parameters)

(I can't see any exploitative angles at the moment, would be just in fear of unknown-unknowns)

suggestion: Manipulate this with URL instead of doing raw string concatenation

If location were something like https://foo.com?x=123#some-header, this would yield things like https://foo.com?x=123#some-header&utm_source=....

I'd personally parse location into a URL and request.querystring into a URLSearchParams, then merge the latter into the former's search params, then read its .href to get the final URL.

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

Fixes the CloudFront redirect Lambda@Edge handler so 301 redirects preserve the incoming request query string (e.g., UTM parameters), preventing query params from being dropped during exact-match and prefix redirects.

Changes:

  • Append request.querystring to redirect Location headers for exact-match and prefix redirects.
  • Add node --test unit tests that render the Go-templated Lambda source similarly to hack/releaser/aws.go and exercise the handler behavior.
  • Run the new unit tests in CI by adding a releaser-test Dockerfile stage and corresponding Bake target, invoked in the existing releaser workflow job.

Reviewed changes

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

Show a summary per file
File Description
hack/releaser/cloudfront-lambda-redirects.js Preserves query strings when constructing redirect Location headers.
hack/releaser/cloudfront-lambda-redirects.test.js Adds Node unit tests validating query-string preservation and directory rewrite pass-through behavior.
hack/releaser/Dockerfile Introduces a releaser-test stage to run the Node unit tests.
docker-bake.hcl Adds a releaser-test Bake target for CI execution.
.github/workflows/build.yml Runs releaser-test alongside releaser-build in the releaser job.

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

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

This PR correctly fixes the query-string preservation bug in the CloudFront redirect Lambda and adds unit tests for the new behavior. No documentation content files are modified. No vendored or generated files are touched. No redirects are missing.

The core logic is sound: withQuery() correctly appends the query string to both exact-match and prefix redirects, using & when the target already contains a ?. The test suite covers the main scenarios (exact redirect with/without query string, appending to an existing query string, prefix strip/no-strip, and directory rewrite pass-through).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config area/release Relates to CI or deployment ci ci updates status/review Pull requests that are ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants