Skip to content

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
mainfrom
feature/preview-local-links
Open

A link to a neighbouring page now works in the preview, and anchors finally jump#193
astetic-dev wants to merge 1 commit into
mainfrom
feature/preview-local-links

Conversation

@astetic-dev

Copy link
Copy Markdown
Owner

Closes #192.

The preview runs in a srcdoc iframe with sandbox="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_target takes relative links only (no scheme, no drive letter, not root-anchored), collapses .. lexically rather than with canonicalize (which follows symlinks and could step outside the boundary), checks the result component-wise against the session folder, and limits it to html/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 sandboxscrollY stays 0, no error — while scrollTo and scrollIntoView() work (500 and 1504 on the same document). That smooth predates 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 DOMContentLoaded is also undone once the document finishes loading, so an incoming fragment is retried after load.

Verified

  • 138 tests pass, 3 new: neighbouring page with fragment, ./, 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.
  • In Chromium: relative links and a subfolder link relay as taurus-open-local with the raw href, https: and mailto: still relay as taurus-open-external, javascript: relays nothing and raises no dialog, e.source === iframe.contentWindow holds (the guard the parent uses), and the incoming fragment lands at the right offset.
  • Not clicked through inside Taurus itself.

…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.
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.

A link to a neighbouring page does nothing in the HTML preview, and in-document anchors never actually jump

1 participant