Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default defineConfig({
// For local playground only. As a user you don't install this plugin directly.
DevTools({
builtinDevTools: false,
authId: 'test-fixed-auth-id',
}),
DevToolsRolldownUI(),
UnoCSS(),
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ export interface DevToolsOptions {
* @default true
*/
builtinDevTools?: boolean
/**
* Use a fixed auth id for all clients connecting to the devtools.
*/
authId?: string
}

export async function DevTools(options: DevToolsOptions = {}): Promise<Plugin[]> {
const {
builtinDevTools = true,
authId,
} = options

const plugins = [
DevToolsInjection(),
DevToolsServer(),
DevToolsServer({ authId }),
]

if (builtinDevTools) {
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/node/plugins/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function renderDockImportsMap(docks: Iterable<DevToolsDockEntry>): string
].join('\n')
}

export function DevToolsServer(): Plugin {
export interface DevToolsServerOptions {
authId?: string
}

export function DevToolsServer(options: DevToolsServerOptions = {}): Plugin {
let context: DevToolsNodeContext
return {
name: 'vite:devtools:server',
Expand All @@ -51,6 +55,7 @@ export function DevToolsServer(): Plugin {
cwd: viteDevServer.config.root,
hostWebSocket: host,
context,
authId: options.authId,
})
viteDevServer.middlewares.use(DEVTOOLS_MOUNT_PATH, middleware)
},
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/node/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CreateWsServerOptions {
hostWebSocket: string
base?: string
context: DevToolsNodeContext
authId?: string
}

const ANONYMOUS_SCOPE = 'vite:anonymous:'
Expand Down Expand Up @@ -117,6 +118,7 @@ export async function createWsServer(options: CreateWsServerOptions) {
return {
backend: 'websocket',
websocket: port,
...(options.authId ? { authId: options.authId } : {}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we send an auth ID in this connection info, it loses the point of the security check (similar to publishing the password to your computer on a blog).

To support custom auth id, we should have updated the ui with a textbox to allow entering the auth id on the client side, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I created a new pr(#223) to support custom auth id in settings UI.

}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/client/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function getDevToolsRpcClient(
const context: DevToolsClientContext = {
rpc: undefined!,
}
const authId = getConnectionAuthIdFromWindows(options.authId)
const authId = getConnectionAuthIdFromWindows(options.authId ?? connectionMeta.authId)
const clientRpc: DevToolsClientRpcHost = new RpcFunctionsCollectorBase<DevToolsRpcClientFunctions, DevToolsClientContext>(context)

async function fetchJsonFromBases(path: string): Promise<any> {
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/types/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ export interface DevToolsNodeUtils {
export interface ConnectionMeta {
backend: 'websocket' | 'static'
websocket?: number | string
authId?: string
}