Skip to content

Web UI: preview image URLs on Ctrl/Cmd + hover - #109347

Merged
alexey-milovidov merged 23 commits into
masterfrom
web-ui-hover-image-preview
Jul 25, 2026
Merged

alexey-milovidov merged 23 commits into
masterfrom
web-ui-hover-image-preview

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

Preview image URLs in the Web UI (play.html) by holding Ctrl (or Cmd on macOS) while hovering.

When a table cell holds a URL ending in .jpg, .jpeg, .png, .gif, or .webp (optionally followed by a query string or fragment), holding Ctrl/Cmd while hovering over the link shows a floating preview of the image that follows the cursor. A plain hover does nothing: the preview only loads while the modifier is held, so untrusted result data never triggers an outbound request without an explicit user gesture. The link's tooltip advertises the gesture.

The preview is capped to half the viewport in each dimension (max-width: 50vw, max-height: 50vh) while preserving aspect ratio; smaller images keep their natural size. A single reused element serves every previewed link. The preview stays hidden until the new image finishes loading, and it is torn down on mouseleave, scroll, blur, and when the result is cleared. When hidden, it detaches src so an in-flight download is aborted. Only http/https URLs qualify, and the extension is checked against the URL's path only (not its query or fragment).

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

In the Web UI (Play), holding Ctrl (Cmd on Mac) while hovering over a table cell whose value is a URL ending in .jpg, .jpeg, .png, .gif, or .webp now shows a preview of the image.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.128 (included in 26.8 and later)

alexey-milovidov and others added 2 commits July 3, 2026 20:14
In `play.html`, when a table cell holds a URL ending in `.jpg`, `.jpeg`,
`.png`, `.gif`, or `.webp` (optionally followed by a query or fragment),
hovering over the link shows a floating preview of the image that follows
the cursor.

The preview is capped to half the viewport in each dimension
(`max-width: 50vw`, `max-height: 50vh`) while preserving aspect ratio;
smaller images keep their natural size. A single reused element serves
every hovered link, and the preview hides itself if the image fails to
load.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Previously the preview element's `display` was set to `block` synchronously
on `mouseenter`, so the previously loaded image stayed visible while the new
one was still loading. Now the preview is kept hidden until the new image's
`load` event fires, and that handler ignores loads the cursor has already
moved away from or superseded, so a late load cannot reveal a stale preview.
Re-entering a link whose image is still loaded shows it immediately, since no
`load` event fires for an unchanged `src`.

Also remove the popup's inner padding and border-radius so the image sits
flush against the frame.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [00ac0e5]

Summary: ✅


AI Review

Summary

This PR adds Ctrl/Cmd-gated image previews in the Web UI and backs the state machine with a focused integration harness. I re-checked the current play.html implementation and the final test_play_image_preview coverage against the earlier review threads; the plain-hover fetch guard, teardown ownership, scroll handling, and production-path regression coverage are all addressed in the current code, and I did not find any remaining issues worth new inline comments.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 3, 2026
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
@alexey-milovidov
alexey-milovidov requested a review from pamarcos July 3, 2026 19:00
Address review feedback: the floating image preview uses `position: fixed`,
so scrolling while the cursor stays still can move the hovered link out from
under the pointer without delivering a mouse event, leaving the preview pinned
on screen after the cell it previews has scrolled away. This is the same
scroll-driven hover edge case the file already handles for the table balloons
via the global capture-phase `scroll` handler.

Factor the hide logic into `hideImagePreview` (reused by `mouseleave`) and call
it from the global `scroll` handler. Clearing `image_preview_hovered_url` there
also suppresses an in-flight `load` that would otherwise reveal a stale preview
after the scroll.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@pamarcos

pamarcos commented Jul 6, 2026

Copy link
Copy Markdown
Member

Feedback from GPT-5.5:
Hovering an image URL automatically sets image_preview.src, so the browser issues a GET to a URL from query results without explicit user action. This is a security/behavior change because untrusted result data can make the operator's browser contact attacker-controlled or internal hosts. Please make preview an explicit opt-in/click action, or restrict it to safe origins.

