Skip to content

Commit 4972986

Browse files
committed
feat: allow to disable auth via config and env
1 parent 14185da commit 4972986

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/core/src/node/rpc/anonymous/auth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import process from 'node:process'
12
import * as p from '@clack/prompts'
23
import { defineRpcFunction } from '@vitejs/devtools-kit'
34
import c from 'ansis'
@@ -19,14 +20,19 @@ export const anonymousAuth = defineRpcFunction({
1920
setup: (context) => {
2021
const internal = getInternalContext(context)
2122
const storage = internal.storage.auth
23+
const isClientAuthDisabled = context.viteConfig.devtools?.clientAuth === false || process.env.VITE_DEVTOOLS_DISABLE_CLIENT_AUTH === 'true'
24+
25+
if (isClientAuthDisabled) {
26+
console.warn('[Vite DevTools] Client authentication is disabled. Any browser can connect to the devtools and access to your server and filesystem.')
27+
}
2228

2329
return {
2430
handler: async (query: DevToolsAuthInput): Promise<DevToolsAuthReturn> => {
2531
const session = context.rpc.getCurrentRpcSession()
2632
if (!session)
2733
throw new Error('Failed to retrieve the current RPC session')
2834

29-
if (storage.get().trusted[query.authId]) {
35+
if (isClientAuthDisabled || storage.get().trusted[query.authId]) {
3036
session.meta.clientAuthId = query.authId
3137
session.meta.isTrusted = true
3238
return {

packages/kit/src/types/vite-augment.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ declare module 'vite' {
66
interface Plugin {
77
devtools?: DevToolsPluginOptions
88
}
9+
interface UserConfig {
10+
devtools?: ViteConfigDevtoolsOptions
11+
}
12+
}
13+
14+
export interface ViteConfigDevtoolsOptions {
15+
/**
16+
* Disable client authentication.
17+
*
18+
* Beware that if you disable client authentication,
19+
* any browsers can connect to the devtools and access to your server and filesystem.
20+
* (including other devices, if you open server `host` option to LAN or WAN)
21+
*
22+
* @default true
23+
*/
24+
clientAuth?: boolean
925
}
1026

1127
export interface PluginWithDevTools extends Plugin {

0 commit comments

Comments
 (0)