Skip to content

Commit bfa7d21

Browse files
committed
fix(security): harden tlon Urbit requests against SSRF
1 parent 5a313c8 commit bfa7d21

18 files changed

Lines changed: 735 additions & 191 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Docs: https://docs.openclaw.ai
1515
- Security/Agents: scope CLI process cleanup to owned child PIDs to avoid killing unrelated processes on shared hosts. Thanks @aether-ai-agent.
1616
- Security/Agents (macOS): prevent shell injection when writing Claude CLI keychain credentials. (#15924) Thanks @aether-ai-agent.
1717
- Security: fix Chutes manual OAuth login state validation (thanks @aether-ai-agent). (#16058)
18+
- Security/Tlon: harden Urbit URL fetching against SSRF by blocking private/internal hosts by default (opt-in: `channels.tlon.allowPrivateNetwork`). Thanks @p80n-sec.
1819
- Security/Voice Call (Telnyx): require webhook signature verification when receiving inbound events; configs without `telnyx.publicKey` are now rejected unless `skipSignatureVerification` is enabled. Thanks @p80n-sec.
1920
- Security/Discovery: stop treating Bonjour TXT records as authoritative routing (prefer resolved service endpoints) and prevent discovery from overriding stored TLS pins; autoconnect now requires a previously trusted gateway. Thanks @simecek.
2021
- macOS: hard-limit unkeyed `openclaw://agent` deep links and ignore `deliver` / `to` / `channel` unless a valid unattended key is provided. Thanks @Cillian-Collins.

‎docs/channels/tlon.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ Minimal config (single account):
5555
}
5656
```
5757

58+
Private/LAN ship URLs (advanced):
59+
60+
By default, OpenClaw blocks private/internal hostnames and IP ranges for this plugin (SSRF hardening).
61+
If your ship URL is on a private network (for example `http://192.168.1.50:8080` or `http://localhost:8080`),
62+
you must explicitly opt in:
63+
64+
```json5
65+
{
66+
channels: {
67+
tlon: {
68+
allowPrivateNetwork: true,
69+
},
70+
},
71+
}
72+
```
73+
5874
## Group channels
5975

6076
Auto-discovery is enabled by default. You can also pin channels manually:

‎extensions/tlon/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"description": "OpenClaw Tlon/Urbit channel plugin",
66
"type": "module",
77
"dependencies": {
8-
"@urbit/aura": "^3.0.0",
9-
"@urbit/http-api": "^3.0.0"
8+
"@urbit/aura": "^3.0.0"
109
},
1110
"devDependencies": {
1211
"openclaw": "workspace:*"

‎extensions/tlon/src/channel.ts‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { monitorTlonProvider } from "./monitor/index.js";
1515
import { tlonOnboardingAdapter } from "./onboarding.js";
1616
import { formatTargetHint, normalizeShip, parseTlonTarget } from "./targets.js";
1717
import { resolveTlonAccount, listTlonAccountIds } from "./types.js";
18-
import { ensureUrbitConnectPatched, Urbit } from "./urbit/http-api.js";
18+
import { authenticate } from "./urbit/auth.js";
19+
import { UrbitChannelClient } from "./urbit/channel-client.js";
1920
import { buildMediaText, sendDm, sendGroupMessage } from "./urbit/send.js";
2021

2122
const TLON_CHANNEL_ID = "tlon" as const;
@@ -24,6 +25,7 @@ type TlonSetupInput = ChannelSetupInput & {
2425
ship?: string;
2526
url?: string;
2627
code?: string;
28+
allowPrivateNetwork?: boolean;
2729
groupChannels?: string[];
2830
dmAllowlist?: string[];
2931
autoDiscoverChannels?: boolean;
@@ -48,6 +50,9 @@ function applyTlonSetupConfig(params: {
4850
...(input.ship ? { ship: input.ship } : {}),
4951
...(input.url ? { url: input.url } : {}),
5052
...(input.code ? { code: input.code } : {}),
53+
...(typeof input.allowPrivateNetwork === "boolean"
54+
? { allowPrivateNetwork: input.allowPrivateNetwork }
55+
: {}),
5156
...(input.groupChannels ? { groupChannels: input.groupChannels } : {}),
5257
...(input.dmAllowlist ? { dmAllowlist: input.dmAllowlist } : {}),
5358
...(typeof input.autoDiscoverChannels === "boolean"
@@ -118,12 +123,11 @@ const tlonOutbound: ChannelOutboundAdapter = {
118123
throw new Error(`Invalid Tlon target. Use ${formatTargetHint()}`);
119124
}
120125

121-
ensureUrbitConnectPatched();
122-
const api = await Urbit.authenticate({
126+
const ssrfPolicy = account.allowPrivateNetwork ? { allowPrivateNetwork: true } : undefined;
127+
const cookie = await authenticate(account.url, account.code, { ssrfPolicy });
128+
const api = new UrbitChannelClient(account.url, cookie, {
123129
ship: account.ship.replace(/^~/, ""),
124-
url: account.url,
125-
code: account.code,
126-
verbose: false,
130+
ssrfPolicy,
127131
});
128132

129133
try {
@@ -146,11 +150,7 @@ const tlonOutbound: ChannelOutboundAdapter = {
146150
replyToId: replyId,
147151
});
148152
} finally {
149-
try {
150-
await api.delete();
151-
} catch {
152-
// ignore cleanup errors
153-
}
153+
await api.close();
154154
}
155155
},
156156
sendMedia: async ({ cfg, to, text, mediaUrl, accountId, replyToId, threadId }) => {
@@ -345,18 +345,17 @@ export const tlonPlugin: ChannelPlugin = {
345345
return { ok: false, error: "Not configured" };
346346
}
347347
try {
348-
ensureUrbitConnectPatched();
349-
const api = await Urbit.authenticate({
348+
const ssrfPolicy = account.allowPrivateNetwork ? { allowPrivateNetwork: true } : undefined;
349+
const cookie = await authenticate(account.url, account.code, { ssrfPolicy });
350+
const api = new UrbitChannelClient(account.url, cookie, {
350351
ship: account.ship.replace(/^~/, ""),
351-
url: account.url,
352-
code: account.code,
353-
verbose: false,
352+
ssrfPolicy,
354353
});
355354
try {
356355
await api.getOurName();
357356
return { ok: true };
358357
} finally {
359-
await api.delete();
358+
await api.close();
360359
}
361360
} catch (error) {
362361
return { ok: false, error: (error as { message?: string })?.message ?? String(error) };

‎extensions/tlon/src/config-schema.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const TlonAccountSchema = z.object({
1919
ship: ShipSchema.optional(),
2020
url: z.string().optional(),
2121
code: z.string().optional(),
22+
allowPrivateNetwork: z.boolean().optional(),
2223
groupChannels: z.array(ChannelNestSchema).optional(),
2324
dmAllowlist: z.array(ShipSchema).optional(),
2425
autoDiscoverChannels: z.boolean().optional(),
@@ -32,6 +33,7 @@ export const TlonConfigSchema = z.object({
3233
ship: ShipSchema.optional(),
3334
url: z.string().optional(),
3435
code: z.string().optional(),
36+
allowPrivateNetwork: z.boolean().optional(),
3537
groupChannels: z.array(ChannelNestSchema).optional(),
3638
dmAllowlist: z.array(ShipSchema).optional(),
3739
autoDiscoverChannels: z.boolean().optional(),

‎extensions/tlon/src/monitor/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ export async function monitorTlonProvider(opts: MonitorTlonOpts = {}): Promise<v
113113

114114
let api: UrbitSSEClient | null = null;
115115
try {
116+
const ssrfPolicy = account.allowPrivateNetwork ? { allowPrivateNetwork: true } : undefined;
116117
runtime.log?.(`[tlon] Attempting authentication to ${account.url}...`);
117-
const cookie = await authenticate(account.url, account.code);
118+
const cookie = await authenticate(account.url, account.code, { ssrfPolicy });
118119
api = new UrbitSSEClient(account.url, cookie, {
119120
ship: botShipName,
121+
ssrfPolicy,
120122
logger: {
121123
log: (message) => runtime.log?.(message),
122124
error: (message) => runtime.error?.(message),

‎extensions/tlon/src/onboarding.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "openclaw/plugin-sdk";
1010
import type { TlonResolvedAccount } from "./types.js";
1111
import { listTlonAccountIds, resolveTlonAccount } from "./types.js";
12+
import { isBlockedUrbitHostname, validateUrbitBaseUrl } from "./urbit/base-url.js";
1213

1314
const channel = "tlon" as const;
1415

@@ -24,6 +25,7 @@ function applyAccountConfig(params: {
2425
ship?: string;
2526
url?: string;
2627
code?: string;
28+
allowPrivateNetwork?: boolean;
2729
groupChannels?: string[];
2830
dmAllowlist?: string[];
2931
autoDiscoverChannels?: boolean;
@@ -45,6 +47,9 @@ function applyAccountConfig(params: {
4547
...(input.ship ? { ship: input.ship } : {}),
4648
...(input.url ? { url: input.url } : {}),
4749
...(input.code ? { code: input.code } : {}),
50+
...(typeof input.allowPrivateNetwork === "boolean"
51+
? { allowPrivateNetwork: input.allowPrivateNetwork }
52+
: {}),
4853
...(input.groupChannels ? { groupChannels: input.groupChannels } : {}),
4954
...(input.dmAllowlist ? { dmAllowlist: input.dmAllowlist } : {}),
5055
...(typeof input.autoDiscoverChannels === "boolean"
@@ -73,6 +78,9 @@ function applyAccountConfig(params: {
7378
...(input.ship ? { ship: input.ship } : {}),
7479
...(input.url ? { url: input.url } : {}),
7580
...(input.code ? { code: input.code } : {}),
81+
...(typeof input.allowPrivateNetwork === "boolean"
82+
? { allowPrivateNetwork: input.allowPrivateNetwork }
83+
: {}),
7684
...(input.groupChannels ? { groupChannels: input.groupChannels } : {}),
7785
...(input.dmAllowlist ? { dmAllowlist: input.dmAllowlist } : {}),
7886
...(typeof input.autoDiscoverChannels === "boolean"
@@ -91,6 +99,7 @@ async function noteTlonHelp(prompter: WizardPrompter): Promise<void> {
9199
"You need your Urbit ship URL and login code.",
92100
"Example URL: https://your-ship-host",
93101
"Example ship: ~sampel-palnet",
102+
"If your ship URL is on a private network (LAN/localhost), you must explicitly allow it during setup.",
94103
`Docs: ${formatDocsLink("/channels/tlon", "channels/tlon")}`,
95104
].join("\n"),
96105
"Tlon setup",
@@ -151,9 +160,32 @@ export const tlonOnboardingAdapter: ChannelOnboardingAdapter = {
151160
message: "Ship URL",
152161
placeholder: "https://your-ship-host",
153162
initialValue: resolved.url ?? undefined,
154-
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
163+
validate: (value) => {
164+
const next = validateUrbitBaseUrl(String(value ?? ""));
165+
if (!next.ok) {
166+
return next.error;
167+
}
168+
return undefined;
169+
},
155170
});
156171

172+
const validatedUrl = validateUrbitBaseUrl(String(url).trim());
173+
if (!validatedUrl.ok) {
174+
throw new Error(`Invalid URL: ${validatedUrl.error}`);
175+
}
176+
177+
let allowPrivateNetwork = resolved.allowPrivateNetwork ?? false;
178+
if (isBlockedUrbitHostname(validatedUrl.hostname)) {
179+
allowPrivateNetwork = await prompter.confirm({
180+
message:
181+
"Ship URL looks like a private/internal host. Allow private network access? (SSRF risk)",
182+
initialValue: allowPrivateNetwork,
183+
});
184+
if (!allowPrivateNetwork) {
185+
throw new Error("Refusing private/internal Ship URL without explicit approval");
186+
}
187+
}
188+
157189
const code = await prompter.text({
158190
message: "Login code",
159191
placeholder: "lidlut-tabwed-pillex-ridrup",
@@ -203,6 +235,7 @@ export const tlonOnboardingAdapter: ChannelOnboardingAdapter = {
203235
ship: String(ship).trim(),
204236
url: String(url).trim(),
205237
code: String(code).trim(),
238+
allowPrivateNetwork,
206239
groupChannels,
207240
dmAllowlist,
208241
autoDiscoverChannels,

‎extensions/tlon/src/types.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type TlonResolvedAccount = {
88
ship: string | null;
99
url: string | null;
1010
code: string | null;
11+
allowPrivateNetwork: boolean | null;
1112
groupChannels: string[];
1213
dmAllowlist: string[];
1314
autoDiscoverChannels: boolean | null;
@@ -25,6 +26,7 @@ export function resolveTlonAccount(
2526
ship?: string;
2627
url?: string;
2728
code?: string;
29+
allowPrivateNetwork?: boolean;
2830
groupChannels?: string[];
2931
dmAllowlist?: string[];
3032
autoDiscoverChannels?: boolean;
@@ -42,6 +44,7 @@ export function resolveTlonAccount(
4244
ship: null,
4345
url: null,
4446
code: null,
47+
allowPrivateNetwork: null,
4548
groupChannels: [],
4649
dmAllowlist: [],
4750
autoDiscoverChannels: null,
@@ -55,6 +58,9 @@ export function resolveTlonAccount(
5558
const ship = (account?.ship ?? base.ship ?? null) as string | null;
5659
const url = (account?.url ?? base.url ?? null) as string | null;
5760
const code = (account?.code ?? base.code ?? null) as string | null;
61+
const allowPrivateNetwork = (account?.allowPrivateNetwork ?? base.allowPrivateNetwork ?? null) as
62+
| boolean
63+
| null;
5864
const groupChannels = (account?.groupChannels ?? base.groupChannels ?? []) as string[];
5965
const dmAllowlist = (account?.dmAllowlist ?? base.dmAllowlist ?? []) as string[];
6066
const autoDiscoverChannels = (account?.autoDiscoverChannels ??
@@ -73,6 +79,7 @@ export function resolveTlonAccount(
7379
ship,
7480
url,
7581
code,
82+
allowPrivateNetwork,
7683
groupChannels,
7784
dmAllowlist,
7885
autoDiscoverChannels,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { SsrFBlockedError } from "openclaw/plugin-sdk";
2+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { authenticate } from "./auth.js";
4+
5+
describe("tlon urbit auth ssrf", () => {
6+
beforeEach(() => {
7+
vi.unstubAllGlobals();
8+
});
9+
10+
afterEach(() => {
11+
vi.unstubAllGlobals();
12+
});
13+
14+
it("blocks private IPs by default", async () => {
15+
const mockFetch = vi.fn();
16+
vi.stubGlobal("fetch", mockFetch);
17+
18+
await expect(authenticate("http://127.0.0.1:8080", "code")).rejects.toBeInstanceOf(
19+
SsrFBlockedError,
20+
);
21+
expect(mockFetch).not.toHaveBeenCalled();
22+
});
23+
24+
it("allows private IPs when allowPrivateNetwork is enabled", async () => {
25+
const mockFetch = vi.fn().mockResolvedValue({
26+
ok: true,
27+
status: 200,
28+
text: async () => "ok",
29+
headers: new Headers({
30+
"set-cookie": "urbauth-~zod=123; Path=/; HttpOnly",
31+
}),
32+
});
33+
vi.stubGlobal("fetch", mockFetch);
34+
35+
const cookie = await authenticate("http://127.0.0.1:8080", "code", {
36+
ssrfPolicy: { allowPrivateNetwork: true },
37+
lookupFn: async () => [{ address: "127.0.0.1", family: 4 }],
38+
});
39+
expect(cookie).toContain("urbauth-~zod=123");
40+
expect(mockFetch).toHaveBeenCalled();
41+
});
42+
});

‎extensions/tlon/src/urbit/auth.ts‎

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
export async function authenticate(url: string, code: string): Promise<string> {
2-
const resp = await fetch(`${url}/~/login`, {
3-
method: "POST",
4-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
5-
body: `password=${code}`,
1+
import type { LookupFn, SsrFPolicy } from "openclaw/plugin-sdk";
2+
import { urbitFetch } from "./fetch.js";
3+
4+
export type UrbitAuthenticateOptions = {
5+
ssrfPolicy?: SsrFPolicy;
6+
lookupFn?: LookupFn;
7+
fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
8+
timeoutMs?: number;
9+
};
10+
11+
export async function authenticate(
12+
url: string,
13+
code: string,
14+
options: UrbitAuthenticateOptions = {},
15+
): Promise<string> {
16+
const { response, release } = await urbitFetch({
17+
baseUrl: url,
18+
path: "/~/login",
19+
init: {
20+
method: "POST",
21+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
22+
body: new URLSearchParams({ password: code }).toString(),
23+
},
24+
ssrfPolicy: options.ssrfPolicy,
25+
lookupFn: options.lookupFn,
26+
fetchImpl: options.fetchImpl,
27+
timeoutMs: options.timeoutMs ?? 15_000,
28+
maxRedirects: 3,
29+
auditContext: "tlon-urbit-login",
630
});
731

8-
if (!resp.ok) {
9-
throw new Error(`Login failed with status ${resp.status}`);
10-
}
32+
try {
33+
if (!response.ok) {
34+
throw new Error(`Login failed with status ${response.status}`);
35+
}
1136

12-
await resp.text();
13-
const cookie = resp.headers.get("set-cookie");
14-
if (!cookie) {
15-
throw new Error("No authentication cookie received");
37+
// Some Urbit setups require the response body to be read before cookie headers finalize.
38+
await response.text().catch(() => {});
39+
const cookie = response.headers.get("set-cookie");
40+
if (!cookie) {
41+
throw new Error("No authentication cookie received");
42+
}
43+
return cookie;
44+
} finally {
45+
await release();
1646
}
17-
return cookie;
1847
}

0 commit comments

Comments
 (0)