@pamarcos pamarcos self-assigned this Jul 6, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

This is on point, but hard to avoid. Maybe preview only when the user holds Ctrl. And/or display a confirmation on the first time.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The hypothetical attack scenario sounds far-fetched.

Comment thread programs/server/play.html Resolved
The floating `position: fixed` image preview was hidden only on `mouseleave`
and `scroll`. Rerunning a query (`Ctrl+Enter`) tears down the hovered result
cell through `clear` (called from `postSingle`, `postMulti`, and history
restore) without delivering either event, so the preview could stay pinned
over the next result until some later scroll.

Call `hideImagePreview` from `clear` so the preview cannot outlive the cell it
was anchored to, regardless of how the result is torn down.

Addresses review feedback on
#109347

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@pamarcos

Copy link
Copy Markdown
Member

Feedback from GPT-5.6 Sol Pro

The preview currently turns untrusted result data into browser requests without an explicit user action:

  1. image_preview.src = url runs on mouseenter. A result containing an attacker-controlled or browser-internal URL can therefore disclose that it was hovered and make the operator's browser contact the target. This should require deliberate opt-in rather than an unconditional hover request, as also discussed in the unresolved thread.

  2. The extension regex operates on the complete string. For example, https://internal.example/admin/restart#preview.png passes the check, but the browser strips the fragment and requests /admin/restart. Please parse the URL and validate only its pathname; query-string or fragment suffixes must not establish that the target is an image.

  3. hideImagePreview only changes display. Leaving the link, scrolling, or replacing the result does not clear src, so a slow or very large download continues while hidden. The hide/teardown path should remove src and clear the associated handlers/state.

Please add a browser/network test proving that no request occurs before opt-in, fragment/query suffixes are rejected, and every hide/teardown path releases the image request.

alexey-milovidov and others added 2 commits July 15, 2026 07:13
A query string or fragment ending in an image extension passed the
check, e.g. `https://internal.example/admin/restart#preview.png`, while
the browser strips the fragment and requests the non-image path. Parse
the URL and test the extension only on its `pathname`, so query-string
or fragment suffixes cannot establish that the target is an image.

Addresses review feedback:
#109347 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
`hideImagePreview` only flipped `display`, so a slow or large image kept
downloading invisibly after the preview was dismissed by `mouseleave`,
scroll, or result teardown. Detach `src` (which aborts the fetch) and
clear the `load`/`error` handlers and the cached URL state on hide.

Addresses review feedback:
#109347 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Points 2 and 3 are addressed:

  • 2 (extension check on the full string): fixed in 3b0576e — the URL is parsed and the extension is now tested only against its pathname, so a query-string or fragment suffix such as https://internal.example/admin/restart#preview.png no longer qualifies (verified against fragment/query attack shapes and legitimate parameterized image URLs).
  • 3 (hidden download keeps running): fixed in 4c0c26a — hideImagePreview now detaches src (which aborts the in-flight fetch) and clears the load/error handlers and cached URL state. This single function covers every hide path: mouseleave, the capture-phase scroll handler, and result teardown via clear.

1 (opt-in before any hover fetch) is the same open question as the unresolved review thread and stays with that design discussion.

On the test: play.html has no browser/DOM test harness in CI (it is covered only by HTTP-serving tests), so an automated browser/network test is not feasible here. The extension validation is a pure predicate and was verified standalone with node against the cases above; the download abort relies on the specified img behavior of aborting the fetch when src is removed.

@pamarcos

Copy link
Copy Markdown
Member

Feedback from GPT-5.6 Sol Pro

The fragment/query extension bypass and hidden-resource cleanup from the previous round are fixed. The security concern in the unresolved thread remains: mouseenter still assigns the result URL directly to image_preview.src.

Merely moving the pointer over untrusted query data therefore makes the operator's browser issue a GET to an attacker-controlled or browser-reachable internal endpoint. Pathname validation does not close this because a valid .png URL can redirect elsewhere. Please require an explicit user opt-in before assigning src, and add reproducible browser/network coverage proving request initiation and teardown behavior.

