livebook
livebook copied to clipboard
Unable to create markdown link with custom URI handlers
Environment
- Elixir & Erlang/OTP versions (elixir --version): Elixir 1.13.2 / Erlang/OTP 24
- Operating system: x86_64-pc-linux-gnu
- How have you started Livebook (mix phx.server, livebook CLI, Docker, etc): docker-compose build
- Livebook version (use git rev-parse HEAD if running with mix): https://github.com/livebook-dev/livebook/commit/fcf3015c87a5060751b998688ed54578a9192f7b
- Browsers that reproduce this bug (the more the merrier): Safari
- Include what is logged in the browser console: n/a
- Include what is logged to the server console: n/a
Current behavior
- Create a markdown cell
- Enter in a link that uses a custom URI, eg:
This is a custom [link](myurihandler://some/path).
- Close markdown editor
- Click on link, note that an error is displayed:
Got unrecognised session path: myurihandler:/some/path
If you want to link another notebook, make sure to include the .livemd extension
Expected behavior
For markdown links that follow a URI format, I would expect the browser to handle the link (thereby invoking the system URI handler).
There is a bug that turns this into a relative URL (fixed in #1255). However, with that fixed, the href
is removed altogether by HTML sanitization given myurihandler://some/path
. I don't think we want to allow arbitrary schemes, in particular javascript:
. Are you looking for a well-known scheme, or a custom one?
We have a few custom schemes that are used to launch native applications.
I see, there's no specific list of dangerous schemes that we could disallow (ref). What we can do is have a configuration under settings for enabling specific schemes other than http/https in the given Livebook instance.
So the idea is to have a Livebook configuration under settings with special protocols allowed in the Livebook instance.
I can take a stab at this next week unless someone beats me to it! 😀
Thanks for the guidance
@josevalim Is this issue still available?
Yes! :)
Great. Let me pick it up. Also please help review this PR https://github.com/livebook-dev/livebook/pull/1389
@josevalim @jonatanklosko currently, I have implemented adding and storing the protocols on the live book settings to efs. Could you guide me on functions I should look out for that actually check for these protocols?
Also, I tried implementing isProtocol function using this regex https://regex101.com/r/mGI6IB/1 rehypeExternalLinks doesn't highlight it. Thank you.
@hameedhub we don't actually need to parse the URLs, we can just pass the configured protocol names as allowed ones, in addition to the defaults. The sanitization rules are here:
https://github.com/livebook-dev/livebook/blob/c8dd1151f08d6a5ae85c909528860130f8539deb/assets/js/lib/markdown.js#L101-L111
and I think we can do something like this:
protocols: {
...defaultSchema.protocols,
href: [...defaultSchema.protocols.href, ...extraProtocols],
},
Closed in #1702.