fix(launchpad): QR code encodes the page's own URL - #59
Merged
Merged
Conversation
…AIN/{shortCode}
The page's QR image was requested without a url, so the QR route encoded
SHORTLINK_DOMAIN plus the bare short code. A visitor on a custom host, or on
a templated path, scanned a code that pointed somewhere else — and any query
string they arrived with was lost in the hop to the phone.
The page now passes its own address (host, template path, query string up to
512 characters) as the QR route's new url parameter. The parameter is
restricted to http(s) URLs whose path ends in that link's short code, so the
endpoint cannot be used to mint codes for arbitrary destinations; the cache
key includes it.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Launchpad page's QR image was requested as
/api/links/{id}/qr?format=svg&size=264, so the QR route fell back toSHORTLINK_DOMAIN/{shortCode}. For a link served on another host or under a template path (/{slug}/{code}), the phone was sent somewhere other than the page the visitor was looking at, and the visitor's query string never made the hop.Change
renderLaunchpadPagepassespageUrlas aurlquery parameter on the QR image.pageUrlfrom the request host, the template path and the visitor's query string (dropped entirely when longer than 512 characters, so the code stays scannable).og:urlgets the same value.GET /api/links/:id/qracceptsurl. It is restricted to http(s) URLs whose path ends in/{shortCode}of that link — the link on any host, under any path, with any query — and anything else is a 400, so the endpoint cannot mint codes for arbitrary destinations. The cache key includes it. Withouturl, behavior is unchanged.Tests —
qr.test.ts(new, 5): the guard's accept/reject cases, a 200 for a templated custom-host URL, a 400 for a foreign destination, the unchanged fallback.redirect.launchpad.test.ts(+2): host + template path + query string reach the QRurl, and an over-long query is dropped. 389 passing.README:
urldocumented under QR Codes.