Address the recurring security Blocker on this PR (reviewer feedback from
`clickhouse-gh`/`pamarcos`, repeated across multiple rounds including a
redirect-bypass variant that pathname validation cannot close): merely
hovering a table cell whose value is an image URL previously made the
browser issue a `GET` to that URL immediately, i.e. to arbitrary
attacker-controlled or internal hosts present in untrusted query results.

Implement the modifier-gated opt-in mitigation floated earlier in the PR
discussion: the preview now only loads and displays while the user holds
Ctrl (`Meta`/Cmd on Mac) over the link, tracked via `image_preview_modifier_held`.
Hovering without the modifier only records the candidate URL
(`image_preview_candidate_url`); no `src` is assigned and no request is made
until the modifier is pressed. Releasing the modifier hides the preview
(quick-look/peek semantics), and `blur` also releases it so a stuck "held"
state cannot survive the window losing focus without a `keyup`. A `title`
attribute on the link advertises the gesture.

Verified with a standalone state-machine harness (`node`) that plain hover
never triggers a fetch, that the modifier gates both directions, and that
holding the modifier before entering the link fetches immediately.
Comment thread programs/server/play.html Resolved
Address the AI review Major at `programs/server/play.html`: the
modifier-gated image preview is supposed to fetch only for the link
currently under the cursor, but `hideImagePreview` deliberately keeps
`image_preview_candidate_url` so that releasing and re-pressing the
modifier while still hovering the same link re-previews it. The `scroll`
handler and the result `clear` path called `hideImagePreview` directly,
so after a link scrolled out from under a stationary cursor (which fires
no `mouseleave`), or after a query rerun tore the result cell down, a
later `Ctrl`/`Cmd` press still fetched the now-stale candidate URL - an
unexpected outbound request for a link no longer under the pointer.

Add `dismissImagePreview`, which forgets `image_preview_candidate_url`
and then hides, and use it from `mouseleave`, `scroll`, and `clear` -
every teardown path where the cursor is no longer over the link. Plain
`hideImagePreview` (which keeps the candidate) is now used only on
modifier release, preserving the re-press-to-re-preview behavior.
Comment thread programs/server/play.html Resolved
Address review: the previous gate fetched from the raw `Control`/`Meta`
`keydown` handler via the latched `image_preview_candidate_url`, so an
unrelated shortcut such as `Ctrl+Enter` (rerun) or `Cmd+C` while the
cursor happened to rest on an image link still assigned `img.src` and
made the browser contact an untrusted URL. Now pressing the modifier
only arms the preview; the fetch happens exclusively from `mouseenter`
and `mousemove` on the link with the modifier already held, a gesture
that cannot piggyback on ordinary shortcuts. This also removes the
candidate-URL latch and `dismissImagePreview`, since the pointer
handlers always carry the correct URL.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109347&sha=82d90b3a59093fdbdc9d2d2f097c79579b32001b&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

AST fuzzer (amd_msan) died with MemorySanitizer: use-of-uninitialized-value, but the report is truncated ("MemorySanitizer: nested bug in the same thread, aborting." followed by "LLVM ERROR: IO failure on output stream: Broken pipe"), so no stack trace was written. The last query before the server died (fuzzing step 146, also the dumped fuzzed AST) was:

SELECT number FROM remote('127.0.0.{1,2,3}', numbers_mt(1)) ORDER BY number ASC WITH FILL TO 1

This PR only touches programs/server/play.html (static HTML, zero C++), so the failure cannot be caused by it. The other red on this head, Stress test (arm_asan_ubsan), is already tracked in #110343.

Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits July 18, 2026 21:38
…roll in the image-preview test

The image-preview regression harness added earlier wired a hand-built `<a>`
straight into `attachImagePreview` and fired `scroll` on `document` directly, so
it never ran the two production paths that were actually fixed during review: the
URL-qualification gate in `QueryResultElement._renderCell` (`^https?://\S+$` plus
the image-extension test on `new URL(text).pathname`) and the capture-phase
`this.shadowRoot` scroll listener that dismisses the preview on a scroll inside
the `query-result` shadow tree. The suite would therefore stay green if the
fragment/query bypass were reintroduced, a non-`http(s)` URL were previewed, the
shadow-root dismissal were deleted, or its capture phase were lost.

Make the fake DOM able to construct a real `QueryResultElement` (a functional
`HTMLElement` base with `attachShadow`/`getElementById`) and give `dispatchEvent`
real capture -> target -> bubble propagation up the `parentNode` chain, then:

- add a `url-gate` scenario that runs `_renderCell` for image paths, image
  extensions hidden in a query/fragment, a non-`http(s)` scheme, and plain text,
  asserting which cells become previewable via an actual `Ctrl`+hover;
- add a `shadow-scroll` scenario that puts the rendered cell in a real shadow
  root and fires `scroll` from the inner `.cell-content` scroller, so the event
  routes through the capture phase to the shadow-root listener.

Verified standalone against `programs/server/play.html` (39 checks pass) and
verified non-vacuous: the harness fails when the pathname gate is replaced by a
full-string match, when the shadow-root scroll listener is deleted, and when that
listener loses its capture phase.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…image-preview

# Conflicts:
#	programs/server/play.html
@pamarcos

Copy link
Copy Markdown
Member

Feedback from GPT-5-6 Sol

The Ctrl/Cmd plus pointer-movement opt-in fixes the unsolicited request concern, and pathname validation/resource cleanup remain correct. The cleanup is still attached to the wrong lifecycle, however.

clearPanel removes a tab's result without calling hideImagePreview. postSingle, postMulti, materializeResult, and beginFlight all use this path, so rerunning can remove the hovered link while leaving the global fixed preview, request, and late-load handler active. Hiding or removing a tab panel has the same ownership gap. Cleanup exists only in the auxiliary global clear wrapper.

The current integration test calls that wrapper, so its clear-teardown scenario passes without exercising production clearPanel; this is already captured in the unresolved test thread.

Please move teardown into the active result/panel lifecycle, while ensuring a background tab clear cannot dismiss an unrelated active preview. Add coverage for a real rerun through clearPanel, panel switching, and tab removal.

Address review (pamarcos / `clickhouse-gh`): after the tabs rework, the
production result teardown goes through `clearPanel` (called from
`postSingle`/`postMulti`/`materializeResult`/`beginFlight`), panel switching
(`setActivePanel`), and tab removal (`panel.remove`) - none of which called
`hideImagePreview`. Only the auxiliary global `clear` wrapper did, so rerunning
a query, switching tabs, or closing a tab could remove the hovered image link
while leaving the floating `position: fixed` preview, its request, and its
late-load handler alive.

Anchor the single global preview to the `query-result` whose cell owns it
(`image_preview_owner`, set in `showImagePreview`, cleared in
`hideImagePreview`). Dismiss it from the real result lifecycle:
`QueryResultElement.clear` and `disconnectedCallback` call
`hideImagePreviewOwnedBy(this)` (which hides only if the preview is anchored to
that result), and `setActivePanel` dismisses a preview whose owner is not in the
newly active panel. This tears the preview down on rerun / panel switch / tab
close, while a background tab's teardown cannot dismiss a preview owned by
another, still-hovered result.

Extend `tests/integration/test_play_image_preview/image_preview_harness.js` to
drive the real production paths: the harness DOM now supports a working
`contains` and fires `connectedCallback`/`disconnectedCallback`, so new
scenarios build genuine `QueryResultElement`s in real tabs and exercise
`clearPanel` (rerun), `setActivePanel` (switch), and `panel.remove` (tab close),
including the negative cases where a background/unrelated teardown must not
dismiss the active preview. Verified non-vacuous: each check fails when the
corresponding teardown or the ownership scoping is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Thanks @pamarcos — good catch. Fixed in 757f3852877: teardown is moved out of the auxiliary global clear wrapper and into the active result/panel lifecycle. The single global preview is now anchored to the query-result that owns the hovered link (image_preview_owner), and it is dismissed from:

  • QueryResultElement.clear — the production rerun path (clearPanel from postSingle/postMulti/materializeResult/beginFlight);
  • QueryResultElement.disconnectedCallback — tab removal (panel.remove) and multi-query re-render;
  • setActivePanel — panel switching (dismiss unless the owner is in the newly active panel).

