Skip to content
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

Allow data urls #2833

Merged
merged 5 commits into from Apr 22, 2024
Merged

Allow data urls #2833

merged 5 commits into from Apr 22, 2024

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Apr 16, 2024

  • Allows data urls protocol in links.
  • Add window.dash_clientside.clean_url function to sanitize url, used between html and dcc.
    • Disable the sanitation by overriding clean_url in an asset file: window.dash_clientside.clean_url = (url) => url;

Fixes #2764

if (url === '') {
return url;
}
const cleaned = url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include the decodeHtmlCharacters step as in braintree/sanitize-url?

[
html.Img(
id="image",
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAACBCAMAAAAYG1bYAAABC1BMVEX///8oLTMXHiUgJi0AAA4UGyMFERsjKC5MUFQAABFfYmUMFR74+PmbnZ/ExcbU1dWpqqva29wsMTeuoMn3N3ato8v5NHSpqM/yPnyxnMYbISgACxeJ1vTx8vLVaJ3SbaDOcqWH2Pb8MHDwQX6Oz+6E3vrm5+eChIaQkpUAAABCRkvHyMmxkL5ucXQ7P0Sur7G5urz8AGDYX5fS1+lnam1VWFzm4O17fYD10t/55+70krH0X47vf6XqyNrXj7bYg63gudHKwty3r9HQ6Pei1/L2tMjKcaXYz+Pk9PvZeKaWzOzWpcXS5vWp5vv/AGDu6vP0obv3usztZJTNwdvjscvBrM721+LqSISor9QSCNdVAAAJ+klEQVR4nO2ca0PbOBaGYzuyE2SHJNAB7JqytE0MNIm7Qwj0NlPa0p3OzjLTmXbn//+StWNJ1s2hLiH2hvN+aSPLjnweXY6OTmg0QCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKB6q2LFy9fvjqXS1+/+enNz65UeP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kQQAAAABJRU5ErkJggg==",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be more readable to commit the image file and then read and base64 encode it inside the test

assert (
element.get_attribute(prop) == "about:blank"
), f"Failed prop: {element_id}.{prop}"
prop_value == "about:blank"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are inlining the sanitization logic to our codebase, probably makes sense to add a few more tests along the lines of these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more tests cases, some of the sanitization in that was done in the lib were not valid as dash prop.

@emilykl
Copy link
Contributor

emilykl commented Apr 16, 2024

LGTM at a high level. The workflow of overriding window.dash_clientside.clean_url to disable the sanitization feels a little weird... couldn't we just add another prop to the affected components to disable sanitization? How many places would we want to allow users to disable?

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Apr 16, 2024

LGTM at a high level. The workflow of overriding window.dash_clientside.clean_url to disable the sanitization feels a little weird... couldn't we just add another prop to the affected components to disable sanitization? How many places would we want to allow users to disable?

I just thought it would be convenient to have it available for multiple components library (dcc & html in this case), if a community library want to use the same clean url pattern for it's url it's now available. Overriding the function to disable it is an afterthought pattern that emerged from that, but I think it does well as a global disable feature that would be something only a user that really want to do that.

@ndrezn
Copy link
Member

ndrezn commented Apr 16, 2024

@emilykl re: prop on component level, see: #2764 (comment). We don't want to allow users to disable sanitization at the component level.

@T4rk1n T4rk1n requested a review from emilykl April 19, 2024 17:38
@emilykl
Copy link
Contributor

emilykl commented Apr 19, 2024

Understood re: why we don't want to disable sanitization at the component level. 👍

Copy link
Contributor

@emilykl emilykl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ndrezn
Copy link
Member

ndrezn commented Apr 19, 2024

One thing I would like to validate before merging. We know this pattern is considered sufficient by Mozilla, but is there any documentation for other browsers (Safari, Chrome) that is in agreement? I started looking but did not find anything. If it exists I imagine it's buried in dev docs somewhere.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Apr 22, 2024

One thing I would like to validate before merging. We know this pattern is considered sufficient by Mozilla, but is there any documentation for other browsers (Safari, Chrome) that is in agreement? I started looking but did not find anything. If it exists I imagine it's buried in dev docs somewhere.

I found this for Safari: https://developer.apple.com/forums/thread/650034?answerId=624675022#624675022
Seems like it was the last one to allow it and no longer does as from 4 years ago.

Copy link
Member

@ndrezn ndrezn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@T4rk1n T4rk1n merged commit 9a4a479 into dev Apr 22, 2024
3 checks passed
@T4rk1n T4rk1n deleted the fix/xss-data-url branch April 22, 2024 15:43
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.

Dangerous link detected error after upgrading to Dash 2.15.0
3 participants