Skip to content

Replace CSP 'nonce-<base64>' directive with 'self' directive#43553

Merged
joshdover merged 4 commits intoelastic:masterfrom
joshdover:csp-nonce-to-self
Aug 21, 2019
Merged

Replace CSP 'nonce-<base64>' directive with 'self' directive#43553
joshdover merged 4 commits intoelastic:masterfrom
joshdover:csp-nonce-to-self

Conversation

@joshdover
Copy link
Copy Markdown
Contributor

@joshdover joshdover commented Aug 19, 2019

Summary

Closes #42497

This replaces our usage of the 'nonce-{nonce}' directive with 'self' which will allow us to support dynamic imports more easily.

This change is BWC by adding fixes for any invalid rules in the csp.rules config option:

  • If any CSP rules contain the {nonce} template, that source will be removed and a warning will be logged.
  • If a CSP rule does not contain 'self', it will be added and a warning will be logged.

Dev Docs

Kibana no longer supports the {nonce} notation in the csp.rules configuration. These will be replaced with the 'self' source directive automatically and log a deprecation warning. The {nonce} notation must be removed before upgrading to 8.0.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@joshdover joshdover added Team:Security Platform Security: Auth, Users, Roles, Spaces, Audit Logging, etc t// release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Feature:Security/CSP Platform Security - Content Security Policy labels Aug 19, 2019
@joshdover joshdover requested review from epixa and kobelb August 19, 2019 22:06
@joshdover joshdover requested review from a team as code owners August 19, 2019 22:06
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-security

@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Aug 19, 2019

ACK: reviewing now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone happened to set the following, we'll likely be breaking this install csp.rules: ["default-src 'unsafe-eval' 'nonce-{nonce}'"]. What if instead whenever we removed a nonce source, we added the 'self' source?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work. I think we should still also add it if script-src or style-src don't have self or nonce.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@joshdover joshdover requested a review from kobelb August 20, 2019 22:30
@joshdover joshdover requested a review from mistic August 21, 2019 15:36
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown
Contributor

@mistic mistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the operations side it looks good to me! 👍

@joshdover joshdover merged commit 5071c74 into elastic:master Aug 21, 2019
@joshdover joshdover deleted the csp-nonce-to-self branch August 21, 2019 19:11
joshdover added a commit to joshdover/kibana that referenced this pull request Aug 21, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

<!DOCTYPE html>
<title>Kibana OpenID Connect Login</title>
<script nonce="${nonce}">
<script>
Copy link
Copy Markdown
Contributor

@azasypkin azasypkin Aug 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: hmmm @joshdover @kobelb aren't we effectively disabling execution of this script here assuming our default CSP rule is script-src 'unsafe-eval' 'self'; now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue to discuss: #44668

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

Labels

Feature:Security/CSP Platform Security - Content Security Policy release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Security Platform Security: Auth, Users, Roles, Spaces, Audit Logging, etc t// v7.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DISCUSS] Use script-src 'self' instead of script-src 'nonce-<base64-value>'

5 participants