Dismissal is owner-scoped (hideImagePreviewOwnedBy), so a background tab clear/switch/removal cannot dismiss a preview owned by another, still-hovered result.

Coverage added to the integration harness for a real rerun through clearPanel, panel switching, and tab removal — including the negative background-tab cases — driving genuine QueryResultElements through the production functions. Verified non-vacuous (each check fails if the corresponding teardown or the ownership scoping is removed).

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Both failures on 788fd0ac668 are engine-side and unrelated to this PR (the diff is play.html plus a JS test harness only — zero C++):

Re-merged master (28bd452c56d) for a fresh CI run.

@groeneai

Copy link
Copy Markdown
Collaborator

03915_exchange_tables_race (#110133) already has an in-progress fix from both angles, so I won't open a competing PR:

Once #110048 lands, the multiply LOGICAL_ERROR on the amd_llvm_coverage, old analyzer, ..., 2/3 shard should stop. Tracking both to merge.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Both red checks on 28bd452c56d are engine/CI-side and unrelated to this PR (the diff is play.html plus a JS test harness only — zero C++):

Review state: zero unresolved threads, AI review verdict is Approve.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master into the branch (658758df445) to pull in the settings-changes-history fix for join_runtime_filter_min_probe_rows (#111671, follow-up to #104860) — this clears two of the three Upgrade-check reds on 2e59649ee55.

The remaining red, Failed to mark the rotated system log table as readonly on system.metric_log (QUERY_IS_TOO_LARGE vs max_query_size), is an engine-side upgrade-check issue unrelated to this PR (the diff is play.html plus a JS test harness only — zero C++); the fix is in progress in #111703.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master into the branch (00ac0e54170) to pull in #111703, which fixes the system.metric_log QUERY_IS_TOO_LARGE readonly-rotation error that caused the Upgrade check (amd_release) red on 658758df445.

The remaining red — Stress test (amd_debug), logical error Cannot create part with type A and storage type B because table does not support polymorphic parts — is engine-side and unrelated to this PR (the diff is play.html plus a JS test harness only, zero C++). A fix is already open: #111626.

@@ -0,0 +1,992 @@
#!/usr/bin/env node

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LOL - I've often said that Web UI does not have tests (because I'm afraid that the ratio of test LOC to code LOC will be around 100x), but it just found a way to add them anyway.

Accepted.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 25, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

We need discoverability - when the mouse is over the image link, the title should say "Ctrl/Cmd for preview".

Merged via the queue into master with commit c41e1d7 Jul 25, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the web-ui-hover-image-preview branch July 25, 2026 17:29
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 25, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The floating `position: fixed` image preview was hidden only on `mouseleave`
and `scroll`. Rerunning a query (`Ctrl+Enter`) tears down the hovered result
cell through `clear` (called from `postSingle`, `postMulti`, and history
restore) without delivering either event, so the preview could stay pinned
over the next result until some later scroll.

Call `hideImagePreview` from `clear` so the preview cannot outlive the cell it
was anchored to, regardless of how the result is torn down.

Addresses review feedback on
ClickHouse#109347

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
A query string or fragment ending in an image extension passed the
check, e.g. `https://internal.example/admin/restart#preview.png`, while
the browser strips the fragment and requests the non-image path. Parse
the URL and test the extension only on its `pathname`, so query-string
or fragment suffixes cannot establish that the target is an image.

Addresses review feedback:
ClickHouse#109347 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`hideImagePreview` only flipped `display`, so a slow or large image kept
downloading invisibly after the preview was dismissed by `mouseleave`,
scroll, or result teardown. Detach `src` (which aborts the fetch) and
clear the `load`/`error` handlers and the cached URL state on hide.

Addresses review feedback:
ClickHouse#109347 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ge-preview

Web UI: preview image URLs on Ctrl/Cmd + hover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants