Provision local HTTPS certificates automatically when running Vite with localHttps - #3953
Provision local HTTPS certificates automatically when running Vite with localHttps#3953fredericoo wants to merge 4 commits into
localHttps#3953Conversation
localHttps
frandiox
left a comment
There was a problem hiding this comment.
Nice. I had seen other Vite plugins doing something similar but since we have a core feature like customer accounts, it makes sense we export one 🤔
I'm seeing this but I think it was fixed already in MiniOxygen?
Request must contain a host header.
at toWeb (file:///...hydrogen/node_modules/.pnpm/@shopify+mini-oxygen@4.2.0_vite@8.0.10_@types+node@22.19.17_esbuild@0.28.1_jiti@2.6.1_t_33b61828dcbe09e87499152c791ecdbb/node_modules/@shopify/mini-oxygen/dist/vite/utils.js:13:11)
| try { | ||
| await provisionCertificates(settings); |
There was a problem hiding this comment.
This is a big side effect when running the Vite plugin, and I'm not sure users would notice (it modifies their system to add a certificate).
Would it make sense if we use node:readline/promises or similar to block the process until the user accepts a terminal prompt? (or exit with a nice message otherwise)
That or require a manual setup https command?
Not sure really 🤔
There was a problem hiding this comment.
i designed the API to support a setup step separately (useful for CI, as we skip interactive prompts)
but the DX obsessive in me wants to make it just work
the experience is pretty clear, there are logs all throughout the process, users know what's going on, so i'd say keep it?
- we can add jsdoc to the httpOnly plugin saying that by using this in vite, if enabled it will create a certificate on your machine
- or a prompt to get acceptance first
open to either way
There was a problem hiding this comment.
I love the "it just works" but at the same time, this is modifying the system to install a certificate... I feel this is something we should ask confirmation for. Or at least have more than 1 single step to run it: force them to enable it manually and read a comment on top of it, etc.
Alternatively... is there a command we could print to uninstall the cert we just added? Perhaps that would be good enough if someone can just undo, and give them the command when they run dev:https?
It seems there's mkcert -uninstall, and we could wire it up with extra cleaning via npx hydrogen setup https --uninstall or similar? We might need a different CAROOT for mkcert so that it doesn't uninstall different certs though 🤔
yeah i fixed it but it's not released yet edit: now fixed in preview, using the correct minioxygen version |
a5581ff to
c9897c6
Compare
Assisted-By: devx/07abca81-b031-4579-88c8-bc07dfd3c5aa
Assisted-By: devx/07abca81-b031-4579-88c8-bc07dfd3c5aa
Assisted-By: devx/07abca81-b031-4579-88c8-bc07dfd3c5aa
Assisted-By: devx/05def498-8bdd-48d0-bd5e-35e4667a2f3d
c9897c6 to
b5b5d11
Compare
TL;DR: Local HTTPS for Vite-based setups required a manual, macOS-flavored mkcert install before Customer Account flows worked. This PR (stacked on #3936) makes certificate provisioning automatic and portable across macOS, Linux, and Windows, mirroring
next dev --experimental-httpsbut with a hardened supply chain: mkcert is pinned to an exact release and verified against per-platform SHA-256 checksums, so a compromised "latest" release can never execute.Before
After
What this changes
src/vite/mkcert.ts: downloads mkcert v1.4.4 from GitHub releases for darwin/linux/windows x x64/arm64, refuses anything that does not match the pinned SHA-256 for that platform, caches the binary at~/.shopify/hydrogen/mkcert/, and re-verifies the checksum before every spawn. Download has a 60s timeout; the write is atomic (tmp + rename) so concurrent dev servers never execute a partial binary.localHttps()provisions missing certificates whenvite devstarts (skipped for build, preview, and CI). Any failure degrades to the existing warning, now including the failure reason, thenpx hydrogen setup httpsremedy, and the manual mkcert steps.hydrogen setup httpsCLI command and a publicprovisionLocalHttps()export on@shopify/hydrogen/vitefor frameworks that read certificate paths while the config is evaluated, before the Vite plugin runs (Nuxt, SolidStart).https:setupscript is now cross-platform: it builds the package and runs the CLI instead of a$HOME/mkdir -pshell one-liner.cashapp/hermit-packagesand ScoopScoopInstaller/Extras) and were additionally verified against the live release assets. A test asserts every target pins a distinct checksum.Developer impact
Extends the existing minor changeset for
@shopify/hydrogen: adds theprovisionLocalHttps()/ProvisionLocalHttpsOptionsexports on@shopify/hydrogen/viteand thehydrogen setup httpsCLI command. ExistinglocalHttps()/localHttpsDevServer()call sites need no changes; the packagedhydrogen-local-httpsskill and repo docs now describe the automatic flow.Out of scope
Risk
vite devnow runsmkcert -install, which installs a root CA into the system trust store and may prompt for a password. This is the same trust decision the manual instructions asked for, but it now happens on dev-server startup. CI environments are excluded (CIenv var); non-TTY sudo fails fast into the warning rather than hanging.How to Test
mv ~/.shopify/hydrogen ~/.shopify/hydrogen.bakpnpm install && pnpm build:pkgspnpm --filter @shopify/hydrogen-example-astro https:devhttps://local.tryhydrogen.dev:5173with a trusted certificate.pnpm https:setup— it should report the certificates are already in place without re-downloading.rm -rf ~/.shopify/hydrogen && mv ~/.shopify/hydrogen.bak ~/.shopify/hydrogen