Skip to content

Commit 630f2bc

Browse files
committed
fix: harden published gateway secret placeholders
1 parent 106b770 commit 630f2bc

8 files changed

Lines changed: 149 additions & 60 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Docs: https://docs.openclaw.ai
6767
- Agents/Google: strip `thinkingBudget=0` for the thinking-required `gemini-2.5-pro` model in embedded-runner and native Google payloads, so requests no longer fail with `Budget 0 is invalid. This model only works in thinking mode.` and the API uses its default thinking behavior instead. (#68607) Thanks @josmithiii.
6868
- Slack/threads: log failed thread starter and history fetches at verbose level while preserving best-effort fallback behavior, so missing Slack thread context is diagnosable without interrupting inbound handling. (#68594) Thanks @martingarramon.
6969
- Gateway/restart: keep stale-gateway cleanup from terminating the current process's parent or ancestors, so plugin sidecars like WeChat no longer kill the active gateway and trigger an infinite supervisor restart loop. Fixes #68451. (#68517) Thanks @openperf.
70+
- Gateway/auth: reject gateway auth credentials that match published example placeholders at startup and secret reload, and keep cloud install snippets from publishing copy-paste gateway/keyring secrets. (#68404) Thanks @coygeek.
7071

7172
## 2026.4.15
7273

‎docs/install/gcp.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,14 @@ For the generic Docker flow, see [Docker](/install/docker).
220220
OPENCLAW_CONFIG_DIR=/home/$USER/.openclaw
221221
OPENCLAW_WORKSPACE_DIR=/home/$USER/.openclaw/workspace
222222

223-
GOG_KEYRING_PASSWORD=change-me-now
223+
GOG_KEYRING_PASSWORD=
224224
XDG_CONFIG_HOME=/home/node/.openclaw
225225
```
226226

227-
Generate strong secrets:
227+
Leave `OPENCLAW_GATEWAY_TOKEN` blank unless you explicitly want to
228+
manage it through `.env`; OpenClaw writes a random gateway token to
229+
config on first start. Generate a keyring password and paste it into
230+
`GOG_KEYRING_PASSWORD`:
228231

229232
```bash
230233
openssl rand -hex 32

‎docs/install/hetzner.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ For the generic Docker flow, see [Docker](/install/docker).
141141
OPENCLAW_CONFIG_DIR=/root/.openclaw
142142
OPENCLAW_WORKSPACE_DIR=/root/.openclaw/workspace
143143

144-
GOG_KEYRING_PASSWORD=change-me-now
144+
GOG_KEYRING_PASSWORD=
145145
XDG_CONFIG_HOME=/home/node/.openclaw
146146
```
147147

148-
Generate strong secrets:
148+
Leave `OPENCLAW_GATEWAY_TOKEN` blank unless you explicitly want to
149+
manage it through `.env`; OpenClaw writes a random gateway token to
150+
config on first start. Generate a keyring password and paste it into
151+
`GOG_KEYRING_PASSWORD`:
149152

150153
```bash
151154
openssl rand -hex 32
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
33
import { describe, expect, it } from "vitest";
4-
import { KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS } from "../gateway/known-weak-gateway-secrets.js";
4+
import {
5+
KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS,
6+
KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS,
7+
} from "../gateway/known-weak-gateway-secrets.js";
58

69
const INSTALL_DOCS_DIR = path.join(process.cwd(), "docs", "install");
7-
const CLOUD_INSTALL_DOCS = ["gcp.md", "hetzner.md"] as const;
10+
const CLOUD_DOCKER_VM_INSTALL_DOCS = new Set(["gcp.md", "hetzner.md"]);
11+
12+
async function readInstallDocs(): Promise<Array<{ docName: string; markdown: string }>> {
13+
const entries = await fs.readdir(INSTALL_DOCS_DIR, { withFileTypes: true });
14+
return await Promise.all(
15+
entries
16+
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
17+
.toSorted((a, b) => a.name.localeCompare(b.name))
18+
.map(async (entry) => ({
19+
docName: entry.name,
20+
markdown: await fs.readFile(path.join(INSTALL_DOCS_DIR, entry.name), "utf8"),
21+
})),
22+
);
23+
}
824

925
describe("cloud install docs", () => {
1026
it("does not publish a copy-paste gateway token placeholder", async () => {
11-
for (const docName of CLOUD_INSTALL_DOCS) {
12-
const markdown = await fs.readFile(path.join(INSTALL_DOCS_DIR, docName), "utf8");
13-
27+
for (const { docName, markdown } of await readInstallDocs()) {
1428
for (const token of KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS) {
15-
expect(markdown).not.toContain(`OPENCLAW_GATEWAY_TOKEN=${token}`);
29+
expect(markdown, docName).not.toContain(`OPENCLAW_GATEWAY_TOKEN=${token}`);
30+
}
31+
for (const password of KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS) {
32+
expect(markdown, docName).not.toContain(`OPENCLAW_GATEWAY_PASSWORD=${password}`);
33+
}
34+
expect(markdown, docName).not.toMatch(/^ GOG_KEYRING_PASSWORD=change-me-now$/m);
35+
if (CLOUD_DOCKER_VM_INSTALL_DOCS.has(docName)) {
36+
expect(markdown, docName).toMatch(/^ OPENCLAW_GATEWAY_TOKEN=[ \t]*\r?$/m);
37+
expect(markdown, docName).toMatch(/^ GOG_KEYRING_PASSWORD=[ \t]*\r?$/m);
38+
expect(markdown, docName).toContain("openssl rand -hex 32");
1639
}
17-
expect(markdown).toMatch(/OPENCLAW_GATEWAY_TOKEN=[ \t]*\r?\n/);
18-
expect(markdown).toContain("openssl rand -hex 32");
1940
}
2041
});
2142
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
1+
import type { ResolvedGatewayAuth } from "./auth.js";
2+
13
export const KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS = [
24
"change-me-to-a-long-random-token",
35
"change-me-now",
46
] as const;
57

68
export const KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS = ["change-me-to-a-strong-password"] as const;
9+
10+
/**
11+
* Placeholder credentials that have ever shipped in `.env.example` or been
12+
* used as copy-paste examples in onboarding docs. If any of these ever
13+
* becomes the resolved gateway credential, reject it. The operator almost
14+
* certainly copied an example file verbatim without replacing the sentinel,
15+
* which would otherwise leave the gateway protected by a publicly-known
16+
* credential.
17+
*/
18+
const KNOWN_WEAK_GATEWAY_TOKENS: ReadonlySet<string> = new Set(
19+
KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS,
20+
);
21+
22+
const KNOWN_WEAK_GATEWAY_PASSWORDS: ReadonlySet<string> = new Set(
23+
KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS,
24+
);
25+
26+
export function assertGatewayAuthNotKnownWeak(auth: ResolvedGatewayAuth): void {
27+
if (auth.mode === "token") {
28+
const token = auth.token?.trim() ?? "";
29+
if (token && KNOWN_WEAK_GATEWAY_TOKENS.has(token)) {
30+
throw new Error(
31+
"Invalid config: gateway auth token is set to a published example placeholder " +
32+
"from docs or .env.example. Generate a real secret (e.g. `openssl rand -hex 32`) " +
33+
"and set OPENCLAW_GATEWAY_TOKEN or gateway.auth.token before starting " +
34+
"the gateway.",
35+
);
36+
}
37+
return;
38+
}
39+
if (auth.mode === "password") {
40+
const password = auth.password?.trim() ?? "";
41+
if (password && KNOWN_WEAK_GATEWAY_PASSWORDS.has(password)) {
42+
throw new Error(
43+
"Invalid config: gateway auth password is set to the example placeholder " +
44+
"from .env.example. Choose a real password and set OPENCLAW_GATEWAY_PASSWORD " +
45+
"or gateway.auth.password before starting the gateway.",
46+
);
47+
}
48+
}
49+
}

‎src/gateway/server-startup-config.secrets.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
22
import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.js";
33
import type { PreparedSecretsRuntimeSnapshot, SecretResolverWarning } from "../secrets/runtime.js";
4+
import { KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS } from "./known-weak-gateway-secrets.js";
45
import {
56
createRuntimeSecretsActivator,
67
prepareGatewayStartupConfig,
@@ -157,6 +158,56 @@ describe("gateway startup config secret preflight", () => {
157158
expect(emitStateEvent).not.toHaveBeenCalled();
158159
});
159160

161+
it.each(KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS)(
162+
"rejects known weak gateway tokens resolved during secret activation: %s",
163+
async (token) => {
164+
const sourceConfig = gatewayTokenConfig({
165+
secrets: {
166+
providers: {
167+
default: { source: "env" },
168+
},
169+
},
170+
gateway: {
171+
auth: {
172+
mode: "token",
173+
token: { source: "env", provider: "default", id: "GATEWAY_TOKEN_REF" },
174+
},
175+
},
176+
});
177+
const prepareRuntimeSecretsSnapshot = vi.fn(async () =>
178+
preparedSnapshot({
179+
...sourceConfig,
180+
gateway: {
181+
...sourceConfig.gateway,
182+
auth: {
183+
...sourceConfig.gateway?.auth,
184+
token,
185+
},
186+
},
187+
}),
188+
);
189+
const activateRuntimeSecretsSnapshot = vi.fn();
190+
const activateRuntimeSecrets = createRuntimeSecretsActivator({
191+
logSecrets: {
192+
info: vi.fn(),
193+
warn: vi.fn(),
194+
error: vi.fn(),
195+
},
196+
emitStateEvent: vi.fn(),
197+
prepareRuntimeSecretsSnapshot,
198+
activateRuntimeSecretsSnapshot,
199+
});
200+
201+
await expect(
202+
activateRuntimeSecrets(sourceConfig, {
203+
reason: "reload",
204+
activate: true,
205+
}),
206+
).rejects.toThrow(/published example placeholder/);
207+
expect(activateRuntimeSecretsSnapshot).not.toHaveBeenCalled();
208+
},
209+
);
210+
160211
it("prunes channel refs from startup secret preflight when channels are skipped", async () => {
161212
process.env.OPENCLAW_SKIP_CHANNELS = "1";
162213
const prepareRuntimeSecretsSnapshot = vi.fn(async ({ config }) => preparedSnapshot(config));

‎src/gateway/server-startup-config.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
activateSecretsRuntimeSnapshot,
2121
prepareSecretsRuntimeSnapshot,
2222
} from "../secrets/runtime.js";
23+
import { resolveGatewayAuth } from "./auth.js";
24+
import { assertGatewayAuthNotKnownWeak } from "./known-weak-gateway-secrets.js";
2325
import {
2426
ensureGatewayStartupAuth,
2527
mergeGatewayAuthConfig,
@@ -114,6 +116,7 @@ export function createRuntimeSecretsActivator(params: {
114116
const prepared = await prepareRuntimeSecretsSnapshot({
115117
config: pruneSkippedStartupSecretSurfaces(config),
116118
});
119+
assertRuntimeGatewayAuthNotKnownWeak(prepared.config);
117120
if (activationParams.activate) {
118121
activateRuntimeSecretsSnapshot(prepared);
119122
logGatewayAuthSurfaceDiagnostics(prepared, params.logSecrets);
@@ -241,6 +244,16 @@ function pruneSkippedStartupSecretSurfaces(config: OpenClawConfig): OpenClawConf
241244
};
242245
}
243246

247+
function assertRuntimeGatewayAuthNotKnownWeak(config: OpenClawConfig): void {
248+
assertGatewayAuthNotKnownWeak(
249+
resolveGatewayAuth({
250+
authConfig: config.gateway?.auth,
251+
env: process.env,
252+
tailscaleMode: config.gateway?.tailscale?.mode ?? "off",
253+
}),
254+
);
255+
}
256+
244257
function logGatewayAuthSurfaceDiagnostics(
245258
prepared: {
246259
sourceConfig: OpenClawConfig;

‎src/gateway/startup-auth.ts‎

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,9 @@ import {
1818
hasGatewayTokenEnvCandidate,
1919
trimToUndefined,
2020
} from "./credentials.js";
21-
import {
22-
KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS,
23-
KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS,
24-
} from "./known-weak-gateway-secrets.js";
25-
26-
/**
27-
* Placeholder credentials that have ever shipped in `.env.example` or been
28-
* used as copy-paste examples in onboarding docs. If any of these ever
29-
* becomes the resolved gateway credential at startup, reject the launch —
30-
* the operator almost certainly copied an example file verbatim without
31-
* replacing the sentinel, which would otherwise leave the gateway protected
32-
* by a publicly-known credential.
33-
*
34-
* This is a belt-and-suspenders complement to keeping `.env.example` blank:
35-
* the example file alone does not protect users who follow an older doc
36-
* snippet or copy a tutorial command line.
37-
*/
38-
const KNOWN_WEAK_GATEWAY_TOKENS: ReadonlySet<string> = new Set(
39-
KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS,
40-
);
21+
import { assertGatewayAuthNotKnownWeak } from "./known-weak-gateway-secrets.js";
4122

42-
const KNOWN_WEAK_GATEWAY_PASSWORDS: ReadonlySet<string> = new Set(
43-
KNOWN_WEAK_GATEWAY_PASSWORD_PLACEHOLDERS,
44-
);
23+
export { assertGatewayAuthNotKnownWeak } from "./known-weak-gateway-secrets.js";
4524

4625
export function mergeGatewayAuthConfig(
4726
base?: GatewayAuthConfig,
@@ -268,31 +247,6 @@ export async function ensureGatewayStartupAuth(params: {
268247
};
269248
}
270249

271-
export function assertGatewayAuthNotKnownWeak(auth: ResolvedGatewayAuth): void {
272-
if (auth.mode === "token") {
273-
const token = auth.token?.trim() ?? "";
274-
if (token && KNOWN_WEAK_GATEWAY_TOKENS.has(token)) {
275-
throw new Error(
276-
"Invalid config: gateway auth token is set to a published example placeholder " +
277-
"from docs or .env.example. Generate a real secret (e.g. `openssl rand -hex 32`) " +
278-
"and set OPENCLAW_GATEWAY_TOKEN or gateway.auth.token before starting " +
279-
"the gateway.",
280-
);
281-
}
282-
return;
283-
}
284-
if (auth.mode === "password") {
285-
const password = auth.password?.trim() ?? "";
286-
if (password && KNOWN_WEAK_GATEWAY_PASSWORDS.has(password)) {
287-
throw new Error(
288-
"Invalid config: gateway auth password is set to the example placeholder " +
289-
"from .env.example. Choose a real password and set OPENCLAW_GATEWAY_PASSWORD " +
290-
"or gateway.auth.password before starting the gateway.",
291-
);
292-
}
293-
}
294-
}
295-
296250
export function assertHooksTokenSeparateFromGatewayAuth(params: {
297251
cfg: OpenClawConfig;
298252
auth: ResolvedGatewayAuth;

0 commit comments

Comments
 (0)