-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[HTTP] Fix CSP config merge behaviour #177728
Conversation
Pinging @elastic/kibana-security (Team:Security) |
Pinging @elastic/kibana-core (Team:Core) |
const config = otherConfigs.reduce<CspConfigType>( | ||
(acc, conf) => deepmerge(acc, conf), | ||
firstConfig | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array values were clobbering each other instead of merging (which is the normal behaviour of lodash merge
).
packages/core/http/core-http-server-internal/src/csp/csp_directives.ts
Outdated
Show resolved
Hide resolved
}; | ||
const directives = CspDirectives.fromConfig(config, additionalConfig1, additionalConfig2); | ||
expect(directives.getCspHeader()).toEqual( | ||
`script-src 'report-sample' 'self' cdn.host.test; worker-src 'report-sample' 'self' blob: cdn.host.test; style-src 'report-sample' 'self' 'unsafe-inline' cdn.host.test; connect-src 'self' *.foo.bar cdn.host.test; font-src 'self' cdn.host.test; frame-src 'self' cdn.host.test; img-src 'self' *.foo.bar cdn.host.test` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this here
Related #177732 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @jloleysens |
Summary
Bug in CSP config merging behaviour
While testing the new
server.cdn.url
configuration I noticed that this causes a regression due to how the CSP configs are merged. Right now ifserver.cdn.url
is configured you cannot setcsp.*
because the CDN's configuration will clobber any values configured there.