[plugin-rsc] Option to salt server reference keys (unguessable, deploy-stable action IDs)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript, vite
- Domain
- build-system
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 287
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Possibly taken @wozhenbang2004 claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
vitejs/vite-plugin-react#1570 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildPossibly taken @NeilPant claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vitejs/vite-plugin-react#1578 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
vitejs/vite-plugin-react#1577 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorPossibly taken @draarivpatel-ui claimed this 2 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
vitejs/vite-plugin-react#1566 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
vitejs/vite-plugin-react#1565 · 2 comments ·
Maintainers usually reply within 1 day
All issues in vitejs/vite-plugin-react
Similar issues
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
mermaid-js/mermaid-v13#1370 ·
Maintainers usually reply within 1 day
-
compiler: the island_chunks_not_emitted report gives a count but not which islands were skippedOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Broken Website
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
darkreader/darkreader#16259 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
Maintainers usually reply within 1 day