Skip to content

fix(ui): prevent automatic remote Markdown images - #909

Merged
small-angel merged 3 commits into
alphaXiv:mainfrom
dajiaohuang:fix/430-local-media-policy
Nov 6, 2026
Merged

small-angel merged 3 commits into
alphaXiv:mainfrom
dajiaohuang:fix/430-local-media-policy

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #908

Chat and Artifacts Markdown loaded remote images on render, and the library picker loaded remote cover thumbnails. A remote Markdown image now renders as a link labelled with its alt text or URL (plain text when it already sits inside a link), local images still render, and the picker shows its file icon. HTML report previews keep loading remote assets: a report is code the user chose to open.

Proved with ui/tests/markdownImages.test.mjs in pnpm test (fails with the plugin disabled; full suite 698/698), typecheck and lints, and a browser render of both surfaces showing no remote requests or nested links.

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Assisted-by: claude-opus-5.5
Assisted-by: gpt-6.1-sol

@small-angel

Copy link
Copy Markdown
Contributor

nice

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect report previews and the library picker in the UI.

No blocking behavior defect was established, but the documentation and comment must meet repository requirements before merging.

Findings

  1. P2 Network description is outdated ▶
  2. P2 Image blocking lacks browser coverage ▶
  3. P2 Comment breaks the format rule ▶
Fix with agent prompt
### Issue 1
ui/src/components/LibraryPicker.tsx:264
Removing the thumbnails makes `arc/storage.md` falsely say the library picker loads images from alphaXiv’s CDN. The repository guide requires fixing essay statements that a change makes false. Update that statement before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
ui/tests/htmlPreviewAssets.test.mjs:56
This assertion checks only that the mock recorded a policy node. The mock’s `outerHTML` is empty, so the test never checks the returned HTML or whether a browser blocks image requests. It can pass even if image blocking breaks.

Add a repeatable browser test for remote images, CSS backgrounds, script-created images, and an allowed local image, while confirming scripts still run.

### Issue 3
ui/src/components/HtmlPreview.tsx:92-93
The new comment spans two lines, but the repository guide requires comments to stay on one line. Shorten it to one line explaining why images are restricted while scripts remain enabled. This repository requirement must be met before merging.

```suggestion
  // Block network images while keeping inlined project images and report scripts enabled.
```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR adds an image-only policy to HTML report previews and replaces remote library thumbnails with the existing file icon.

  • HTML report previews block automatic remote image loads.
  • Library paper rows use a file icon instead of remote covers.

Reviews (1) · Last reviewed commit: "fix(ui): prevent automatic remote image ..." · Reviewed by Greptile

