惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
量子位
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
博客园 - 聂微东
美团技术团队
Last Week in AI
Last Week in AI
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(browser): keep user tabs open on SSRF-denied reads (#...
scotthuang · 2026-05-08 · via Recent Commits to openclaw:main

@@ -0,0 +1,124 @@

1+

import type { Page } from "playwright-core";

2+

import { afterEach, describe, expect, it, vi } from "vitest";

3+

import { SsrFBlockedError } from "../infra/net/ssrf.js";

4+

import {

5+

assertBrowserNavigationRedirectChainAllowed,

6+

assertBrowserNavigationResultAllowed,

7+

} from "./navigation-guard.js";

8+

import { assertPageNavigationCompletedSafely } from "./pw-session.js";

9+10+

vi.mock("./navigation-guard.js", async (importOriginal) => {

11+

const actual = await importOriginal<Record<string, unknown>>();

12+

return {

13+

...actual,

14+

assertBrowserNavigationRedirectChainAllowed: vi.fn(async () => {}),

15+

assertBrowserNavigationResultAllowed: vi.fn(async () => {}),

16+

};

17+

});

18+19+

const mockedRedirectChain = vi.mocked(assertBrowserNavigationRedirectChainAllowed);

20+

const mockedResultAllowed = vi.mocked(assertBrowserNavigationResultAllowed);

21+22+

afterEach(() => {

23+

mockedRedirectChain.mockReset();

24+

mockedRedirectChain.mockImplementation(async () => {});

25+

mockedResultAllowed.mockReset();

26+

mockedResultAllowed.mockImplementation(async () => {});

27+

});

28+29+

function fakePage(url = "https://blocked.example/admin"): {

30+

page: Page;

31+

close: ReturnType<typeof vi.fn>;

32+

} {

33+

const close = vi.fn(async () => {});

34+

const page = {

35+

url: vi.fn(() => url),

36+

close,

37+

} as unknown as Page;

38+

return { page, close };

39+

}

40+41+

describe("assertPageNavigationCompletedSafely", () => {

42+

it("does not close the tab when a read-only caller hits an SSRF-blocked URL (response: null)", async () => {

43+

// A read-only caller (snapshot/screenshot/interactions) passes response: null

44+

// and must never lose the user's tab when the policy guard rejects.

45+

mockedResultAllowed.mockRejectedValueOnce(new SsrFBlockedError("blocked by policy"));

46+47+

const { page, close } = fakePage();

48+49+

await expect(

50+

assertPageNavigationCompletedSafely({

51+

cdpUrl: "http://127.0.0.1:18792",

52+

page,

53+

response: null,

54+

ssrfPolicy: { allowPrivateNetwork: false },

55+

targetId: "tab-1",

56+

}),

57+

).rejects.toBeInstanceOf(SsrFBlockedError);

58+59+

expect(close).not.toHaveBeenCalled();

60+

});

61+62+

it("does not close the tab when a navigate caller hits an SSRF-blocked URL (response: non-null)", async () => {

63+

// Even when the helper is invoked with a real Response (i.e. on the

64+

// navigate path), the close decision now belongs to the caller. The

65+

// helper must only quarantine + rethrow; the caller's try/catch is

66+

// responsible for closing if it owns the navigation lifecycle.

67+

mockedResultAllowed.mockRejectedValueOnce(new SsrFBlockedError("blocked by policy"));

68+69+

const { page, close } = fakePage();

70+

const response = { request: () => undefined } as unknown as Parameters<

71+

typeof assertPageNavigationCompletedSafely

72+

>[0]["response"];

73+74+

await expect(

75+

assertPageNavigationCompletedSafely({

76+

cdpUrl: "http://127.0.0.1:18792",

77+

page,

78+

response,

79+

ssrfPolicy: { allowPrivateNetwork: false },

80+

targetId: "tab-1",

81+

}),

82+

).rejects.toBeInstanceOf(SsrFBlockedError);

83+84+

expect(close).not.toHaveBeenCalled();

85+

});

86+87+

it("rethrows non-policy errors without touching the tab", async () => {

88+

const boom = new Error("transient playwright error");

89+

mockedResultAllowed.mockRejectedValueOnce(boom);

90+91+

const { page, close } = fakePage();

92+93+

await expect(

94+

assertPageNavigationCompletedSafely({

95+

cdpUrl: "http://127.0.0.1:18792",

96+

page,

97+

response: null,

98+

ssrfPolicy: { allowPrivateNetwork: false },

99+

targetId: "tab-1",

100+

}),

101+

).rejects.toBe(boom);

102+103+

expect(close).not.toHaveBeenCalled();

104+

});

105+106+

it("returns silently when both guards pass", async () => {

107+

const { page, close } = fakePage("https://allowed.example/");

108+109+

await expect(

110+

assertPageNavigationCompletedSafely({

111+

cdpUrl: "http://127.0.0.1:18792",

112+

page,

113+

response: null,

114+

ssrfPolicy: { allowPrivateNetwork: false },

115+

targetId: "tab-1",

116+

}),

117+

).resolves.toBeUndefined();

118+119+

expect(close).not.toHaveBeenCalled();

120+

expect(mockedResultAllowed).toHaveBeenCalledWith(

121+

expect.objectContaining({ url: "https://allowed.example/" }),

122+

);

123+

});

124+

});