Selaa lähdekoodia

Securised CORS

Brendan Abolivier 8 vuotta sitten
vanhempi
commit
77b12b5cfc
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
2 muutettua tiedostoa jossa 5 lisäystä ja 5 poistoa
  1. 2
    3
      server.js
  2. 3
    2
      settings.example.json

+ 2
- 3
server.js Näytä tiedosto

@@ -31,10 +31,9 @@ app.use(bodyParser.urlencoded({ extended: true }));
31 31
 app.use(bodyParser.json());
32 32
 
33 33
 
34
-// Allow cross-origin requests. Wildcard for now, we'll see if we can improve
35
-// that.
34
+// Allow cross-origin requests.
36 35
 app.all('/*', function(req, res, next) {
37
-    res.header('Access-Control-Allow-Origin', '*');
36
+    res.header('Access-Control-Allow-Origin', settings.formUrl);
38 37
     res.header('Access-Control-Allow-Headers', 'Content-Type')
39 38
     next();
40 39
 });

+ 3
- 2
settings.example.json Näytä tiedosto

@@ -5,12 +5,13 @@
5 5
         "port": 465,
6 6
         "secure": true,
7 7
         "auth": {
8
-            "user": "noreply@noreply.tld",
8
+            "user": "noreply@example.tld",
9 9
             "pass": "hackme"
10 10
         }
11 11
     },
12 12
     "recipients": [
13 13
         "you@example.tld",
14 14
         "someone.else@example.com"
15
-    ]
15
+    ],
16
+    "formUrl": "https://example.tld/contact"
16 17
 }