[plugin-rsc] Option to salt server reference keys (unguessable, deploy-stable action IDs)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- react, typescript, vite
- 領域
- build-system
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 1.2k
- フォーク
- 287
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vitejs/vite-plugin-react のほかの issue
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)対応中かも @wozhenbang2004 が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
vitejs/vite-plugin-react#1570 ·
メンテナーはふだん 1 日以内に返信
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC build対応中かも @NeilPant が 3 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
vitejs/vite-plugin-react#1578 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
vitejs/vite-plugin-react#1577 ·
メンテナーはふだん 1 日以内に返信
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceError対応中かも @draarivpatel-ui が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
vitejs/vite-plugin-react#1566 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
vitejs/vite-plugin-react#1565 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
vitejs/vite-plugin-react の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
knaw-huc/textannoviz#742 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cloudflare/realtimekit-ui#219 ·
メンテナーはふだん 1 日以内に返信
-
ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaks対応中かも @argszero が今日担当しました。 オープンarea/tui platform/wsl status/repro-simulated type/bug version/v2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
anomalyco/opencode#66773 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mermaid-js/mermaid-v13#1370 ·
メンテナーはふだん 1 日以内に返信