Repository navigation
feat(preview): an optional key so only scanned devices get in - #108
Merged
Merged
Conversation
With the phone preview on, the dev server answers everyone on the Wi-Fi: Stacki's own routes are locked to this computer, but the site and everything Vite serves are open to any device on the same network. The QR card now has a settings gear beside Copy with one option, "Only via this code". Off by default and never saved (not in settings, not in .stacki): turning the preview off, closing the project or quitting forgets it. Turned on, main makes a random key (32 bytes, base64url) and restarts the dev server with it in its environment only (STACKI_PREVIEW_KEY). The QR code and Copy carry it as a query parameter; the shown address and the code's spoken label never do. The loopback guard answers the code's address with an HttpOnly, SameSite=Lax cookie and a 303 to the same page without the key, so it leaves the address bar and the history; the cookie then lets that device in, and every other request from the network gets 403, Vite's live-reload WebSocket included (an upgrade listener before Vite's). This computer always passes, so the canvas needs no key, and Stacki's routes stay closed to every other device, key or not. Every device that scans the code gets in (a phone and an iPad alike); turning the option off and on makes a new key, which locks out the devices that scanned an older code. Keys are compared in constant time. The request and state of dev:setNetwork carry the access (open, or key with its key), parsed at the boundary. Changing the access while on keeps the card in place, dimmed, instead of redrawing it as skeletons. The popover grows from 232 to 260 px for the gear, and the QR tile from 208 to 236 px so it still fills it. Tests: the contract (access, key format), the guard's verdicts, cookie bounds and a real server reached through this machine's own network address (403 without the code, 303 and cookie with it, the WebSocket refused without the cookie), main's key life cycle, the popover (gear, setting, keyless display, keyed Copy, no redraw), the Chromium layout, and the LAN integration run against a real Astro server.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An optional key in the phone preview's QR code, so only the devices that scan it can open the preview, as discussed on Discord.
UI
Tests
npm run integration:lanagainst a real Astro dev server.