owncloud / ocis

:atom_symbol: ownCloud Infinite Scale Stack
https://doc.owncloud.com/ocis/next/
Apache License 2.0
1.4k stars 183 forks source link

duplicated CSP frame-ancestors policy #10042

Closed wkloucek closed 1 month ago

wkloucek commented 1 month ago

Describe the bug

On the root path of oCIS, we get two content-security-policy headers. One has a static frame-ancestors 'self' config

Steps to reproduce

  1. run oCIS 6.3.0 eg. in Kubernetes using the development-install deployment example
  2. open oCIS, eg https://ocis.kube.owncloud.test/ after opening the network console
  3. Look at the request to https://ocis.kube.owncloud.test/

Expected behavior

Have one header content-security-policy reflecting my oCIS csp configuration.

Actual behavior

image

Further context

The second header seems to be statically set to frame-ancestors 'self' and always there, even if I have a more sophisticated CSP config

wkloucek commented 1 month ago

This additional header probably originates here:

https://github.com/owncloud/ocis/blob/a7a10f8f0c91859b7f3406d39d618ceded9a47e2/services/web/pkg/middleware/silentrefresh.go#L7-L13

wkloucek commented 1 month ago

And what it actually does: it takes precedence over the frame-ancestors policy in the first header...

micbar commented 1 month ago

@kulmann @JammingBen

Escalating it to P2

jvillafanez commented 1 month ago

As far as I know, the CSP is fully handled by the proxy service (through the csp.yaml file), and no other service should try to set the CSP. The easiest solution is to remove that header from the web service and let the proxy service to handle it; we might need to document that the frame-ancestor 'self' (or a more relaxed) policy is required.

Alternatively, we could implement a way for any service to overwrite the CSP in the proxy service. In this case, the web service would require the proxy service to set, at least, the frame-ancestor 'self' policy. However, the solution seems complex and will require proper design. Note that setting the policy might be critical (service might not work properly if the policy isn't set), and we need to deal with communication errors between the services.

micbar commented 1 month ago

The easiest solution is to remove that header from the web service and let the proxy service to handle it;

Yes. That should do it for now.

jvillafanez commented 1 month ago

https://github.com/owncloud/ocis/pull/10146 should fix the double CSP header.

jvillafanez commented 1 month ago

PR merged. Closing.