fix: allow displaying images in plans from local filesystem#151
Closed
contextbotai[bot] wants to merge 2 commits into
Closed
fix: allow displaying images in plans from local filesystem#151contextbotai[bot] wants to merge 2 commits into
contextbotai[bot] wants to merge 2 commits into
Conversation
When plans contain markdown images with absolute file paths (e.g. ), the browser resolves them relative to the localhost server origin. Previously these requests returned 404, causing broken images. Add a serveLocalImage handler to the annotation server that serves files from disk when the request path has an allowed image extension (.png, .jpg, .jpeg, .gif, .svg, .webp, .avif, .ico, .bmp) and the file exists. Path traversal is mitigated via normalize + absolute path check. Non-image extensions are rejected to limit exposure. Closes PLAN-55
Contributor
|
@contextbotai - review this diff, compare it against conventions and rules in this codebase and refactor to follow instructions/ rules / conventions. |
Replace the synchronous existsSync from node:fs with the idiomatic Bun.file(path).exists() API in serveLocalImage. This follows the bun-native-apis convention which requires preferring Bun.* globals over Node equivalents in server code. The function becomes async (returning Promise<Response | null>) since Bun.file().exists() is async, which is fine given it's only called from within the async fetch handler.
Contributor
|
I don't know that I love this pattern of serving images from disk. This would be problematic when we allow sharing plans. I think we should explore some other paths, like having the server pull the image and directly encoding it the payload, etc. |
Contributor
Author
|
Thanks for your feedback! We're actively building the ability to handle comments on ContextBot PRs automatically. We'll take a look at your comment shortly. In the meantime, come chat with the founders on Slack. We'd love to hear from you! This is an automated response from ContextBot. |
Contributor
|
I think we should use another approach (e.g., #165) |
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
Fixes PLAN-55 — images in plans that reference local file paths (e.g.
/Users/<user>/.codex/generated_images/...) now render correctly in the plan review UI.Problem
When a plan contains markdown images with absolute file paths like:
The browser resolves these relative to the localhost server origin, producing requests like
http://localhost:<port>/Users/alice/.codex/generated_images/.... The annotation server had no handler for these paths and returned 404, causing broken images.Solution
Added a
serveLocalImagehandler to the annotation server (packages/server/src/annotation.ts) that:.png,.jpg,.jpeg,.gif,.svg,.webp,.avif,.ico,.bmp)..segments) to prevent traversalBun.file()which automatically sets the correct Content-TypeThis is placed as a fallback route — it only fires after all named routes (
/,/config,/payload,/update-notice,/submit) have been checked, so it cannot shadow existing functionality.Safety considerations
/etc/passwdreturn 404)node:path.normalizeand verified to still be absolute after normalizationVerification
serveLocalImage+ integration)