Not sure what to add. It seems there is no public documentation on embedding Nextcloud on other websites. It’s a gerneral challenge and not particluar to my setup, I think.
I run nextcloud v32 with nginx on my server.
I discovered, I can embed Nextcloud on a different subdomain (with same domain), when I add the subdomain to $allowedFrameAncestors in the ContentSecurityPolicy.php config (Although this might not be the way to do it properly).
Rephrasing my question:
How to configure nextclouds content security policy so that it allows me to use nextcloud in the context of another app?
Documentation in ContentSecurityPolicy.php:
/\*\* @var array Domains which can embed this Nextcloud instance \*/
protected $allowedFrameAncestors = null;
So why can’t I just add arbitrary domains to allow embedding?
Ther also seems to be a StrictContentSecurityPolicy.php file. But since changes in the other file take effect, I would assume it’s not relevant.
In the config.sample.php I find following:
* Your list of trusted domains that users can log into. Specifying trusted
* domains prevents host header poisoning. Do not remove this, as it performs
* necessary security checks.
* You can specify:
*
* - The exact hostname of your host or virtual host, e.g., demo.example.org.
* - The exact hostname with permitted port, e.g., demo.example.org:443.
* This disallows all other ports on this host
* - Use * as a wildcard, e.g., ubos-raspberry-pi*.local will allow
* ubos-raspberry-pi.local and ubos-raspberry-pi-2.local
* - The IP address with or without permitted port, e.g., [2001:db8::1]:8080
* Using TLS certificates where commonName=<IP address> is deprecated
*/
'trusted_domains' => [
'demo.example.org',
'otherdomain.example.org',
'10.111.112.113',
'[2001:db8::1]'
],
That also looks relevant for login.
I also tried to update the nginx config: /etc/nginx/sites-available/nextcloud.conf
# === WOPI Allow ===
location ^~ /index.php/apps/richdocuments/wopi/ {
add_header Access-Control-Allow-Origin "https://myFirstDomain.com https://myOtherDomain.com" always;
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, PUT, DELETE" always;
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Depth, User-Agent, X-Requested-With, X-File-Name, Cache-Control" always;
add_header X-Frame-Options "ALLOW-FROM https://myFirstDomain.com ALLOW-FROM https://myOtherDomain.com" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer" always;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
But this does not seem to have any effect.