Skip to content

Commit 64385e0

Browse files
authored
Add frame-src CSP override option for custom origins (#994)
* Add frame-src content policy override option for custom origin Signed-off-by: Milton Moura <[email protected]> * Add changeset Signed-off-by: Milton Moura <[email protected]> * add mention of on the README.md Signed-off-by: Milton Moura <[email protected]> --------- Signed-off-by: Milton Moura <[email protected]>
1 parent 703dcce commit 64385e0

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

.changeset/chilly-lemons-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@matrix-widget-toolkit/widget-server': minor
3+
---
4+
5+
Add CSP_FRAME_SRC support to enable custom frame-src origins

containers/widget-server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ COPY files/provide_environment.sh /
3838
VOLUME /var/cache/nginx /tmp
3939

4040
ENTRYPOINT [ "/provide_environment.sh" ]
41-
CMD [ "nginx", "-g", "daemon off; load_module \"modules/ngx_http_perl_module.so\"; env __ENVIRONMENT_SCRIPT__; env __CSP_FONT_SRC__; env __CSP_STYLE_SRC__; env __CSP_SCRIPT_SRC__; env __CSP_IMG_SRC__; env __CSP_CONNECT_SRC__;" ]
41+
CMD [ "nginx", "-g", "daemon off; load_module \"modules/ngx_http_perl_module.so\"; env __ENVIRONMENT_SCRIPT__; env __CSP_FRAME_SRC__; env __CSP_FONT_SRC__; env __CSP_STYLE_SRC__; env __CSP_SCRIPT_SRC__; env __CSP_IMG_SRC__; env __CSP_CONNECT_SRC__;" ]

containers/widget-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Simply replace the `/etc/nginx/conf.d/custom/content-security-policy.conf` file
108108
Note that the `$__STYLE_CSP_NONCE__` will be used to add the unique nonce to each request.
109109

110110
It is also possible to extend the existing CSP with additional values:
111-
The values of the `CSP_FONT_SRC`, `CSP_STYLE_SRC`, `CSP_SCRIPT_SRC`, `CSP_IMG_SRC`, `CSP_CONNECT_SRC` environment variables will be appended to the respecting policy.
111+
The values of the `CSP_FRAME_SRC`, `CSP_FONT_SRC`, `CSP_STYLE_SRC`, `CSP_SCRIPT_SRC`, `CSP_IMG_SRC`, `CSP_CONNECT_SRC` environment variables will be appended to the respecting policy.
112112
Environment variable references can be added as string, e.g. `export CSP_IMG_SRC='${REACT_APP_HOME_SERVER_URL}'`.
113113
Note that it is not possible to remove existing entries without replacing the `content-security-policy.conf` file.
114114

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_header Content-Security-Policy "default-src 'none'; font-src 'self' data: $__CSP_FONT_SRC__; style-src 'self' $__STYLE_CSP_NONCE__ $__CSP_STYLE_SRC__; script-src 'self' $__STYLE_CSP_NONCE__ $__CSP_SCRIPT_SRC__; img-src 'self' data: $__CSP_IMG_SRC__; connect-src 'self' $__CSP_CONNECT_SRC__; manifest-src 'self';";
1+
add_header Content-Security-Policy "default-src 'none'; frame-src 'self' $__CSP_FRAME_SRC__; font-src 'self' data: $__CSP_FONT_SRC__; style-src 'self' $__STYLE_CSP_NONCE__ $__CSP_STYLE_SRC__; script-src 'self' $__STYLE_CSP_NONCE__ $__CSP_SCRIPT_SRC__; img-src 'self' data: $__CSP_IMG_SRC__; connect-src 'self' $__CSP_CONNECT_SRC__; manifest-src 'self';";

containers/widget-server/files/default.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ server_tokens off;
99
perl_set $__ENVIRONMENT_SCRIPT__ 'sub { return $ENV{"__ENVIRONMENT_SCRIPT__"}; }';
1010

1111
# provide additional variables that can be used in the CSP
12+
perl_set $__CSP_FRAME_SRC__ 'sub {return $ENV{"__CSP_FRAME_SRC__"}; }';
1213
perl_set $__CSP_FONT_SRC__ 'sub {return $ENV{"__CSP_FONT_SRC__"}; }';
1314
perl_set $__CSP_STYLE_SRC__ 'sub {return $ENV{"__CSP_STYLE_SRC__"}; }';
1415
perl_set $__CSP_SCRIPT_SRC__ 'sub {return $ENV{"__CSP_SCRIPT_SRC__"}; }';
@@ -48,8 +49,8 @@ server {
4849
# they have a hash in the filename.
4950
location /static {
5051
add_header Cache-Control "public, max-age=31556926, immutable";
51-
}
52-
52+
}
53+
5354
location /assets {
5455
add_header Cache-Control "public, max-age=31556926, immutable";
5556
}

containers/widget-server/files/provide_environment.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
# Create a new entrypoint that exports a __ENVIRONMENT_SCRIPT__ variable
4-
# from all REACT_APP_* environment variables. The variable contains a
4+
# from all REACT_APP_* environment variables. The variable contains a
55
# variable assignment to window.__ENVIRONMENT__ that should be put
66
# into a <script>.
77

@@ -26,6 +26,7 @@ __ENVIRONMENT__=`echo -n "{$JSON_CONTENT}" | base64 -w 0`
2626
export __ENVIRONMENT_SCRIPT__="window.__ENVIRONMENT__ = '${__ENVIRONMENT__}';"
2727

2828
# compile the CSP hooks
29+
export __CSP_FRAME_SRC__=`echo $CSP_FRAME_SRC | envsubst`
2930
export __CSP_FONT_SRC__=`echo $CSP_FONT_SRC | envsubst`
3031
export __CSP_STYLE_SRC__=`echo $CSP_STYLE_SRC | envsubst`
3132
export __CSP_SCRIPT_SRC__=`echo $CSP_SCRIPT_SRC | envsubst`

0 commit comments

Comments
 (0)