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

Metadata page requires style-src hash in CSP #1332

Open
Tracked by #1776
baszoetekouw opened this issue Oct 21, 2024 · 7 comments
Open
Tracked by #1776

Metadata page requires style-src hash in CSP #1332

baszoetekouw opened this issue Oct 21, 2024 · 7 comments
Assignees

Comments

@baszoetekouw
Copy link
Member

baszoetekouw commented Oct 21, 2024

For some reason, the metadata page of engineblock won't display properly in Edge/Chrome without a CSP style-src hash. Investigate why this hapens.

@baszoetekouw baszoetekouw changed the title Metadata page should not use embedded CSS Metadata page requires style-src hash in CSP Oct 21, 2024
@baszoetekouw
Copy link
Member Author

Note: currently no CSP header is set on engine.

@johanib
Copy link
Contributor

johanib commented Jan 29, 2025

Discussed: On prod, no CSP header is set. We see no reason why this is not set stricter. But when the style-src is restricted, the metadata page does not show properly.

So investigate why, and restrict the style-src CSP.

@baszoetekouw
Copy link
Member Author

This the (stricter) CSP that we would like to use, if feasible:

content-security-policy: default-src 'none'; script-src 'self'; style-src 'self'; font-src 'self'; connect-src 'self'; img-src 'self' https://static.openconex.org http://localhost:* data:; form-action 'self'; frame-ancestors 'none'; base-uri 'none'

@johanib johanib self-assigned this Feb 4, 2025
@johanib johanib moved this from Backlog to In Progress in PHP development Feb 4, 2025
@johanib johanib assigned baszoetekouw and unassigned johanib Feb 5, 2025
@johanib
Copy link
Contributor

johanib commented Feb 5, 2025

As discussed, could not reproduce. Is it possible to include the errors from the browser console?

@tvdijen
Copy link
Contributor

tvdijen commented Feb 5, 2025

Image

Using: Header set Content-Security-Policy "default-src 'self'; font-src 'self'; style-src 'self'; script-src 'unsafe-inline' 'self'; img-src 'self' https://.myorg.nl: data:; frame-ancestors 'none'; form-action 'self' https:; base-uri 'none';"

Once I add the hashes the errors are gone and the metadata XML is properly styled. We see the same behaviour in Chrome. Firefox is not affected by this at all and will always show a styled metadata XML without console-errors.

@johanib
Copy link
Contributor

johanib commented Feb 6, 2025

Thanks, with that I'm able to reproduce the error. (I still need to change the Content-Type header to application/xml for Chrome to render the xml instead of downloading it.)

But as far as I know, this is not something we can fix serverside, as there is no style information in the XML file.
The styles originates from Chrome when it makes the xml look fancy:

Image

So, server-side, it's impossible to generate a hash.

When we add the hash in the error to the csp, that might fix it, but only until chrome updates the render script.

In a way, it's working as intended since someone whom the server does not trust (Chrome) is injecting styles into the page.

The only reference online I could find is here:
https://stackoverflow.com/questions/77359483/content-security-policy-error-with-unstyled-sitemap-xml-in-chrome-browser

So I think the options are:

  • Relax the style-src csp (for xml endpoints specific, if possible)
  • Render the xml ourselves
  • Change the content type to text, so the browser renders the xml as is

@tvdijen
Copy link
Contributor

tvdijen commented Feb 6, 2025

The Content-type is not something that can be changed.
MUST be application/samlmetadata+xml as per SAML 2.0 metadata specifications paragraph 4.1.1.

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

No branches or pull requests

3 participants