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

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
D
Docker
B
Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
G
Google Developers Blog
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42

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): reject malformed artifact base64 · openclaw...
vincentkoc · 2026-06-20 · via Recent Commits to openclaw:main

@@ -51,6 +51,11 @@ type ArtifactCollectionOptions = {

5151

downloadArtifactId?: string;

5252

};

535354+

type ArtifactBase64Payload = {

55+

data?: string;

56+

sizeBytes: number;

57+

};

58+5459

type ResolvedArtifactSession = {

5560

sessionKey: string;

5661

agentId?: string;

@@ -155,40 +160,85 @@ function base64FromDataUrl(value: string): string | undefined {

155160

if (!metadata.includes(";base64")) {

156161

return undefined;

157162

}

158-

return trimmed.slice(commaIndex + 1).replace(/\s+/g, "");

163+

return trimmed.slice(commaIndex + 1);

159164

}

160165161166

function isBase64Whitespace(value: string): boolean {

162167

return value === " " || value === "\n" || value === "\r" || value === "\t";

163168

}

164169165-

function estimateBase64Size(value: string | undefined): number | undefined {

170+

function isArtifactBase64DataChar(value: string): boolean {

171+

const code = value.charCodeAt(0);

172+

return (

173+

(code >= 0x41 && code <= 0x5a) ||

174+

(code >= 0x61 && code <= 0x7a) ||

175+

(code >= 0x30 && code <= 0x39) ||

176+

value === "+" ||

177+

value === "/" ||

178+

value === "-" ||

179+

value === "_"

180+

);

181+

}

182+183+

function normalizeArtifactBase64Char(value: string): string {

184+

if (value === "-") {

185+

return "+";

186+

}

187+

if (value === "_") {

188+

return "/";

189+

}

190+

return value;

191+

}

192+193+

function readArtifactBase64Payload(

194+

value: string | undefined,

195+

opts: { includeData: boolean },

196+

): ArtifactBase64Payload | undefined {

166197

if (!value) {

167198

return undefined;

168199

}

169200

let encodedLength = 0;

170201

let padding = 0;

202+

let sawPadding = false;

203+

let data = opts.includeData ? "" : undefined;

171204

for (const char of value) {

172-

if (!char || isBase64Whitespace(char)) {

173-

continue;

174-

}

175-

encodedLength += 1;

176-

}

177-

for (let index = value.length - 1; index >= 0 && padding < 2; index -= 1) {

178-

const char = value[index];

179-

if (!char || isBase64Whitespace(char)) {

205+

if (isBase64Whitespace(char)) {

180206

continue;

181207

}

182208

if (char === "=") {

183209

padding += 1;

210+

if (padding > 2) {

211+

return undefined;

212+

}

213+

sawPadding = true;

214+

encodedLength += 1;

215+

if (data !== undefined) {

216+

data += char;

217+

}

184218

continue;

185219

}

186-

break;

220+

if (sawPadding || !isArtifactBase64DataChar(char)) {

221+

return undefined;

222+

}

223+

encodedLength += 1;

224+

if (data !== undefined) {

225+

data += normalizeArtifactBase64Char(char);

226+

}

187227

}

188228

if (encodedLength === 0) {

189229

return undefined;

190230

}

191-

return Math.max(0, Math.floor((encodedLength * 3) / 4) - padding);

231+

const remainder = encodedLength % 4;

232+

if ((padding > 0 && remainder !== 0) || remainder === 1) {

233+

return undefined;

234+

}

235+

if (data !== undefined && padding === 0 && remainder > 0) {

236+

data += "=".repeat(4 - remainder);

237+

}

238+

return {

239+

...(data !== undefined ? { data } : {}),

240+

sizeBytes: Math.max(0, Math.floor((encodedLength * 3) / 4) - padding),

241+

};

192242

}

193243194244

function mediaUrlValue(value: unknown): string | undefined {

@@ -274,10 +324,14 @@ function resolveBlockDownload(

274324

const dataUrl = [url, sourceUrl, imageUrl, audioUrl, data, content, sourceData].find(

275325

(value) => typeof value === "string" && /^data:/i.test(value),

276326

);

277-

const base64FromDetectedDataUrl = dataUrl ? base64FromDataUrl(dataUrl) : undefined;

278-

const directBase64 = [data, sourceData, content].find(

279-

(value) => typeof value === "string" && !/^data:/i.test(value),

327+

const base64FromDetectedDataUrl = readArtifactBase64Payload(

328+

dataUrl ? base64FromDataUrl(dataUrl) : undefined,

329+

opts,

280330

);

331+

const directBase64 = [data, sourceData, content]

332+

.filter((value): value is string => typeof value === "string" && !/^data:/i.test(value))

333+

.map((value) => readArtifactBase64Payload(value, opts))

334+

.find((value): value is ArtifactBase64Payload => value !== undefined);

281335

const base64 = base64FromDetectedDataUrl ?? directBase64;

282336

const remoteUrl = [url, sourceUrl, imageUrl, audioUrl].find(

283337

(value) => typeof value === "string" && isSafeDownloadUrl(value),

@@ -292,9 +346,14 @@ function resolveBlockDownload(

292346

const sizeBytes =

293347

typeof explicitSize === "number" && Number.isFinite(explicitSize) && explicitSize >= 0

294348

? Math.floor(explicitSize)

295-

: estimateBase64Size(base64);

349+

: base64?.sizeBytes;

296350

if (base64) {

297-

return { mode: "bytes", ...(opts.includeData ? { data: base64 } : {}), mimeType, sizeBytes };

351+

return {

352+

mode: "bytes",

353+

...(base64.data ? { data: base64.data } : {}),

354+

mimeType,

355+

sizeBytes,

356+

};

298357

}

299358

if (remoteUrl) {

300359

return { mode: "url", url: remoteUrl, mimeType, sizeBytes };