A link to a neighbouring page now works in the preview, and anchors finally jump - #193
Open
astetic-dev wants to merge 1 commit into
Open
A link to a neighbouring page now works in the preview, and anchors finally jump#193astetic-dev wants to merge 1 commit into
astetic-dev wants to merge 1 commit into
Conversation
…inally jump Refs #192. A generated report points at its neighbours -- acties.html links to dashboard.html#AST-DHR-AIT-0009 -- and that did nothing. The preview runs in a srcdoc iframe with sandbox="allow-scripts": no origin of its own, so it cannot navigate. The bridge caught the click and then dropped it. The parent can read the target file and render it again. What is allowed is decided in Rust rather than by the page: that page is generated, untrusted, and can post a message without a click. Relative only (no scheme, no drive letter, not root-anchored), `..` collapsed lexically instead of with canonicalize -- which follows symlinks and could step outside the boundary -- checked component-wise against the session folder, and limited to html/htm/md. A link pointing past it does nothing, exactly as before. Two things surfaced by running the real bridge in a browser engine rather than assuming: scrollIntoView with behavior:'smooth' does NOTHING in this sandbox. scrollY stays 0, with no error, while scrollTo and scrollIntoView without smooth both work. The smooth has been there since the bridge was written, so in-document anchors in the preview have never jumped -- including the ones the README credits the Markdown renderer with. And a jump on DOMContentLoaded is undone by the browser once the document finishes loading, so an incoming fragment is retried after load.
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.
Closes #192.
The preview runs in a
srcdociframe withsandbox="allow-scripts", so it cannot navigate — a relative link had nowhere to resolve to and the bridge dropped it. The parent can read the target and render it again, so that is the route.What may be followed is decided in Rust, not by the page.
preview_link_targettakes relative links only (no scheme, no drive letter, not root-anchored), collapses..lexically rather than withcanonicalize(which follows symlinks and could step outside the boundary), checks the result component-wise against the session folder, and limits it tohtml/htm/md. A page opened outside the session folder falls back to its own folder. Anything else does nothing, as before.Two things measured, not assumed
I ran the real bridge inside a sandboxed iframe in Chromium and clicked every kind of link.
scrollIntoView({behavior: 'smooth'})does nothing in this sandbox —scrollYstays 0, no error — whilescrollToandscrollIntoView()work (500 and 1504 on the same document). Thatsmoothpredates this change, so in-document anchors in the preview have never jumped, including the ones the README credits the Markdown renderer with. Fixed here.A jump on
DOMContentLoadedis also undone once the document finishes loading, so an incoming fragment is retried afterload.Verified
./, subfolder, percent-encoded space, and..within the folder; refusals for../../, root-anchored, drive letter,file://,http://,javascript:, empty, bare anchor, and a sibling folder sharing a prefix; and the previewable-extension set.taurus-open-localwith the raw href,https:andmailto:still relay astaurus-open-external,javascript:relays nothing and raises no dialog,e.source === iframe.contentWindowholds (the guard the parent uses), and the incoming fragment lands at the right offset.