[plugin-rsc] Option to salt server reference keys (unguessable, deploy-stable action IDs)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript, vite
- Ambito
- build-system
Direzione di ricerca
The key is built in ServerReferencesManager.resolve(), reached through getPluginApi(config).manager.serverReferences, so start there and see how referenceKey is hashed from toRelativeId(importId). A salt option would need to flow through the plugin options into that hash while keeping the output hex and leaving the default unchanged. Done means an opt-in salt changes the keys, the default output is unchanged, and the generated manifest and bound-args AAD still work.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Related plugins
Description
This would bring vite plugin rsc in line with next.js' action salting. Claude's summary below (reviewed by me)
In production builds, a server reference's key comes only from the module's path:
// ServerReferencesManager.resolve()
referenceKey: hashString(this.manager.toRelativeId(importId)) // sha256(path)[:12]
So an action ID is sha256("app/actions.ts")[:12] + "#signOut". Anyone who knows or can guess an app's file layout can compute every action ID, including actions the client never received. Action IDs aren't access control, and every action has to check who is calling it anyway. Still, frameworks generally don't want the set of actions to be enumerable from the source layout.
Next.js salts the hash:
// crates/next-custom-transforms/src/transforms/server_actions.rs
// $$id = special_byte + sha1('hash_salt' + 'file_name' + ':' + 'export_name')
with serverReferenceHashSalt: encryptionKey (packages/next/src/build/webpack-config.ts). That gives two behaviors:
- Encryption key shared across builds: IDs stay the same while path and export are unchanged, so a tab opened before a deploy can still call the action against the new build.
- No shared key: the salt is random per build, so IDs rotate on every deploy.
Suggested solution
Proposal
Add a build-only option, for example:
vitePluginRsc({
serverReferenceHashSalt?: string
})
mixed into the key, e.g. hashString(salt + "\0" + toRelativeId(importId)). If it's unset, keys stay as they are today, so nothing changes for existing users. A natural default for frameworks is the value they already pass as defineEncryptionKey.
The result has to stay hex: the key is spliced into generated identifiers (import_${referenceKey} in the server-references manifest) and is part of the bound-args AAD (${referenceKey}#${name}). Since resolve() is the only place a server reference key is created, a change there covers the RSC registration, the client and SSR proxies, encryption and the manifest at once.
An alternative is a general hook, such as serverReferenceKey?(relativeId: string) => string, if you'd rather not take on salting semantics.
Workaround today
We wrap getPluginApi(config).manager.serverReferences.resolve in configResolved and rehash referenceKey. It works, but ServerReferencesManager isn't a documented extension point, and we'd like to drop the wrapper.
Related
- #1229: deployment skew and compatibility-aware recovery. A salted key that stays stable when the framework's key is shared is what lets a stale client's action keep running across a deploy.
- #1424: the dev server will run any export of a 'use server' module, because it doesn't check export names. Different problem, same concern about what can be invoked.
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- Lingua principale
- TypeScript
- Stelle
- 1.2k
- Fork
- 287
- Merge medio
- 1g 17h
- PR unite (30g)
- 19
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Forse già presa @wozhenbang2004 l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
vitejs/vite-plugin-react#1570 ·
I maintainer di solito rispondono entro 1 giorno
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildForse già presa @NeilPant l’ha presa 3 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
vitejs/vite-plugin-react#1578 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
vitejs/vite-plugin-react#1577 ·
I maintainer di solito rispondono entro 1 giorno
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorForse già presa @draarivpatel-ui l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
vitejs/vite-plugin-react#1566 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
vitejs/vite-plugin-react#1565 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vitejs/vite-plugin-react
Issue simili
-
ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
mermaid-js/mermaid-v13#1370 ·
I maintainer di solito rispondono entro 1 giorno
-
compiler: the island_chunks_not_emitted report gives a count but not which islands were skippedApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Broken Website
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
darkreader/darkreader#16259 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
I maintainer di solito rispondono entro 1 giorno