feat(desktop): carry remote gateway headers through the connections registry, test probes, and Settings UI

Completes PR #74468 (remote gateway headers for Cloudflare Access, #74466)
against the v2 multi-connection registry that landed after the PR was
authored, and closes the review blockers:

- connection-registry: additive optional `headers` field on remote/cloud
  entries (normalized through the same forbidden-name filter, secret
  envelopes like `token`); inherited on edit, treated as dial material by
  connectionDialFieldsChanged, preserved by normalizeRegistry, and carried
  through migrateV1ToRegistry. v2 registries without the field load
  unchanged — no version bump.
- main.ts registry paths: connectRegistryBackend dials with the entry's
  headers (readiness probe, ticket mint, descriptor REST via
  getJsonForBackend/fetchJsonForBackend, registry ws-url minting with
  rememberRemoteWsHeaders so renderer upgrades get them injected).
- saveRegistryConnection encrypts incoming plaintext header values with the
  same safeStorage/allowPlainText seam as tokens; sanitizeRegistryConnection
  exposes only header NAMES to the renderer — values never cross IPC.
- Connection tests exercise the leg they validate: both
  hermes:connection-config:test and hermes:connections:test now send the
  configured headers on the HTTP status call, the ws-ticket mint, AND the
  live WebSocket probe (probeGatewayWebSocket grew an injectable `headers`
  option passed as the undici WebSocket constructor's second argument).
- Settings → Connections gains an "Extra gateway headers" editor for
  remote/cloud entries (name + secret value rows, stored values shown as
  saved-but-hidden, clearable), with i18n keys (en + zh; other locales fall
  back through defineLocale).
This commit is contained in:
Teknium
2026-08-16 19:15:18 -07:00
parent fcef62ef72
commit b711fd0513
12 changed files with 443 additions and 26 deletions
+3 -3
View File
@@ -148,9 +148,9 @@ terminal commands, and file operations run against the remote Hermes host, not
the computer displaying the Desktop UI.
Remote gateways that sit behind an access proxy may require extra headers on
every HTTP and WebSocket request. Until Settings exposes those fields, advanced
deployments can add a `headers` object to Desktop's Electron
`userData/connection.json` remote block:
every HTTP and WebSocket request. Configure them per connection in Settings →
Connections (Extra gateway headers), or add a `headers` object to Desktop's
Electron `userData/connection.json` remote block:
```json
{
+1 -1
View File
@@ -772,7 +772,6 @@ export {
modeIsRemoteLike,
normalizeRemoteBaseUrl,
normalizeRemoteHeaders,
remoteRequestMatchesBaseUrl,
normalizeSshConfig,
normAuthMode,
pathWithGlobalRemoteProfile,
@@ -782,6 +781,7 @@ export {
profileHasRemoteConnection,
profileRemoteOverride,
profileSshOverride,
remoteRequestMatchesBaseUrl,
resolveAuthMode,
resolveProfileBackendRoute,
resolveTestWsUrl,
@@ -603,3 +603,130 @@ test('connectionDialFieldsChanged: ssh routing fields recycle, kind change recyc
true
)
})
// --- remote gateway headers (Cloudflare Access etc., #74466 / PR #74468) ---
test('normalizeConnectionInput keeps filtered headers on remote/cloud, drops them elsewhere', () => {
const registry = emptyRegistry()
const remote = normalizeConnectionInput(
{
kind: 'remote',
label: 'CF box',
url: 'https://hermes.example.com',
authMode: 'token',
token: { enc: 'x' },
headers: {
'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' },
Authorization: { encoding: 'plain', value: 'blocked' }
}
},
registry
)
assert.deepEqual(remote.headers, {
'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' }
})
const ssh = normalizeConnectionInput(
{
kind: 'ssh',
label: 'Box',
host: 'box.lan',
headers: { 'CF-Access-Client-Id': { encoding: 'plain', value: 'id' } }
} as any,
registry
)
assert.equal((ssh as any).headers, undefined)
})
test('mergeConnectionInput inherits stored headers when the editor payload omits them', () => {
const stored = {
id: 'cf',
kind: 'remote' as const,
label: 'CF box',
url: 'https://hermes.example.com',
authMode: 'token' as const,
headers: { 'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' } }
}
const renamed = mergeConnectionInput({ id: 'cf', kind: 'remote', label: 'Renamed' }, stored)
assert.deepEqual(renamed.headers, stored.headers)
// An explicit headers payload (even empty) is authoritative — clearing works.
const cleared = mergeConnectionInput({ id: 'cf', kind: 'remote', label: 'CF box', headers: {} }, stored)
assert.deepEqual(cleared.headers, {})
})
test('connectionDialFieldsChanged: a header change recycles live backends', () => {
const before = {
id: 'cf',
kind: 'remote',
label: 'CF box',
url: 'https://hermes.example.com',
authMode: 'token',
token: { enc: 'x' },
headers: { 'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' } }
} as const
assert.equal(connectionDialFieldsChanged(before, { ...before }), false)
assert.equal(
connectionDialFieldsChanged(before, {
...before,
headers: { 'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'OTHER' } }
}),
true
)
assert.equal(connectionDialFieldsChanged(before, { ...before, headers: undefined }), true)
})
test('normalizeRegistry preserves stored headers on remote entries (v2 additive field)', () => {
const registry = normalizeRegistry({
version: REGISTRY_VERSION,
primary: 'cf',
connections: [
{ id: 'local', kind: 'local', label: 'This device' },
{
id: 'cf',
kind: 'remote',
label: 'CF box',
url: 'https://hermes.example.com',
authMode: 'token',
token: { enc: 'x' },
headers: {
'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' },
Cookie: { encoding: 'plain', value: 'blocked' }
}
}
]
})
const remote = registry.connections.find(c => c.id === 'cf')
assert.ok(remote)
assert.deepEqual(remote.headers, {
'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' }
})
})
test('migrateV1ToRegistry carries v1 remote headers into the registry entry', () => {
const registry = migrateV1ToRegistry({
mode: 'remote',
remote: {
url: 'https://hermes.example.com',
authMode: 'token',
token: { enc: 'x' },
headers: { 'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' } }
}
})
const remote = registry.connections.find(c => c.kind === 'remote')
assert.ok(remote)
assert.deepEqual(remote.headers, {
'CF-Access-Client-Id': { encoding: 'safeStorage', value: 'id' }
})
})
+42 -1
View File
@@ -31,6 +31,7 @@ import {
hostLabelFromBaseUrl,
modeIsRemoteLike,
normalizeRemoteBaseUrl,
normalizeRemoteHeaders,
normalizeSshConfig,
normAuthMode
} from './connection-config'
@@ -55,6 +56,11 @@ export interface RegistryConnection {
authMode?: 'oauth' | 'token'
/** remote: encrypted token envelope (opaque here; main.ts encrypts/decrypts). */
token?: unknown
/** remote/cloud: extra gateway headers (Cloudflare Access etc.). Secret
* envelopes, same shape as `token`; names pre-filtered through
* normalizeRemoteHeaders. Optional and additive — v2 registries written
* before this field keep loading unchanged. */
headers?: Record<string, unknown>
/** cloud: portal org slug/id the instance was discovered under. */
org?: string
/** ssh fields (normalizeSshConfig shapes). */
@@ -309,6 +315,7 @@ export interface ConnectionInput {
url?: string
authMode?: string
token?: unknown
headers?: Record<string, unknown>
org?: string
host?: string
user?: string
@@ -399,6 +406,18 @@ export function normalizeConnectionInput(input: ConnectionInput, registry: Conne
entry.token = input.token
}
// Extra gateway headers (access-proxy credentials) apply to any
// remote-shaped entry regardless of auth mode — Cloudflare Access sits in
// front of both token- and OAuth-gated gateways. Normalization drops
// transport-/Hermes-managed names; an empty result stores nothing.
if (input.headers !== undefined) {
const headers = normalizeRemoteHeaders(input.headers)
if (Object.keys(headers).length > 0) {
entry.headers = headers
}
}
const org = String(input.org || '').trim()
if (kind === 'cloud' && org) {
@@ -440,6 +459,10 @@ export function mergeConnectionInput(input: ConnectionInput, existing?: null | R
inherit('keyPath')
inherit('remoteHermesPath')
inherit('remoteProfile')
// Headers inherit like other dial fields: an edit payload that omits the
// field keeps the stored set; an explicit payload (even {}) is
// authoritative so the editor can clear them.
inherit('headers')
// ssh user/port: the editor shows ONE composite host field (user@host:port),
// and normalizeSshConfig gives explicit user/port fields precedence over the
@@ -489,7 +512,13 @@ export function connectionDialFieldsChanged(before: RegistryConnection, after: R
// Token envelopes are opaque here (main.ts encrypts). An edit that carries
// no new token inherits the stored envelope verbatim, so structural
// equality is exact for the label-only case.
return JSON.stringify(before.token ?? null) !== JSON.stringify(after.token ?? null)
if (JSON.stringify(before.token ?? null) !== JSON.stringify(after.token ?? null)) {
return true
}
// Headers are dial material too: a changed access-proxy credential means
// every open socket/backend authenticated with the OLD set.
return JSON.stringify(before.headers ?? null) !== JSON.stringify(after.headers ?? null)
}
// ── Registry-level operations (all pure: return a new registry) ────────────
@@ -564,6 +593,12 @@ export function normalizeRegistry(raw: unknown): ConnectionRegistry {
clean.token = entry.token
}
const storedHeaders = normalizeRemoteHeaders(entry.headers)
if (Object.keys(storedHeaders).length > 0) {
clean.headers = storedHeaders
}
const org = String(entry.org || '').trim()
if (kind === 'cloud' && org) {
@@ -646,6 +681,12 @@ export function migrateV1ToRegistry(v1: unknown): ConnectionRegistry {
entry.token = block.token
}
const v1Headers = normalizeRemoteHeaders(block.headers)
if (Object.keys(v1Headers).length > 0) {
entry.headers = v1Headers
}
const org = String(block.org || '').trim()
if (kind === 'cloud' && org) {
@@ -132,3 +132,48 @@ test('probe reports unavailable when no WebSocket implementation is provided', a
assert.equal(result.ok, false)
assert.match(result.reason, /not available/)
})
test('probe passes extra upgrade headers to the WebSocket constructor (Cloudflare Access)', async () => {
const { FakeWs, instances } = makeFakeWs()
const seen: any[] = []
class HeaderFakeWs extends FakeWs {
constructor(url, options?) {
super(url)
seen.push(options)
}
}
const headers = { 'CF-Access-Client-Id': 'id', 'CF-Access-Client-Secret': 'secret' }
const pending = probeGatewayWebSocket('wss://x/api/ws?token=t', {
WebSocketImpl: HeaderFakeWs,
headers,
readyGraceMs: 1
})
instances[0].emit('open', {})
instances[0].emit('message', {})
const result = await pending
assert.equal(result.ok, true)
assert.deepEqual(seen[0], { headers })
// No headers → the constructor is called with the URL alone (browser-safe).
const bare = makeFakeWs()
const seenBare: any[] = []
class BareWs extends bare.FakeWs {
constructor(url, options?) {
super(url)
seenBare.push(options)
}
}
const barePending = probeGatewayWebSocket('wss://x/api/ws?token=t', { WebSocketImpl: BareWs, readyGraceMs: 1 })
bare.instances[0].emit('open', {})
bare.instances[0].emit('message', {})
await barePending
assert.equal(seenBare[0], undefined)
})
+11 -1
View File
@@ -44,11 +44,21 @@ function probeGatewayWebSocket<T>(
WebSocketImpl?: any
connectTimeoutMs?: number
readyGraceMs?: number
/** Extra upgrade-request headers (access-proxy credentials such as
* Cloudflare Access service tokens). Passed as the non-standard second
* constructor argument `{ headers }` that Node's (undici) WebSocket —
* the impl the Electron main process supplies — understands. Without
* this the probe would dial the bare upgrade and fail against a gateway
* the renderer (whose upgrade gets headers injected via
* webRequest.onBeforeSendHeaders) can actually reach — the exact
* false-negative the probe exists to prevent. */
headers?: Record<string, string>
} = {}
) {
const WebSocketImpl = options.WebSocketImpl
const connectTimeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS
const readyGraceMs = options.readyGraceMs ?? DEFAULT_READY_GRACE_MS
const headers = options.headers && Object.keys(options.headers).length > 0 ? options.headers : null
if (typeof WebSocketImpl !== 'function') {
return Promise.resolve({
@@ -94,7 +104,7 @@ function probeGatewayWebSocket<T>(
}
try {
socket = new WebSocketImpl(wsUrl)
socket = headers ? new WebSocketImpl(wsUrl, { headers }) : new WebSocketImpl(wsUrl)
} catch (error) {
finish({
ok: false,
+109 -18
View File
@@ -7826,6 +7826,54 @@ function decryptRemoteHeaders(headers) {
return out
}
/**
* Turn an editor payload of remote gateway headers into stored secret
* envelopes. The payload map is authoritative (a name missing from it is
* cleared); per-name values are:
* - non-empty string → new plaintext value, encrypted like a token
* - null → keep the currently stored envelope for that name
* (the editor shows a set-but-hidden secret)
* - envelope object → stored verbatim (hand-edited import path)
* Name filtering (forbidden/managed headers) happens in
* normalizeRemoteHeaders at the registry/config layer.
*/
function encryptIncomingRemoteHeaders(raw, existing, options: { allowPlainText?: boolean } = {}) {
const out = {}
const stored = normalizeRemoteHeaders(existing)
for (const [name, value] of Object.entries(raw || {})) {
const key = String(name || '').trim()
if (!key) {
continue
}
if (typeof value === 'string') {
const trimmed = value.trim()
if (trimmed) {
out[key] = encryptDesktopSecret(trimmed, { allowPlainText: options.allowPlainText === true })
}
continue
}
if (value === null) {
if (stored[key]) {
out[key] = stored[key]
}
continue
}
if (value && typeof value === 'object') {
out[key] = value
}
}
return out
}
function rememberRemoteWsHeaders(wsUrl, headers = {}) {
if (!wsUrl || Object.keys(headers).length === 0) {
return
@@ -8129,13 +8177,17 @@ function writeDesktopConnectionsRegistry(registry) {
* sanitizeDesktopConnectionConfig.
*/
function sanitizeRegistryConnection(entry) {
const { token, ...rest } = entry
const { token, headers, ...rest } = entry
const decrypted = decryptDesktopSecret(token)
return {
...rest,
tokenSet: Boolean(decrypted),
tokenPreview: tokenPreview(decrypted)
tokenPreview: tokenPreview(decrypted),
// Header VALUES are secrets (Cloudflare Access client secrets etc.) and
// never cross the IPC boundary — the renderer only needs the names to
// render the edit form.
headerNames: headers && typeof headers === 'object' ? Object.keys(headers) : []
}
}
@@ -8181,7 +8233,18 @@ async function saveRegistryConnection(input: any = {}) {
encryptSecret: encryptDesktopSecret
})
const merged = mergeConnectionInput({ ...input, token }, existing)
// Extra gateway headers arrive as plaintext strings from the editor (or
// envelopes from a hand-edited import). Encrypt plaintext values the same
// way tokens are stored; a null/empty value drops that header. An absent
// `headers` field inherits the stored set via mergeConnectionInput.
const headers =
input.headers && typeof input.headers === 'object'
? encryptIncomingRemoteHeaders(input.headers, existing?.headers, {
allowPlainText: input.allowPlainTextToken
})
: input.headers
const merged = mergeConnectionInput({ ...input, token, headers }, existing)
const entry = normalizeConnectionInput(merged, registry)
// Token-auth remotes must actually have a token to be dialable. OAuth and
@@ -9209,10 +9272,12 @@ async function testDesktopConnectionConfig(input: any = {}) {
let baseUrl
let token = null
let authMode = 'token'
let testHeaders = {}
if (wantRemote && block?.url) {
baseUrl = normalizeRemoteBaseUrl(block.url)
authMode = normAuthMode(block.authMode)
testHeaders = decryptRemoteHeaders(block.headers)
if (authMode !== 'oauth') {
token = decryptDesktopSecret(block.token)
@@ -9222,9 +9287,10 @@ async function testDesktopConnectionConfig(input: any = {}) {
baseUrl = remote.baseUrl
token = remote.token
authMode = normAuthMode(remote.authMode)
testHeaders = remote.headers || {}
}
const status = (await fetchJson(`${baseUrl}/api/status`, token, { timeoutMs: 8_000 })) as any
const status = (await fetchJson(`${baseUrl}/api/status`, token, { timeoutMs: 8_000, headers: testHeaders })) as any
// The HTTP status check above proves the backend is reachable, but the chat
// surface only works once the renderer's live WebSocket to ``/api/ws``
@@ -9233,13 +9299,15 @@ async function testDesktopConnectionConfig(input: any = {}) {
// false-positive "reachable" while the real boot still failed with "Could not
// connect to Hermes gateway". Mirror the renderer's connect here so the test
// reflects the full path the app actually uses.
const wsUrl = await resolveTestWsUrl(baseUrl, authMode, token, { mintTicket: mintGatewayWsTicket })
const wsUrl = await resolveTestWsUrl(baseUrl, authMode, token, {
mintTicket: url => mintGatewayWsTicket(url, testHeaders)
})
// Skip the WS leg only when the runtime genuinely lacks a WebSocket (so an
// older Electron/Node never fails the test spuriously); Electron's main
// process ships a global WebSocket on every supported version.
if (wsUrl && typeof globalThis.WebSocket === 'function') {
const probe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket })
const probe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket, headers: testHeaders })
if (!probe.ok) {
throw new Error(
@@ -9630,10 +9698,12 @@ async function connectRegistryBackend(source, profile, key, poolEntry) {
token,
`registry:${source.id}`,
undefined,
source.kind === 'cloud' ? 'cloud' : 'url'
source.kind === 'cloud' ? 'cloud' : 'url',
undefined,
source.headers
)
await waitForHermes(connection.baseUrl, connection.token, undefined, connection.authMode)
await waitForHermes(connection.baseUrl, connection.token, undefined, connection.authMode, connection.headers)
poolEntry.remoteBaseUrl = connection.baseUrl
return {
@@ -12308,6 +12378,7 @@ ipcMain.handle('hermes:connections:test', async (_event, id) => {
let baseUrl
let token = null
let authMode = 'token'
let testHeaders = {}
if (entry.kind === 'local') {
const local = await startHermes()
@@ -12317,6 +12388,7 @@ ipcMain.handle('hermes:connections:test', async (_event, id) => {
} else {
baseUrl = normalizeRemoteBaseUrl(entry.url)
authMode = normAuthMode(entry.authMode)
testHeaders = decryptRemoteHeaders(entry.headers)
if (authMode !== 'oauth') {
token = decryptDesktopSecret(entry.token)
@@ -12327,14 +12399,16 @@ ipcMain.handle('hermes:connections:test', async (_event, id) => {
}
}
const status = (await fetchJson(`${baseUrl}/api/status`, token, { timeoutMs: 8_000 })) as any
const status = (await fetchJson(`${baseUrl}/api/status`, token, { timeoutMs: 8_000, headers: testHeaders })) as any
// Same HTTP+WS two-leg check as testDesktopConnectionConfig: HTTP alone is
// a false positive when the WebSocket leg is blocked.
const wsUrl = await resolveTestWsUrl(baseUrl, authMode, token, { mintTicket: mintGatewayWsTicket })
const wsUrl = await resolveTestWsUrl(baseUrl, authMode, token, {
mintTicket: url => mintGatewayWsTicket(url, testHeaders)
})
if (wsUrl && typeof globalThis.WebSocket === 'function') {
const probe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket })
const probe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket, headers: testHeaders })
if (!probe.ok) {
throw new Error(
@@ -12412,11 +12486,16 @@ ipcMain.handle('hermes:gateway:ws-url-for', async (_event, payload) => {
const connection: any = await ensureRegistryBackend(connectionId, profile)
if (connection.authMode === 'oauth') {
const ticket = await mintGatewayWsTicket(connection.baseUrl)
const ticket = await mintGatewayWsTicket(connection.baseUrl, connection.headers)
const wsUrl = buildGatewayWsUrlWithTicket(connection.baseUrl, ticket)
return registryGatewayWsUrl(connection, buildGatewayWsUrlWithTicket(connection.baseUrl, ticket))
rememberRemoteWsHeaders(wsUrl, connection.headers)
return registryGatewayWsUrl(connection, wsUrl)
}
rememberRemoteWsHeaders(connection.wsUrl, connection.headers)
return registryGatewayWsUrl(connection, connection.wsUrl)
})
})
@@ -12487,10 +12566,10 @@ async function getJsonForBackend(descriptor, path, opts: any = {}) {
const url = `${descriptor.baseUrl}${path}`
if (descriptor.authMode === 'oauth') {
return fetchJsonViaOauthSession(url, opts)
return fetchJsonViaOauthSession(url, requestOptionsWithHeaders(opts, descriptor.headers || {}))
}
return fetchJson(url, descriptor.token, opts)
return fetchJson(url, descriptor.token, requestOptionsWithHeaders(opts, descriptor.headers || {}))
}
// Any-method REST call against a resolved backend descriptor — the descriptor
@@ -12514,17 +12593,29 @@ async function fetchJsonForBackend(
const nativeAt = await ensureNativeAccessToken(descriptor.baseUrl).catch(() => null)
if (nativeAt) {
return fetchJson(url, null, { method: opts.method, body: opts.body, timeoutMs: opts.timeoutMs, bearer: nativeAt })
return fetchJson(url, null, {
method: opts.method,
body: opts.body,
timeoutMs: opts.timeoutMs,
bearer: nativeAt,
headers: descriptor.headers
})
}
return fetchJsonViaOauthSession(url, { method: opts.method, body: opts.body, timeoutMs: opts.timeoutMs })
return fetchJsonViaOauthSession(url, {
method: opts.method,
body: opts.body,
timeoutMs: opts.timeoutMs,
headers: descriptor.headers
})
}
return fetchJson(url, descriptor.token, {
method: opts.method,
body: opts.body,
upload: opts.upload,
timeoutMs: opts.timeoutMs
timeoutMs: opts.timeoutMs,
headers: descriptor.headers
})
}
@@ -33,6 +33,12 @@ interface EditorState {
token: string
host: string
keyPath: string
// Extra gateway headers (access proxies such as Cloudflare Access).
// `value: ''` on a row that came from storage means "keep the saved
// secret" (sent as null); a typed value replaces it; a removed row clears
// it. `stored` marks rows hydrated from headerNames so the placeholder can
// say "saved" instead of demanding a value.
headers: { name: string; stored: boolean; value: string }[]
}
function editorFromConnection(conn: DesktopRegistryConnection): EditorState {
@@ -49,12 +55,13 @@ function editorFromConnection(conn: DesktopRegistryConnection): EditorState {
// parsed host string — sending stored user/port alongside a retyped host
// would silently resurrect the old values.
host: conn.host ? `${conn.user ? `${conn.user}@` : ''}${conn.host}${conn.port ? `:${conn.port}` : ''}` : '',
keyPath: conn.keyPath || ''
keyPath: conn.keyPath || '',
headers: (conn.headerNames || []).map(name => ({ name, stored: true, value: '' }))
}
}
function emptyEditor(kind: DesktopConnectionKind): EditorState {
return { id: null, kind, label: '', url: '', authMode: 'token', token: '', host: '', keyPath: '' }
return { id: null, kind, label: '', url: '', authMode: 'token', token: '', host: '', keyPath: '', headers: [] }
}
/**
@@ -129,6 +136,19 @@ export function ConnectionsSettings() {
if (allowPlainTextToken) {
payload.allowPlainTextToken = true
}
// Authoritative header map: typed value → new secret; empty value on
// a stored row → null (keep saved secret); a removed row is simply
// absent, which clears it server-side.
const headerEntries = editor.headers
.map(row => ({ name: row.name.trim(), stored: row.stored, value: row.value.trim() }))
.filter(row => row.name)
if (headerEntries.length > 0 || editor.headers.length === 0) {
payload.headers = Object.fromEntries(
headerEntries.map(row => [row.name, row.value ? row.value : row.stored ? null : ''])
)
}
} else if (editor.kind === 'ssh') {
// The composite host string (user@host:port) is the single source
// of truth — never send separate user/port (see editorFromConnection).
@@ -431,6 +451,60 @@ export function ConnectionsSettings() {
</>
)}
{(editor.kind === 'remote' || editor.kind === 'cloud') && (
<div className="grid gap-2">
<div>
<div className="text-sm font-medium">{s.headersTitle}</div>
<p className="mt-1 text-xs text-muted-foreground">{s.headersDesc}</p>
</div>
{editor.headers.map((row, index) => (
<div className="flex items-center gap-2" key={index}>
<Input
className="flex-1"
onChange={e =>
setEditor({
...editor,
headers: editor.headers.map((h, i) => (i === index ? { ...h, name: e.target.value } : h))
})
}
placeholder="CF-Access-Client-Id"
value={row.name}
/>
<Input
className="flex-1"
onChange={e =>
setEditor({
...editor,
headers: editor.headers.map((h, i) => (i === index ? { ...h, value: e.target.value } : h))
})
}
placeholder={row.stored ? s.headerValueSaved : s.headerValuePlaceholder}
type="password"
value={row.value}
/>
<Button
onClick={() => setEditor({ ...editor, headers: editor.headers.filter((_, i) => i !== index) })}
size="sm"
variant="ghost"
>
{s.headerRemove}
</Button>
</div>
))}
<div>
<Button
onClick={() =>
setEditor({ ...editor, headers: [...editor.headers, { name: '', stored: false, value: '' }] })
}
size="sm"
variant="outline"
>
{s.headerAdd}
</Button>
</div>
</div>
)}
{editor.kind === 'ssh' && (
<ListRow
action={
+9
View File
@@ -754,6 +754,10 @@ export interface DesktopRegistryConnection {
remoteProfile?: string
tokenSet: boolean
tokenPreview: null | string
// Names of the stored extra gateway headers (Cloudflare Access etc.);
// header VALUES are secrets and never cross the IPC boundary. Optional so
// fixtures/older payloads without the field remain valid.
headerNames?: string[]
}
export interface DesktopConnectionsRegistry {
@@ -776,6 +780,11 @@ export interface DesktopRegistryConnectionInput {
// Plaintext token to store (encrypted at rest); omit to keep the saved one.
token?: string
allowPlainTextToken?: boolean
// Extra gateway headers for remote/cloud entries (access proxies such as
// Cloudflare Access). The map is authoritative when present: name → new
// plaintext value (encrypted at rest), or null to keep the stored secret
// for that name. Omit the field entirely to keep the saved set unchanged.
headers?: Record<string, null | string>
org?: string
host?: string
user?: string
+7
View File
@@ -685,6 +685,13 @@ export const en: Translations = {
labelPlaceholder: 'Homelab',
urlTitle: 'Gateway URL',
sshHostTitle: 'SSH host',
headersTitle: 'Extra gateway headers',
headersDesc:
'Sent with every HTTP and WebSocket request to this gateway — for access proxies such as Cloudflare Access (CF-Access-Client-Id / CF-Access-Client-Secret). Values are stored encrypted. Headers Hermes manages (Authorization, Cookie, Host…) are ignored.',
headerValuePlaceholder: 'Value',
headerValueSaved: 'Saved — leave blank to keep',
headerAdd: 'Add header',
headerRemove: 'Remove',
save: 'Save connection',
saving: 'Saving…',
cancel: 'Cancel',
+6
View File
@@ -574,6 +574,12 @@ export interface Translations {
labelPlaceholder: string
urlTitle: string
sshHostTitle: string
headersTitle: string
headersDesc: string
headerValuePlaceholder: string
headerValueSaved: string
headerAdd: string
headerRemove: string
save: string
saving: string
cancel: string
+7
View File
@@ -889,6 +889,13 @@ export const zh: Translations = {
labelPlaceholder: '家庭服务器',
urlTitle: '网关 URL',
sshHostTitle: 'SSH 主机',
headersTitle: '额外网关请求头',
headersDesc:
'随发往此网关的每个 HTTP 和 WebSocket 请求一起发送——用于 Cloudflare Access 等访问代理(CF-Access-Client-Id / CF-Access-Client-Secret)。值加密存储。由 Hermes 管理的请求头(Authorization、Cookie、Host 等)会被忽略。',
headerValuePlaceholder: '值',
headerValueSaved: '已保存——留空以保留',
headerAdd: '添加请求头',
headerRemove: '移除',
save: '保存连接',
saving: '保存中…',
cancel: '取消',