Comment thread ui/src/components/LibraryPicker.tsx Resolved
Comment thread ui/tests/htmlPreviewAssets.test.mjs Outdated
});
const resolved = [];
await exports.assembleDocument("", (src) => { resolved.push(src); return `/root/${src}`; }, new AbortController().signal);
assert.ok(doc.headNodes.some((node) => node.attributes["http-equiv"] === "Content-Security-Policy" && node.attributes.content === "img-src data: blob:"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Image blocking lacks browser coverage

This assertion checks only that the mock recorded a policy node. The mock’s outerHTML is empty, so the test never checks the returned HTML or whether a browser blocks image requests. It can pass even if image blocking breaks.

Add a repeatable browser test for remote images, CSS backgrounds, script-created images, and an allowed local image, while confirming scripts still run.

Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/tests/htmlPreviewAssets.test.mjs
Line: 56

Comment:
**Image blocking lacks browser coverage**

This assertion checks only that the mock recorded a policy node. The mock’s `outerHTML` is empty, so the test never checks the returned HTML or whether a browser blocks image requests. It can pass even if image blocking breaks.

Add a repeatable browser test for remote images, CSS backgrounds, script-created images, and an allowed local image, while confirming scripts still run.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread ui/src/components/HtmlPreview.tsx Outdated
Comment on lines +92 to +93
// Project images are inlined below. Prevent automatic network image loads,
// including srcset and CSS backgrounds, without disabling report scripts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Comment breaks the format rule

The new comment spans two lines, but the repository guide requires comments to stay on one line. Shorten it to one line explaining why images are restricted while scripts remain enabled. This repository requirement must be met before merging.

Suggested change
// Project images are inlined below. Prevent automatic network image loads,
// including srcset and CSS backgrounds, without disabling report scripts.
// Block network images while keeping inlined project images and report scripts enabled.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/components/HtmlPreview.tsx
Line: 92-93

Comment:
**Comment breaks the format rule**

The new comment spans two lines, but the repository guide requires comments to stay on one line. Shorten it to one line explaining why images are restricted while scripts remain enabled. This repository requirement must be met before merging.

```suggestion
  // Block network images while keeping inlined project images and report scripts enabled.
```

**Context Used:** AGENTS.md ([source](https://github.com/alphaxiv/openresearch/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@small-angel

Copy link
Copy Markdown
Contributor

comment written by Claude Sonnet 5.5

the two changes here are right for what they cover: the img-src data: blob: meta lands first in <head>, local images are already inlined as data: so they keep working, and scripts stay enabled. the problem is that the app-wide rule is "external images don't load by default", and this only gets there for two surfaces. since we're making the change, it should be thorough. the issue is a contributor write-up of this patch, so it shouldn't be what bounds the scope.

blocking, remaining places that still load external images or media:

  • chat markdown: Md.tsx passes https?:// and // image URLs straight through the resolver (/^(https?:)?\/\//i.test(src)), so a remote ![](https://…) in a chat still loads.
  • artifacts markdown: ArtifactsTab.tsx resolve() returns external srcs unchanged (isExternalSrc(src)), and the img component renders them.
  • html preview media: img-src doesn't gate <video>, <audio> or <source>, so remote media in a report still auto-loads. adding media-src data: blob: to the same meta covers it. if that's deliberately left out, say so in the description.

what to do with a blocked external image in markdown is a taste call. dropping it silently hides that something was there; rendering the alt text or a plain link keeps it visible.

non-blocking: AlphaXivPaper.coverBlobId in ui/src/api.ts is now unread by the ui. it's a backend wire field, so leaving it is fine.

Clover's concern is that more restrictions could break existing html reports. reports that embed remote images or media are expected to break under this policy, so that isn't a reason to hold back. the one case worth confirming is local files: a report referencing a local image that the inliner skips (over the 4 MB budget, 200 file cap, or srcset/CSS url()) goes blank. it did before as well, so no regression.

@dajiaohuang
dajiaohuang force-pushed the fix/430-local-media-policy branch from 29d1f26 to 2b8ac2a Compare November 5, 2026 19:32
@small-angel

Copy link
Copy Markdown
Contributor

comment written by Claude Sonnet 5.5

thanks for covering the markdown and media gaps, the link fallback with alt text is what we wanted. the review turned up one change of direction and a conflict.

blocking: drop the html preview restriction. markdown images are passive, so a remote ![](https://…) leaks on render with nobody opening anything. an html report is code the agent wrote that the user chose to open, its scripts can already fetch and load CDN scripts, and an img-src / media-src csp only closes part of that. it also breaks plots that pull remote assets. so the patch should be the library picker plus the Md.tsx and ArtifactsTab.tsx image handling. concretely, revert the HtmlPreview.tsx csp, ui/tests/browser/htmlPreview.* and the htmlPreviewAssets.test.mjs assertion, and update the title and description to match.

blocking: the branch conflicts with main in arc/storage.md (#895 touched the same paragraph). drop that hunk from this patch and rebase.

once those are in and checks are green, this is good to merge.

@dajiaohuang
dajiaohuang force-pushed the fix/430-local-media-policy branch from 164cf54 to 360ab31 Compare November 5, 2026 21:34
@dajiaohuang dajiaohuang changed the title Avoid automatic remote images in report previews fix(ui): prevent automatic remote Markdown images Nov 5, 2026
Chat and Artifacts Markdown now share one rehype plugin for remote images, so a badge inside a link renders as its text instead of a nested anchor, and remote images no longer form an image carousel of links. The happy-dom test runs in `pnpm test`, replacing the Playwright test CI never ran, and the now-unread `versionId` and `coverBlobId` paper fields go.

Assisted-by: claude-opus-5.5
Assisted-by: gpt-6.1-sol
@small-angel
small-angel merged commit d3fdcbe into alphaXiv:main Nov 6, 2026
12 checks passed
@small-angel

Copy link
Copy Markdown
Contributor

we got this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid automatic remote images in report previews and library picker

2 participants