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

推荐订阅源

D
DataBreaches.Net
罗磊的独立博客
雷峰网
雷峰网
量子位
V
Visual Studio Blog
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
月光博客
月光博客
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
腾讯CDC
Engineering at Meta
Engineering at Meta
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
A
About on SuperTechFans

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(gateway): require owner auth for managed image media ...
steipete · 2026-05-08 · via Recent Commits to openclaw:main

@@ -9,24 +9,21 @@ import { setMediaStoreNetworkDepsForTest } from "../media/store.js";

991010

const authorizeGatewayHttpRequestOrReplyMock = vi.fn();

1111

const resolveOpenAiCompatibleHttpOperatorScopesMock = vi.fn();

12-

const getLatestSubagentRunByChildSessionKeyMock = vi.fn();

12+

const resolveOpenAiCompatibleHttpSenderIsOwnerMock = vi.fn();

1313

const loadSessionEntryMock = vi.fn();

1414

const readSessionMessagesMock = vi.fn();

15151616

vi.mock("./http-utils.js", () => ({

1717

authorizeGatewayHttpRequestOrReply: authorizeGatewayHttpRequestOrReplyMock,

1818

resolveOpenAiCompatibleHttpOperatorScopes: resolveOpenAiCompatibleHttpOperatorScopesMock,

19+

resolveOpenAiCompatibleHttpSenderIsOwner: resolveOpenAiCompatibleHttpSenderIsOwnerMock,

1920

}));

20212122

vi.mock("./session-utils.js", () => ({

2223

loadSessionEntry: loadSessionEntryMock,

2324

readSessionMessagesAsync: readSessionMessagesMock,

2425

}));

252626-

vi.mock("../agents/subagent-registry.js", () => ({

27-

getLatestSubagentRunByChildSessionKey: getLatestSubagentRunByChildSessionKeyMock,

28-

}));

29-3027

const {

3128

DEFAULT_MANAGED_IMAGE_ATTACHMENT_LIMITS,

3229

attachManagedOutgoingImagesToMessage,

@@ -128,7 +125,6 @@ async function requestManagedImage(params: {

128125

authResponse?: Record<string, unknown>;

129126

headers?: Record<string, string>;

130127

transcriptMessages?: Record<string, unknown>[];

131-

subagentRun?: Record<string, unknown> | null;

132128

sessionEntry?: { sessionId: string; sessionFile?: string };

133129

}) {

134130

authorizeGatewayHttpRequestOrReplyMock.mockImplementation(async ({ res }) => {

@@ -140,7 +136,15 @@ async function requestManagedImage(params: {

140136

return { ok: true, ...params.authResponse };

141137

});

142138

resolveOpenAiCompatibleHttpOperatorScopesMock.mockReturnValue(params.scopes ?? ["operator.read"]);

143-

getLatestSubagentRunByChildSessionKeyMock.mockReturnValue(params.subagentRun ?? null);

139+

resolveOpenAiCompatibleHttpSenderIsOwnerMock.mockImplementation((_req, requestAuth) => {

140+

if (requestAuth.authMethod === "token" || requestAuth.authMethod === "password") {

141+

return true;

142+

}

143+

return (

144+

requestAuth.trustDeclaredOperatorScopes === true &&

145+

(params.scopes ?? ["operator.read"]).includes("operator.admin")

146+

);

147+

});

144148

loadSessionEntryMock.mockReturnValue({

145149

storePath: path.join(params.stateDir, "gateway-sessions.json"),

146150

entry: params.sessionEntry ?? { sessionId: "sess-1", sessionFile: "session.jsonl" },

@@ -237,7 +241,7 @@ describe("handleManagedOutgoingImageHttpRequest", () => {

237241

const { result } = await requestManagedImage({

238242

stateDir,

239243

pathName: `/api/chat/media/outgoing/${encodeURIComponent(sessionKey)}/${attachmentId}/full`,

240-

headers: { "x-openclaw-requester-session-key": sessionKey },

244+

authResponse: { authMethod: "token" },

241245

});

242246243247

expect(result.statusCode).toBe(200);

@@ -259,25 +263,40 @@ describe("handleManagedOutgoingImageHttpRequest", () => {

259263

expect(result.body.byteLength).toBe(0);

260264

});

261265262-

it("rejects requests from unrelated sessions", async () => {

266+

it("rejects non-owner trusted-proxy requests with self-declared session ownership", async () => {

263267

const { attachmentId, sessionKey } = await createFixture(stateDir);

264268265269

const { result } = await requestManagedImage({

266270

stateDir,

267271

pathName: `/api/chat/media/outgoing/${encodeURIComponent(sessionKey)}/${attachmentId}/full`,

268-

headers: { "x-openclaw-requester-session-key": "agent:main:other" },

272+

authResponse: { authMethod: "trusted-proxy", trustDeclaredOperatorScopes: true },

273+

headers: { "x-openclaw-requester-session-key": sessionKey },

269274

});

270275271276

expect(result.statusCode).toBe(403);

272277

});

273278274-

it("allows device-token access without requester session ownership", async () => {

279+

it("rejects device-token access with self-declared session ownership", async () => {

275280

const { attachmentId, sessionKey } = await createFixture(stateDir);

276281277282

const { result } = await requestManagedImage({

278283

stateDir,

279284

pathName: `/api/chat/media/outgoing/${encodeURIComponent(sessionKey)}/${attachmentId}/full`,

280285

authResponse: { authMethod: "device-token" },

286+

headers: { "x-openclaw-requester-session-key": sessionKey },

287+

});

288+289+

expect(result.statusCode).toBe(403);

290+

});

291+292+

it("serves owner trusted-proxy requests with admin scope", async () => {

293+

const { attachmentId, sessionKey } = await createFixture(stateDir);

294+295+

const { result } = await requestManagedImage({

296+

stateDir,

297+

pathName: `/api/chat/media/outgoing/${encodeURIComponent(sessionKey)}/${attachmentId}/full`,

298+

authResponse: { authMethod: "trusted-proxy", trustDeclaredOperatorScopes: true },

299+

scopes: ["operator.admin"],

281300

});

282301283302

expect(result.statusCode).toBe(200);

@@ -332,14 +351,14 @@ describe("handleManagedOutgoingImageHttpRequest", () => {

332351

const first = await requestManagedImage({

333352

stateDir,

334353

pathName,

335-

headers: { "x-openclaw-requester-session-key": sessionKey },

354+

authResponse: { authMethod: "token" },

336355

sessionEntry: { sessionId: "sess-main", sessionFile },

337356

transcriptMessages,

338357

});

339358

const second = await requestManagedImage({

340359

stateDir,

341360

pathName,

342-

headers: { "x-openclaw-requester-session-key": sessionKey },

361+

authResponse: { authMethod: "token" },

343362

sessionEntry: { sessionId: "sess-main", sessionFile },

344363

transcriptMessages,

345364

});

@@ -354,7 +373,7 @@ describe("handleManagedOutgoingImageHttpRequest", () => {

354373

const third = await requestManagedImage({

355374

stateDir,

356375

pathName,

357-

headers: { "x-openclaw-requester-session-key": sessionKey },

376+

authResponse: { authMethod: "token" },

358377

sessionEntry: { sessionId: "sess-main", sessionFile },

359378

transcriptMessages,

360379

});