Allow allowedOrigin to be configured on container startup (#6894)
* This allows allowedOrigin to be configured on container startup * Allow for all forms of allowedOrigin values * Update readme.md
Edwin Hermans committed
Mar 18, 2025 at 20:00 UTC
7a33270e9a1cc2996b7af49f1cfbfcf43bc342ca
4 files changed
+11
-1
docker/Dockerfile
+1
@@ -70,6 +70,7 @@ ENV SESSION_KEY=""
70
ENV REVERSE_PROXY="false"
71
ENV REVERSE_PROXY_TLS_PORT=""
72
ENV ARGS=""
73
+ENV ALLOWED_ORIGIN="false"
74
75
RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
76
&& [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
docker/config.json.template
+2
-1
@@ -25,7 +25,8 @@
25
"NewAccounts": true,
26
"localSessionRecording": true,
27
"_userNameIsEmail": true,
28
- "_certUrl": "my.reverse.proxy"
28
+ "_certUrl": "my.reverse.proxy",
29
+ "allowedOrigin": false
30
}
31
},
32
"_letsencrypt": {
docker/readme.md
+3
@@ -47,6 +47,9 @@ LOCALSESSIONRECORDING=false
47
MINIFY=true
48
# set this value to add extra arguments to meshcentral on startup (e.g --debug ldap)
49
ARGS=
50
+# set to the hostname(s) meshcentral will be reachable on, or true to disable origin checking
51
+# forms allowed "hostname" or "hostname1,hostname2" or ["hostname1","hostname2"]
52
+ALLOWED_ORIGIN=false
53
```
54
55
## docker-compose.yml
docker/startup.sh
+5
@@ -21,6 +21,11 @@ else
21
sed -i "s/\"minify\": false/\"minify\": $MINIFY/" meshcentral-data/"${CONFIG_FILE}"
22
sed -i "s/\"WebRTC\": false/\"WebRTC\": $WEBRTC/" meshcentral-data/"${CONFIG_FILE}"
23
sed -i "s/\"AllowFraming\": false/\"AllowFraming\": $IFRAME/" meshcentral-data/"${CONFIG_FILE}"
24
+ if [[ "$ALLOWED_ORIGIN" =~ ^\[.*\]|^true|^false ]]; then
25
+ sed -i "s/\"allowedOrigin\": false/\"allowedOrigin\": $ALLOWED_ORIGIN/" meshcentral-data/"${CONFIG_FILE}"
26
+ else
27
+ sed -i "s/\"allowedOrigin\": false/\"allowedOrigin\": \"$ALLOWED_ORIGIN\"/" meshcentral-data/"${CONFIG_FILE}"
28
+ fi
29
if [ -z "$SESSION_KEY" ]; then
30
SESSION_KEY="$(cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 48 | head -n 1)"
31
fi