RGraph is a JavaScript charts library based on
HTML5 SVG and canvas. RGraph is mature (over 17 years
old) and has a wealth of features making it an ideal
choice to use for showing charts on your website.
Get the latest version of RGraph (version 6.20, 1st December 2024) from
the download page. You can read the changelog here. There's also older versions available,
minified files and links to cdnjs.com hosted libraries.
Tooltips fail in 'style-src' when applying Content-Security-Policy
Posted by Alek at 20:46 on Sunday 17th April 2022[link]
Hi Richard,
I apply CSP to the header responses, like "style-src 'self'" and since we do not allow any inline styling I've noticed that script fails the policy on line 794: tooltipObj.innerHTML = args.text;
I use standard tooltips with no style modifications
args.text value is "'MY VALUE GOES HERE FOLLWED BY RGRAPH STYLE
<div id="RGraph_tooltipsPointer" style="background-color:black; color: transparent;position:absolute;bottom:-5px;left:50%;transform:translateX(-50%) rotate(45deg);width:10px;height:10px"></div>'"
Do you have any suggestions
Thank you
Alek
Posted by Richard at 21:08 on Sunday 17th April 2022[link]
You could make an exception for the page that uses RGraph tooltips.
Also, another way might be to turn off tooltip pointers. This would of course mean that you don't get the pointer triangle at the bottom of tooltips but if you can live without them then this may work well also.
To do this set the tooltipsPointer option to false.
Posted by Alek at 04:05 on Monday 18th April 2022[link]
Unfortunately 'unsafe-inline' is not an option, but tooltipsPointer: false works
There could be another solution: use of styles from css file and include it as a class
Thank you!
Posted by Richard at 10:17 on Monday 18th April 2022[link]
Great. I'm now going to change from setting the styles inline and relying on .innerHTML, to set them separately after the DIV has been added to the DOM, like this:
Which works when the style-src CSP option is in use. So try version 6.08 (whenever I get around to releasing it!) and see if that works better for you..
Posted by Alek at 20:25 on Monday 18th April 2022[link]