Skip to content

Commit 70d5ae7

Browse files
authored
documentation for secrets and cors (#374)
1 parent 2b0279f commit 70d5ae7

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default defineConfig({
7878
link: "/configuration/autostart",
7979
},
8080
{ text: "Raspberry Specific", link: "/configuration/raspberry" },
81+
{ text: "Cors Proxy", link: "/configuration/cors" },
8182
],
8283
},
8384
{

configuration/cors.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Cors Proxy
2+
3+
MagicMirror² contains an internal cors proxy which is useful for some modules.
4+
5+
Since MagicMirror² versions greater `v2.35.0` the cors proxy is disabled by
6+
default due to security reasons.
7+
8+
## What is a cors proxy?
9+
10+
There are some good articles online, e.g.
11+
[What are CORS proxies, and when are they safe?](https://httptoolkit.com/blog/cors-proxies/).
12+
13+
## Why do we need a cors proxy for MagicMirror²?
14+
15+
We ran into cors problems with some modules which make api requests to external
16+
websites from inside the browser.
17+
18+
Examples are
19+
20+
- some news url's when using the default newsfeed module
21+
- 3rd-party modules (e.g. weather api's)
22+
- ...
23+
24+
To get such url's working we can use the internal cors proxy. Instead using the
25+
original url `https://example.com` in the module configuration we use
26+
`/cors?url=https://example.com`. With this the request doesn't go directly from
27+
the browser to the external url but to the MagicMirror² Server which makes the
28+
call to the external url and sends the answer back to the browser.
29+
30+
## Setup cors proxy
31+
32+
You have to enable the cors proxy in `config.js`.
33+
34+
::: warning NOTE
35+
36+
We offer no guarantee that the use of the cors proxy is safe in all setups. We
37+
investigated in security and protecting against misuse, but use at your own
38+
risk.
39+
40+
:::
41+
42+
You can us 2 setup variants.
43+
44+
### Cors allow all
45+
46+
This opens cors to all url's. You should only use this if your MagicMirror² is
47+
not reachable from outside your network:
48+
49+
```js
50+
cors: "allowAll",
51+
```
52+
53+
### Cors allow whitelist
54+
55+
This is the safest variant. You have to list all domains which are allowed to
56+
make cors requests:
57+
58+
```js
59+
cors: "allowWhitelist",
60+
corsDomainWhitelist: ["example.com", "api.mapbox.com"],
61+
```

configuration/secrets.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ including all secrets, and send it somewhere else.
5151

5252
## Using secrets in server-side modules
5353

54-
You have to add a new parameter in `config.js`:
54+
You have to add new parameters in `config.js`:
5555

5656
```js
5757
let config = {
@@ -126,6 +126,8 @@ Example:
126126
let config = {
127127
...
128128
hideConfigSecrets: true,
129+
cors: "allowWhitelist",
130+
corsDomainWhitelist: ["api.mapbox.com"],
129131
...
130132
modules: [
131133
{
@@ -152,3 +154,15 @@ acts as a proxy here:
152154
`mapUrl: "/cors?url=https://api.mapbox.com/styles/v1/${SECRET_MAPBOX_ID}/tiles/{z}/{x}/{y}?access_token=${SECRET_MAPBOX_TOKEN}"`
153155

154156
Behind the scenes the server substitutes the variables before fetching the data.
157+
158+
::: warning NOTE
159+
160+
You must whitelist every domain you use as cors url. Therefore, in the example
161+
above, we need to set
162+
163+
```js
164+
cors: "allowWhitelist",
165+
corsDomainWhitelist: ["api.mapbox.com"],
166+
```
167+
168+
:::

0 commit comments

Comments
 (0)