gradio: Gradio sanitizing links; no longer able to open in new window

Describe the bug

Currently my chat bot returns verified sources with html links as seen below. It uses the target="_blank"> to open these links in a new tab. Gradio past the version that introduced marked now sanitizes this target parameter out of the processed link.

input: f'<a href="{link}" class="source" rel="noopener noreferrer" target="_blank"> {name} | {score:.0%}</a>

output in published site: f'<a href="{link}" class="source" rel="noopener noreferrer"> {name} | {score:.0%}</a>

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

working on it

Screenshot

working on it

Logs

working on it

System Info

gradio>=3.29.1

Severity

blocking upgrade to latest gradio version

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I’ll look into that @6DammK9! Thanks for raising this.

Just commenting, not going to re-open the issue. target="_blank" doesn’t work when the hyperlink has the same domain with the gradio host.

	DOMPurify.addHook("afterSanitizeAttributes", function (node) {
		if ("target" in node) {
			if (is_external_url(node.getAttribute("href"))) {
				node.setAttribute("target", "_blank");
				node.setAttribute("rel", "noopener noreferrer");
			}
		}
	});

Therefore when you’re working on some on-prem solution under a static domain, pay attention to this situation. My case is just using nginx to make the exact same PDF file host available in 2 domains.

This work: xxx.company.com/chatbot > yyy.company.com/filehost.pdf This doesn’t work: This work: xxx.company.com/chatbot > xxx.company.com/filehost.pdf

I created an issue here explaining my situation.

Based on my testing, the last version when this worked was 3.31.0 (i checked checked each version from the latest and worked backwards)

Heads up, that version leveraged marked’s html sanitization; it wasn’t the best and often parsed html as text.

Thanks. I noticed that… pros and cons. Sadly, having the web page change and user losing the entire chat history when clicking on a link is is what I am trying to avoid

Based on my testing, the last version when this worked was 3.31.0 (i checked checked each version from the latest and worked backwards)

Heads up, that version leveraged marked’s html sanitization; it wasn’t the best and often parsed html as text.

We should make sure we add the correct rel attributes as well to prevent security issues:

https://github.com/cure53/DOMPurify/issues/317#issuecomment-698800327

We should also add noreferrer in addition to noopener.

Based on my testing, the last version when this worked was 3.31.0 (i checked checked each version from the latest and worked backwards)

I’ve been able to repro this in a test space here with 3.35.2. Might be a side effect of #3667. Looking into fixing this!