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

SAML2 Login fails with CSP in chrome based browsers #11676

Closed
torstenwerner opened this issue Aug 9, 2022 · 3 comments
Closed

SAML2 Login fails with CSP in chrome based browsers #11676

torstenwerner opened this issue Aug 9, 2022 · 3 comments
Assignees
Labels
in: saml2 An issue in SAML2 modules type: bug A general bug
Milestone

Comments

@torstenwerner
Copy link

I have checked out the branch 5.8.x, started

./gradlew :servlet:spring-boot:java:saml2:login:bootRun

and opened http://localhost:8080/ . It redirects to http://localhost:8080/saml2/authenticate/one but this page fails with this error message

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'sha256-ePniVEkSivX/c7XWBGafqh8tSpiRrKiqYeqbG7N1TOE='". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), 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.

in the javascript console of chromium based browsers. The form submit does not work. The CSP (Content Security Policy) is inlined in the HTML of the page as a <meta> element.

It works in firefox. But that would exclude a majority of users.

If it is possible to turn off the inline CSP I would be happy to use it as a quick workaround.

@torstenwerner
Copy link
Author

The CSP rule unsafe-hashes seems to be missing in chromium based browsers. But the better solution would be to move the javascript into a separate javascript file.

https://content-security-policy.com/unsafe-hashes/

@marcusdacoregio
Copy link
Contributor

Hi @torstenwerner, thank you for the report.

I think this problem is related not only to the sample but to this new feature #11631. I'll transfer this issue to the Spring Security project

@marcusdacoregio marcusdacoregio transferred this issue from spring-projects/spring-security-samples Aug 10, 2022
@marcusdacoregio marcusdacoregio self-assigned this Aug 10, 2022
@marcusdacoregio marcusdacoregio added type: bug A general bug in: saml2 An issue in SAML2 modules labels Aug 10, 2022
@marcusdacoregio marcusdacoregio added this to the 5.8.0-M2 milestone Aug 10, 2022
@marcusdacoregio marcusdacoregio changed the title saml 2 login sample fails with CSP in chrome based browsers SAML2 Login fails with CSP in chrome based browsers Aug 10, 2022
@marcusdacoregio
Copy link
Contributor

marcusdacoregio commented Aug 10, 2022

Instead of adding the unsafe-* to the CSP in order to allow inline HTML event handlers (which is not recommended), we could add:

<script>window.onload = () => document.forms[0].submit();</script>

And then recompute the hash for this javascript and add in the meta-tag.

marcusdacoregio added a commit to marcusdacoregio/spring-security that referenced this issue Aug 10, 2022
To avoid relying on HTML event handlers and adding unsafe-* rules to CSP, the javascript is moved to a <script> tag. This also allows a better browser compatibility

Closes spring-projectsgh-11676
@rwinch rwinch modified the milestones: 5.8.0-M2, 5.8.0-M3 Aug 12, 2022
jzheaux pushed a commit that referenced this issue Aug 16, 2022
To avoid relying on HTML event handlers and adding unsafe-* rules to CSP, the javascript is moved to a <script> tag. This also allows a better browser compatibility

Closes gh-11676
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: saml2 An issue in SAML2 modules type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants