fix(line): migrate media downloads to saveMediaBuffer for sandbox access#353
Open
BingqingLyu wants to merge 2 commits into
Open
fix(line): migrate media downloads to saveMediaBuffer for sandbox access#353BingqingLyu wants to merge 2 commits into
BingqingLyu wants to merge 2 commits into
Conversation
…nd improve MIME detection Migrate LINE media downloads from buildRandomTempFilePath (/tmp) to saveMediaBuffer (~/.openclaw/media/inbound/) so files are accessible inside the sandbox. Also: - Switch from getMessageContent to getMessageContentWithHttpInfo to capture the Content-Type header from LINE API responses. - Pass originalFilename (from LINE file messages) through to saveMediaBuffer, enabling extension-based MIME fallback in detectMime. - Remove the local detectContentType/getExtensionForContentType helpers (now handled by saveMediaBuffer's detectMime pipeline). ✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
Addresses Greptile review: `httpResponse.httpResponse.headers` was confusing because the outer variable shadowed the SDK property name. ✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/tmpviabuildRandomTempFilePath, which is outside the sandbox root (~/.openclaw/media/). Sandboxed agents cannot access downloaded LINE media files (images, videos, audio, documents).<media:...>placeholders but the files are inaccessible.downloadLineMedianow usessaveMediaBuffer(writes to~/.openclaw/media/inbound/), captures theContent-Typeheader from LINE API responses, and passesoriginalFilenamefrom file messages through todetectMimefor extension-based MIME fallback.saveMediaBufferitself (only thefilePathargument todetectMimewas missing). No new dependencies.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
~/.openclaw/media/inbound/instead of/tmp/openclaw/. Sandboxed agents can access these files.Content-Typefrom LINE API response headers is now used for MIME detection, improving accuracy over buffer-only sniffing.filemessages (PDF, DOCX, etc.) now preserve the original filename in the saved file path, enabling extension-based MIME fallback for uncommon file types.Security Impact (required)
NoNoNo— same LINE API endpoint, switched fromgetMessageContenttogetMessageContentWithHttpInfo(same HTTP call, richer response object)NoNo— files move from/tmpto~/.openclaw/media/inbound/, both are local storage.saveMediaBufferapplies the same size limits.Yes, explain risk + mitigation: N/ARepro + Verification
Environment
channels.linewith sandbox enabledSteps
~/.openclaw/media/inbound/for the downloaded fileExpected
~/.openclaw/media/inbound/with correct MIME type and extensionActual (before fix)
/tmp/openclaw/line-media-*.extEvidence
download.test.tstests updated to match the newsaveMediaBuffer-based flow (mocksaveMediaBufferinstead offs.writeFile).Human Verification (required)
download.ts,bot-handlers.ts, andstore.tsto confirm the changes are still applicable (no upstream changes to these code paths since the original fork implementation).originalFilenameisundefinedfor non-file message types (image/video/audio) —saveMediaBufferhandles this gracefully. Oversized media rejection still works (streaming size check beforesaveMediaBuffercall).Review Conversations
N/A — fresh PR, no review conversations yet.
Compatibility / Migration
Yes— media files are now saved to a different path, but all consumers use the returnedpathfromdownloadLineMedia, not hardcoded paths.NoNoFailure Recovery (if this breaks)
/tmpstorage (non-sandbox-accessible).~/.openclaw/media/inbound/after download.Risks and Mitigations
getMessageContentWithHttpInfoAPI may behave differently across@line/bot-sdkversions (response shape).httpResponse.headersexists. TheContent-Typeheader extraction has a?? undefinedfallback for missing headers.✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)