-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix: target blank removed from anchor tag #4933
fix: target blank removed from anchor tag #4933
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #4933 +/- ##
===========================================
- Coverage 80.17% 79.39% -0.79%
===========================================
Files 164 164
Lines 13820 13840 +20
Branches 693 698 +5
===========================================
- Hits 11080 10988 -92
- Misses 2591 2701 +110
- Partials 149 151 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@sidharthv96 I don't understand the checks that are failing and how to resolve those? |
I have not investigated it further, but GA says
perhaps something else is needed to make it happen, we cannot merge it while the error it the build is being reproduced |
It could be that dompurify apis are not accessible when we're using the sanitzation on server end maybe, it's my speculation. |
Yes, is it a maybe. Same guess. In that case we have to find a workaround |
I am not well aware of DOMPurify functions, but |
@nirname So I was digging in on this and I found out that people are facing issues while using dompurify with SSR and the alternative is to use either jsDom or isomorphic-dompurify you may refer to the following thread but it still gave me addhook is not defined |
@REVERB283 Yes, I saw this issue too. And I am at the same point as you are now. Try investigating it further, please. Let's also summon @sidharthv96, perhaps he will give us the right direction. To summarize: GA actions say |
You can try using
|
…/github.com/REVERB283/mermaid into bug/4716_fix_target_blank_getting_sanitized
…bug/4716_fix_target_blank_getting_sanitized
…/github.com/REVERB283/mermaid into bug/4716_fix_target_blank_getting_sanitized
@nirname I managed to resolve the remaining issues, please review it once again. |
@REVERB283 yes, I see. Changes are OK. I do not fully understand why this works. Could you explain it for me? I'd like to clarify it for myself. |
@REVERB283 could you add some tests to ensure that no future requests will brake this feature? |
I too don't have the proper clarity myself but it seems like when I call addHook() in the global scope it doesn't seem to be accessible; could be possible that it gets called before DOMPurify gets imported/defined (which should be highly unlikely). However when I call addHook() inside removeScript() it seems to work without errors. I've come to this conclusion after updating the code and calling the guthub workflow "build-docs" multiple times on my local system using "act". |
I'm very new to unit testing but I can surely try. Can you help me out with the files where I need to write the test cases? Also can you point out some already implemented examples that I can take reference from? Much appreciated. |
@REVERB283 yes, sure. There are 2 types of tests - unit tests, which we mainly use for testing parsers, because they are internal. And e2e (end-to-end) also known as integration tests. What they do is starting client and performing actions on behalf of it (like clicking links in headless chrome, sending requests and fetching responses). In our case they check what the rendered image is, so these are used to test renderers. All the integration tests are inside cypress folder, like this pie rendering test. Tests for parsers are located in a specific diagram folder inside mermaid package, like this pie parser test. Our current current e2e testing tool is Cypress. To reduce amount of checks and ensure that graph layout is stable we often compare 2 images. In our specific case we need to ensure that _target attribute inside SVG is present or absent. Have a look at this example, which in fact should have been implemented with image comparison (my bad). Anyway, this is just an example, good or bad, which you can take as a base. Very likely image comparison won't work for this current fix. Here is another one for flowchart, which is basically identical. May be a little bit more descriptive since |
@nirname I've added few test cases, can you review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'll do! May be we should wait for one more approval, but basically it is ready. Great job.
@sidharthv96 any update? |
@REVERB283 - Just chiming in here to let you know that @sidharthv96 is currently on vacation. |
okay no worries! |
…ting_sanitized fix: target blank removed from anchor tag
@REVERB283, Thank you for the contribution! |
📑 Summary
target=_blank was getting sanitized
Resolves #4716
📏 Design Decisions
I've added a Dompurify hook that will add target="_blank" and rel="noopener noreferrer" back to the elements which will have target property in them. While debugging I found that Dompurify when sanitizing the input string removes target property for security reasons but if we really need that I found this could be an option.