Skip to content

Commit bdcc683

Browse files
authored
refactor(gateway): retire the Control UI device-auth migration window (#124667)
* refactor(gateway): delete the retired Control UI device-auth migration window The one-time remediation window for the retired gateway.controlUi.dangerouslyDisableDeviceAuth break-glass threaded a pending state machine through the connect pipeline, startup bootstrap, lifecycle, request context, device management, security audit, the hello frame, and a Control UI banner flow — steady-state runtime carrying a retired-shape shim the architecture reserves for doctor. The window is closed: the retired key is now fully inert, doctor still detects and removes it, and a browser that never completed the migration pairs through the normal device flow (one approval, no data loss). Deleted with it: the config-machine-state import of the legacy flag, the hello deviceAuthMigration field (optional; clients validate envelopes only, so older gateways emitting it stay compatible), the migration-bound device management authz states, the requireNoPairingCapableOperator approval mode, the effective-operator pairing event emitter whose only subscriber was the migration completion, and the Control UI banner, loader, overlay wiring, i18n strings, and e2e scenario support. Swift and Kotlin protocol models regenerated. Live-verified on an isolated gateway with the retired key present in config: clean boot with no migration warning, silent CLI pairing and silent local scope widening unaffected, and doctor reporting the key as retired-and-inert. Net -1111 production LOC. * fix(ci): finish migration-window cleanup surfaced by the gates The doctor migration for the retired key kept its "Preserved for remediation" change text and describe; both now state plain removal, with the retired tests updated. peekStoredDeviceIdentityId lost its only production consumer with the deleted banner loader and is removed with its test mock. Also fixes the unrelated no-unnecessary-boolean-literal-compare lint break that #124636 landed on main in scripts/check-changed.mts (truthiness is equivalent for the boolean-or-undefined TTY probe). * fix(ui): drop the retired-key device-auth reader from the security summary Review findings on the migration-window removal: the Control UI security summary still derived its "Device auth" row from the retired dangerouslyDisableDeviceAuth key, rendering device auth as disabled on configurations that merely retain the inert key. Device auth is now unconditionally enforced, so the row and its derivation are removed rather than pinned to a constant. The build-admission test also tracks and removes its temporary device-identity databases after each run.
1 parent fa29984 commit bdcc683

56 files changed

Lines changed: 163 additions & 2701 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ public struct HelloOk: Codable, Sendable {
12381238
public let controluitabs: [[String: AnyCodable]]?
12391239
public let controluiwidgetkinds: [[String: AnyCodable]]?
12401240
public let pluginsurfaceurls: [String: AnyCodable]?
1241-
public let deviceauthmigration: [String: AnyCodable]?
12421241
public let auth: [String: AnyCodable]
12431242
public let policy: [String: AnyCodable]
12441243

@@ -1251,7 +1250,6 @@ public struct HelloOk: Codable, Sendable {
12511250
controluitabs: [[String: AnyCodable]]? = nil,
12521251
controluiwidgetkinds: [[String: AnyCodable]]? = nil,
12531252
pluginsurfaceurls: [String: AnyCodable]? = nil,
1254-
deviceauthmigration: [String: AnyCodable]? = nil,
12551253
auth: [String: AnyCodable],
12561254
policy: [String: AnyCodable])
12571255
{
@@ -1263,7 +1261,6 @@ public struct HelloOk: Codable, Sendable {
12631261
self.controluitabs = controluitabs
12641262
self.controluiwidgetkinds = controluiwidgetkinds
12651263
self.pluginsurfaceurls = pluginsurfaceurls
1266-
self.deviceauthmigration = deviceauthmigration
12671264
self.auth = auth
12681265
self.policy = policy
12691266
}
@@ -1277,7 +1274,6 @@ public struct HelloOk: Codable, Sendable {
12771274
case controluitabs = "controlUiTabs"
12781275
case controluiwidgetkinds = "controlUiWidgetKinds"
12791276
case pluginsurfaceurls = "pluginSurfaceUrls"
1280-
case deviceauthmigration = "deviceAuthMigration"
12811277
case auth
12821278
case policy
12831279
}

‎docs/gateway/security/audit-checks.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ exhaustive):
5454
| `gateway.control_ui.allowed_origins_required` | critical | Non-loopback Control UI without explicit browser-origin allowlist | `gateway.controlUi.allowedOrigins` | no |
5555
| `gateway.control_ui.allowed_origins_wildcard` | warn/critical | `allowedOrigins=["*"]` disables browser-origin allowlisting | `gateway.controlUi.allowedOrigins` | no |
5656
| `gateway.control_ui.host_header_origin_fallback` | warn/critical | Enables Host-header origin fallback (DNS rebinding hardening downgrade) | `gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback` | no |
57-
| `gateway.control_ui.device_auth_disabled` | critical | Retired device-auth bypass migration still permits remediation access | complete **Secure this browser** pairing (`gateway.controlUi.deviceAuthMigration` state) | no |
5857
| `gateway.real_ip_fallback_enabled` | warn/critical | Trusting `X-Real-IP` fallback can enable source-IP spoofing via proxy misconfig | `gateway.allowRealIpFallback`, `gateway.trustedProxies` | no |
5958
| `gateway.token_too_short` | warn | Short shared token is easier to brute force | `gateway.auth.token` | no |
6059
| `gateway.auth_no_rate_limit` | warn | Exposed auth without rate limiting increases brute-force risk | `gateway.auth.rateLimit` | no |

‎docs/gateway/security/index.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ Trusted proxy headers do not make node device pairing automatically trusted - `g
691691
The Control UI needs a secure context (HTTPS or localhost) to generate device identity.
692692

693693
- Token/password auth does not replace browser device identity over remote plain HTTP. Use HTTPS (for example, Tailscale Serve) or open the UI on `127.0.0.1` from the Gateway host.
694-
- `gateway.controlUi.dangerouslyDisableDeviceAuth`: retired break-glass input. Older configs preserve authenticated, pairing-only Control UI access for remediation until a browser reopened over HTTPS or localhost completes the bounded, explicit self-pairing migration; do not add it to current config.
694+
- `gateway.controlUi.dangerouslyDisableDeviceAuth`: retired break-glass input, now fully inert. Control UI browsers pair through the normal device flow; `openclaw doctor --fix` removes the legacy key.
695695
- Separately, successful `gateway.auth.mode: "trusted-proxy"` authentication can admit **operator** Control UI sessions without device identity. This does not extend to node-role Control UI sessions.
696696
697697
### Insecure/dangerous flags
@@ -701,7 +701,6 @@ The Control UI needs a secure context (HTTPS or localhost) to generate device id
701701
<AccordionGroup>
702702
<Accordion title="Flags tracked by the audit today">
703703
- `gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback=true`
704-
- pending Control UI device-auth migration imported from retired `gateway.controlUi.dangerouslyDisableDeviceAuth=true`
705704
- `security.audit.suppressions configured (<count>)`
706705
- `hooks.gmail.allowUnsafeExternalContent=true`
707706
- `hooks.mappings[<index>].allowUnsafeExternalContent=true`
@@ -713,7 +712,7 @@ The Control UI needs a secure context (HTTPS or localhost) to generate device id
713712
<Accordion title="All dangerous*/dangerously* keys in the config schema">
714713
Control UI and browser:
715714
- `gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback`
716-
- `gateway.controlUi.dangerouslyDisableDeviceAuth` (retired upgrade input)
715+
- `gateway.controlUi.dangerouslyDisableDeviceAuth` (retired, inert)
717716
- `browser.ssrfPolicy.dangerouslyAllowPrivateNetwork`
718717

719718
Channel name-matching (bundled and plugin channels; also per `accounts.<accountId>` where applicable):

‎docs/gateway/trusted-proxy-auth.md‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ Scope implications:
209209

210210
- Device-less Control UI WebSocket sessions cannot self-declare permissions. OpenClaw clears their requested scope list to `[]`, then applies any matching server-side `identityScopes` grant after proxy identity verification.
211211
- If methods fail with `missing scope` after a successful WebSocket connect, use HTTPS so the browser can generate device identity and complete pairing. See [Control UI insecure HTTP](/web/control-ui#insecure-http).
212-
- Older configs that still contain the retired
213-
`gateway.controlUi.dangerouslyDisableDeviceAuth=true` key use the bounded
214-
[Control UI upgrade migration](/web/control-ui#device-pairing-first-connection).
215212

216213
Reverse-proxy scope capping: if your proxy sends `x-openclaw-scopes` on the Control UI WebSocket upgrade request, OpenClaw caps device enrollment or upgrade requests and the final union of device-authorized and identity-granted session scopes. This header does not grant scopes; it only narrows authority. When `deviceAutoApprove.enabled` is true, the cap also limits the persistent device grant written by [automatic device approval](#automatic-device-approval).
217214

@@ -542,7 +539,7 @@ Separate, non-trusted-proxy-specific findings also apply whenever Control UI is
542539

543540
- For Control UI, use HTTPS so the browser can generate device identity and complete pairing.
544541
- For custom automation, use device identity/pairing, the reserved direct-local `gateway-client` backend helper path, or [admin HTTP RPC](/plugins/admin-http-rpc).
545-
- Do not add the retired `gateway.controlUi.dangerouslyDisableDeviceAuth` key to current config. Older installs use the one-time self-pairing migration automatically.
542+
- Do not add the retired `gateway.controlUi.dangerouslyDisableDeviceAuth` key to current config; it is ignored and `openclaw doctor --fix` removes it.
546543

547544
</Accordion>
548545
<Accordion title="WebSocket still failing">

‎docs/web/control-ui.md‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ Onboarding usually configures a gateway token for shared-secret auth. If the Gat
4949

5050
After gateway auth succeeds, connecting from a new browser or device usually requires a **one-time pairing approval**, shown as `disconnected (1008): pairing required`. On the Gateway host, `openclaw dashboard` is the preferred owner path: it opens a short-lived, single-use pairing link and leaves that exact signed browser with a durable administrator credential. Opening a fresh link in the same browser also repairs a previously limited credential; another browser profile cannot inherit or replay the grant.
5151

52-
<Warning>
53-
When upgrading directly from a release that used the retired
54-
`gateway.controlUi.dangerouslyDisableDeviceAuth=true` break-glass setting,
55-
OpenClaw keeps token/password- or trusted-proxy-authenticated Control UI access
56-
available for pairing-only remediation. If the browser is on plain HTTP and cannot create device identity,
57-
reopen it over HTTPS or localhost first. Then click **Secure this browser** in
58-
the warning banner. The Gateway returns to normal device-auth enforcement only
59-
after a signed browser pairs explicitly; it never creates or approves an
60-
identity for a device-less browser. The transition is not available when
61-
another operator device is already paired. Gateway startup and
62-
`openclaw doctor --fix` both report this migration explicitly instead of
63-
silently discarding the old key.
64-
</Warning>
65-
6652
<Steps>
6753
<Step title="List pending requests">
6854
```bash

‎packages/gateway-protocol/src/schema/frames.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ export const HelloOkSchema = closedObject({
127127
),
128128
),
129129
pluginSurfaceUrls: Type.Optional(Type.Record(NonEmptyString, NonEmptyString)),
130-
deviceAuthMigration: Type.Optional(
131-
closedObject({
132-
pending: Type.Literal(true),
133-
}),
134-
),
135130
auth: closedObject({
136131
deviceToken: Type.Optional(NonEmptyString),
137132
recoveryMigrationAllowed: Type.Optional(Type.Literal(true)),

‎src/commands/doctor/shared/legacy-config-migrations.runtime.gateway.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const GATEWAY_WEBCHAT_RULE: LegacyConfigRule = {
3737
const CONTROL_UI_DEVICE_AUTH_MIGRATION_RULE: LegacyConfigRule = {
3838
path: ["gateway", "controlUi", "dangerouslyDisableDeviceAuth"],
3939
message:
40-
'gateway.controlUi.dangerouslyDisableDeviceAuth is retired. OpenClaw will preserve authenticated, pairing-only access for remediation, remove the legacy key, and prompt you to reopen the Control UI over HTTPS or localhost before clicking Secure this browser. Run "openclaw doctor --fix".',
40+
'gateway.controlUi.dangerouslyDisableDeviceAuth is retired and ignored. Control UI browsers pair through the normal device flow; run "openclaw doctor --fix" to remove the legacy key.',
4141
match: (value) => typeof value === "boolean",
4242
};
4343

@@ -69,21 +69,16 @@ function escapeControlForLog(value: string): string {
6969
export const LEGACY_CONFIG_MIGRATIONS_RUNTIME_GATEWAY: LegacyConfigMigrationSpec[] = [
7070
defineLegacyConfigMigration({
7171
id: "gateway.control-ui-device-auth-bypass->pairing-migration",
72-
describe: "Convert the retired Control UI device-auth bypass into explicit pairing",
72+
describe: "Remove the retired Control UI device-auth bypass",
7373
legacyRules: [CONTROL_UI_DEVICE_AUTH_MIGRATION_RULE],
7474
apply: (raw, changes) => {
7575
const gateway = getRecord(raw.gateway);
7676
const controlUi = getRecord(gateway?.controlUi);
7777
if (!controlUi || !Object.hasOwn(controlUi, "dangerouslyDisableDeviceAuth")) {
7878
return;
7979
}
80-
const migrationRequired = controlUi.dangerouslyDisableDeviceAuth === true;
8180
delete controlUi.dangerouslyDisableDeviceAuth;
82-
changes.push(
83-
migrationRequired
84-
? "Preserved the retired Control UI device-auth bypass for remediation. Reopen the Control UI over HTTPS or localhost, then click Secure this browser."
85-
: "Removed disabled gateway.controlUi.dangerouslyDisableDeviceAuth legacy config.",
86-
);
81+
changes.push("Removed retired gateway.controlUi.dangerouslyDisableDeviceAuth legacy config.");
8782
},
8883
}),
8984
defineLegacyConfigMigration({

‎src/commands/doctor/shared/legacy-config-migrations.runtime.retired.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ describe("retired runtime config migrations", () => {
209209

210210
it.each([
211211
[
212-
"uses a dedicated, actionable migration for the retired device-auth bypass",
212+
"removes the retired device-auth bypass when it was enabled",
213213
true,
214-
"Preserved the retired Control UI device-auth bypass for remediation. Reopen the Control UI over HTTPS or localhost, then click Secure this browser.",
214+
"Removed retired gateway.controlUi.dangerouslyDisableDeviceAuth legacy config.",
215215
],
216216
[
217-
"removes a disabled retired device-auth bypass without requiring pairing",
217+
"removes a disabled retired device-auth bypass",
218218
false,
219-
"Removed disabled gateway.controlUi.dangerouslyDisableDeviceAuth legacy config.",
219+
"Removed retired gateway.controlUi.dangerouslyDisableDeviceAuth legacy config.",
220220
],
221221
] as const)("%s", (_name, bypassEnabled, expectedChange) => {
222222
const migration = LEGACY_CONFIG_MIGRATIONS_RUNTIME_GATEWAY.find(
@@ -234,7 +234,7 @@ describe("retired runtime config migrations", () => {
234234
expect(raw).not.toHaveProperty("gateway.controlUi.dangerouslyDisableDeviceAuth");
235235
expect(changes).toEqual([expectedChange]);
236236
if (bypassEnabled) {
237-
expect(migration?.legacyRules?.[0]?.message).toContain("reopen the Control UI over HTTPS");
237+
expect(migration?.legacyRules?.[0]?.message).toContain("retired and ignored");
238238
}
239239
});
240240

‎src/gateway/server-kernel-request-runtime.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ export async function prepareGatewayKernelRequestRuntime(params: {
6060
watchNodeHttpRuntime,
6161
sharedGatewaySessionGenerationState,
6262
resolveSharedGatewaySessionGenerationForRuntimeSnapshot,
63-
completeControlUiDeviceAuthMigrationForEffectiveOperator,
64-
claimControlUiDeviceAuthMigration,
65-
releaseControlUiDeviceAuthMigrationClaim,
6663
nodeRegistry,
6764
nodeDesktopService,
6865
workerEnvironmentService,
@@ -161,12 +158,6 @@ export async function prepareGatewayKernelRequestRuntime(params: {
161158
clients,
162159
});
163160
},
164-
completeControlUiDeviceAuthMigration:
165-
completeControlUiDeviceAuthMigrationForEffectiveOperator,
166-
claimControlUiDeviceAuthMigration: (deviceId: string) =>
167-
claimControlUiDeviceAuthMigration(deviceId, { env: process.env }),
168-
releaseControlUiDeviceAuthMigrationClaim: (deviceId: string) =>
169-
releaseControlUiDeviceAuthMigrationClaim(deviceId, { env: process.env }),
170161
nodeRegistry,
171162
...(nodeDesktopService ? { nodeDesktopService } : {}),
172163
...(workerEnvironmentService ? { workerEnvironmentService } : {}),

‎src/gateway/server-lifecycle.ts‎

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import { getTotalPendingReplies } from "../auto-reply/reply/dispatcher-registry.
44
import { listLoadedChannelPlugins } from "../channels/plugins/registry-loaded.js";
55
import type { ChannelId } from "../channels/plugins/types.public.js";
66
import { getRuntimeConfig } from "../config/io.js";
7-
import {
8-
onEffectiveOperatorDevicePaired,
9-
type EffectiveOperatorDeviceIdentity,
10-
} from "../infra/device-pairing.js";
117
import { upsertPresence } from "../infra/system-presence.js";
128
import { startDiagnosticHeartbeat, stopDiagnosticHeartbeat } from "../logging/diagnostic.js";
139
import type { createSubsystemLogger } from "../logging/subsystem.js";
1410
import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js";
1511
import { clearSecretsRuntimeSnapshotState } from "../secrets/runtime-state.js";
16-
import { roleScopesAllow } from "../shared/operator-scope-compat.js";
1712
import {
1813
recordRemoteNodeInfo,
1914
removeRemoteNodeInfo,
@@ -29,10 +24,7 @@ import { createGatewayCronReconciliation } from "./server-cron-reconciled.js";
2924
import { applyGatewayLaneConcurrency, resolveGatewayLaneConcurrency } from "./server-lanes.js";
3025
import { createGatewayServerLiveState } from "./server-live-state.js";
3126
import type { GatewayRequestContext } from "./server-methods/types.js";
32-
import {
33-
type GatewayCloseOptions,
34-
shouldRetainControlUiDeviceAuthMigrationSession,
35-
} from "./server-public.js";
27+
import type { GatewayCloseOptions } from "./server-public.js";
3628
import type { prepareGatewayKernelState } from "./server-runtime-state-prepare.js";
3729
import type { GatewayShutdownRuntime } from "./server-shutdown.runtime.js";
3830
import {
@@ -57,8 +49,6 @@ export async function prepareGatewayLifecycle(params: {
5749
const { runtime, port, log, logCron, diagnosticsEnabled, shutdownRuntime } = params;
5850
const {
5951
minimalTestGateway,
60-
controlUiDeviceAuthMigration,
61-
completeControlUiDeviceAuthMigration,
6252
workerGatewayEndpoint,
6353
transportBridge,
6454
sessionMessageSubscribers,
@@ -95,51 +85,6 @@ export async function prepareGatewayLifecycle(params: {
9585
bindDeviceNodeControl,
9686
workerPlacementRuntime,
9787
} = runtime;
98-
const completeControlUiDeviceAuthMigrationForEffectiveOperator = (
99-
device: EffectiveOperatorDeviceIdentity,
100-
) => {
101-
if (
102-
!controlUiDeviceAuthMigration.pending ||
103-
!roleScopesAllow({
104-
role: "operator",
105-
requestedScopes: ["operator.pairing"],
106-
allowedScopes: device.scopes,
107-
})
108-
) {
109-
return;
110-
}
111-
const normalizedDeviceId = device.deviceId.trim();
112-
// Close the process-local grace immediately after approval. The durable
113-
// receipt prevents stale legacy config from reopening it.
114-
controlUiDeviceAuthMigration.pending = false;
115-
for (const client of clients) {
116-
if (!client.isControlUiDeviceAuthMigrationSession) {
117-
continue;
118-
}
119-
if (
120-
client.isControlUiDeviceAuthMigration &&
121-
shouldRetainControlUiDeviceAuthMigrationSession({
122-
sessionDevice: client.connect.device,
123-
approvedDevice: device,
124-
})
125-
) {
126-
// Retention is bound to the approved key as well as its derived id.
127-
// Keep only that identity long enough to receive the approval response.
128-
continue;
129-
}
130-
client.invalidated = true;
131-
client.invalidatedReason = "device-auth-migration-completed";
132-
client.socket.close(4001, "device auth migration completed");
133-
}
134-
try {
135-
completeControlUiDeviceAuthMigration(normalizedDeviceId, { env: process.env });
136-
} catch (error) {
137-
log.warn(`failed to persist Control UI device-auth migration completion: ${String(error)}`);
138-
}
139-
};
140-
const unsubscribeEffectiveOperatorPairing = onEffectiveOperatorDevicePaired(
141-
completeControlUiDeviceAuthMigrationForEffectiveOperator,
142-
);
14388
workerGatewayEndpoint.resolve = transportBridge.getWorkerIngressEndpoint;
14489
const subscribeSessionMessageEvents: GatewayRequestContext["subscribeSessionMessageEvents"] = (
14590
connId,
@@ -446,7 +391,6 @@ export async function prepareGatewayLifecycle(params: {
446391
runtimeState.stopGatewayUpdateCheck();
447392
runtimeState.controlUiSessionPullRequests?.stop();
448393
runtimeState.sessionViewerPresence?.stop();
449-
unsubscribeEffectiveOperatorPairing();
450394
kernel.setDispatchReady(false);
451395
gatewayInstanceRuntimeRef.current?.close();
452396
cronReconciliation.invalidate();
@@ -644,8 +588,6 @@ export async function prepareGatewayLifecycle(params: {
644588

645589
return {
646590
...runtime,
647-
completeControlUiDeviceAuthMigrationForEffectiveOperator,
648-
unsubscribeEffectiveOperatorPairing,
649591
subscribeSessionMessageEvents,
650592
unsubscribeSessionMessageEvents,
651593
restartRecoveryCandidates,

0 commit comments

Comments
 (0)