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

CSP error in Dashboard #2511

Closed
humphd opened this issue Nov 22, 2021 · 6 comments · Fixed by #2845
Closed

CSP error in Dashboard #2511

humphd opened this issue Nov 22, 2021 · 6 comments · Fixed by #2845
Assignees
Labels
area: dashboard Related to Telescope's dashboard (the page that has stats) type: bug Something isn't working
Milestone

Comments

@humphd
Copy link
Contributor

humphd commented Nov 22, 2021

See https://dev.api.telescope.cdot.systems/v1/status/pages/build.html and open dev tools to see console:

Screen Shot 2021-11-22 at 1 53 16 PM

@humphd humphd added type: bug Something isn't working area: dashboard Related to Telescope's dashboard (the page that has stats) labels Nov 22, 2021
@Qiwen-Yu
Copy link
Contributor

@humphd Can I take this one?

@Qiwen-Yu
Copy link
Contributor

@humphd Sorry for the late response, but this link does not work now https://dev.api.telescope.cdot.systems/v1/status/pages/build.html

@humphd
Copy link
Contributor Author

humphd commented Dec 16, 2021

Things change when you wait 3 weeks, https://dev.api.telescope.cdot.systems/v1/status/build

@humphd humphd changed the title referenceButtons is null in build-log dashboard CSP error in Dashboard with inline (“script-src”) Jan 13, 2022
@humphd
Copy link
Contributor Author

humphd commented Jan 13, 2022

Since the other issue is gone, I'm morphing this to deal with this issue instead:

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).

@humphd humphd changed the title CSP error in Dashboard with inline (“script-src”) CSP error in Dashboard Feb 4, 2022
@humphd
Copy link
Contributor Author

humphd commented Feb 4, 2022

api.telescope.cdot.systems/:1 Refused to connect to 'http://api.telescope.cdot.systems/v1/status/status/' because it violates the following Content Security Policy directive: "connect-src 'self' *.fontawesome.com https://telescope.cdot.systems *.github.com".

I can't get the status checks for our API servers to work in the dashboards due to this.

@JerryHue
Copy link
Contributor

JerryHue commented Feb 6, 2022

So, I think these two issues are actually not related, amusingly enough.

The first issue is:

Since the other issue is gone, I'm morphing this to deal with this issue instead:

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).

There are two important clues:

  • The word inline. This might refer to several things, such as "style attribute, onclick, or script tag bodies (depends on the context of the source it is applied to) and javascript: URIs". I quoted directly from the CSP website.
  • The warning happens 11 times.

If we pay attention to the status.hbs file, and search for onclick, we will find it appears 11 times!

The way to solve the issue, then, is to delete the part that has those onclicks. I noticed that this part belongs to a "theme color option" bar that we are not using at all (it doesn't work because of the violation policy). I find this solution better than trying to figure out a proper set of CSP rules so that these click handlers work.

The other issue is:

api.telescope.cdot.systems/:1 Refused to connect to 'http://api.telescope.cdot.systems/v1/status/status/' because it violates the following Content Security Policy directive: "connect-src 'self' *.fontawesome.com https://telescope.cdot.systems *.github.com".

I can't get the status checks for our API servers to work in the dashboards due to this.

To catch this one, we need to head over the Network tab in the Developer tools. If you head over to https://api.telescope.cdot.systems/v1/status, you will notice that the first request has a 301 for its response, and the response gives the new location as http://api.telescope.cdot.systems/v1/status/. This is traefik doing its magic.

Well, if you head over the docker-compose.yml and figure out the middleware for traefik, you will see that we are using the regex (^.*\/status$). This regex also matches with the URL https://api.telescope.cdot.systems/v1/status/status, and we can see in the network activity that for the request made by fetch to this location it also gets a redirect to location http://api.telescope.cdot.systems/v1/status/status.

The reason the policy is violated is clear when we read this. The rule is violated because we are requesting to http://api.telescope.cdot.systems/v1/status/status, which doesn't match with any value in connect-src rule. Indeed, it doesn't even match 'self' because of the http change. So, to avoid this redirection, we can tighten the regex to be (^.*\/[^status]+\/status$$).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dashboard Related to Telescope's dashboard (the page that has stats) type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants