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

Content Security Policy Issues for Tooltip #3014

Open
bj00rn opened this issue Jan 2, 2023 · 3 comments
Open

Content Security Policy Issues for Tooltip #3014

bj00rn opened this issue Jan 2, 2023 · 3 comments

Comments

@bj00rn
Copy link

bj00rn commented Jan 2, 2023

Description

Getting errors when tooltip is shown is unless unsafe-inline CSP directive is allowed.

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-xxx='), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.

(anonymous) @ html.js:7
each @ each.js:5
html @ html.js:20
showTooltip @ billboard.js:8340
a @ billboard.js:16719
(anonymous) @ billboard.js:16751
(anonymous) @ on.js:3

Any way around this? Reluctant to allow inline styles

Steps to check or reproduce

Add meta tag to

<meta http-equiv="Content-Security-Policy" content="style-src 'self'">
@netil
Copy link
Member

netil commented Jan 9, 2023

Hi @bj00rn, thanks for the report.
To fix security policy issue it needs to remove all inlined styles which aren't impossible for now.

As you already now, but you can relax your CSP to allow inlined styles by adding as:

<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'">

@danmangit
Copy link

We are facing the same issue for one of our customers. Relaxing the CSP rules might not be possible, especially in companies with high security standards. Could you please provide a fix?

@Igfig
Copy link

Igfig commented Jun 21, 2024

I've been having the same problem. It looks like there might actually be a potential fix, contrary to what @netil was saying: https://stackoverflow.com/a/29089970/4143163

Basically, instead of setting the background-color on each square with inline styles when you set the tooltip's innerHTML (e.g. <span style='background-color:#FF0000'>), you set it afterwards, using element.style.backgroundColor = "#FF0000".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants