-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradio sanitizing links; no longer able to open in new window #4536
Comments
Hi @decent-engineer-decent-datascientist can you please provide a way for us to reproduce this issue? Can you also confirm that this is an issue on the latest version of Gradio? |
@hannahblair thank you for helping out, completely snowed under with work. |
Ah cool! is there any way within gradio to add those hooks to my app? Thank you for debugging this @hannahblair |
Hey friend, just checking to see if there was a preferred pattern to add those dompurify hooks to Gradio's JS. |
@decent-engineer-decent-datascientist Gradio doesn't expose those hooks (and it feels too low-level for us to expose) so no workaround at the moment short of modifying the Gradio code directly. I think we should just write the hook in Gradio to ensure that |
I encountered the same issue and was able to reproduce it using the code below quite easily. While we wait for a fix, does anyone know the last version of gradio where this worked correctly? Version where links in the chatbot had the target="_blank" correctly inserted / preserved and subsequently opened in a new tab
Resulting HTML (via inspect element)
|
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) |
We should make sure we add the correct cure53/DOMPurify#317 (comment) We should also add |
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 |
Is this fixed now? I'm outputting an a tag with target="_blank" and it gets automatically removed for some reason. I understand it is because the documents being referenced by the links point to files that are part of the same URL where the application is running. Is this the case? How do I solve it?. |
Depending on the specific issue it should be fixed. If you are using the latest version of gradio and are still having issues, please open a new issue with a minimal reproduction so we can look into it. |
I created an issue here explaining my situation. |
Just commenting, not going to re-open the issue. 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. This work: |
I'll look into that @6DammK9! Thanks for raising this. |
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 introducedmarked
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?
Reproduction
working on it
Screenshot
working on it
Logs
System Info
gradio>=3.29.1
Severity
blocking upgrade to latest gradio version
The text was updated successfully, but these errors were encountered: