forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-policy-common.js
47 lines (40 loc) · 1.37 KB
/
browser-policy-common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
BrowserPolicy = {};
var inTest = false;
BrowserPolicy._runningTest = function () {
return inTest;
};
BrowserPolicy._setRunningTest = function () {
inTest = true;
};
WebApp.connectHandlers.use(function (req, res, next) {
// Never set headers inside tests because they could break other tests.
if (BrowserPolicy._runningTest())
return next();
var xFrameOptions = BrowserPolicy.framing &&
BrowserPolicy.framing._constructXFrameOptions();
var csp = BrowserPolicy.content &&
BrowserPolicy.content._constructCsp();
if (xFrameOptions) {
res.setHeader("X-Frame-Options", xFrameOptions);
}
if (csp) {
res.setHeader("Content-Security-Policy", csp);
}
next();
});
// We use `rawConnectHandlers` to set X-Content-Type-Options on all
// requests, including static files.
// XXX We should probably use `rawConnectHandlers` for X-Frame-Options
// and Content-Security-Policy too, but let's make sure that doesn't
// break anything first (e.g. the OAuth popup flow won't work well with
// a CSP that disallows inline scripts).
WebApp.rawConnectHandlers.use(function (req, res, next) {
if (BrowserPolicy._runningTest())
return next();
var contentTypeOptions = BrowserPolicy.content &&
BrowserPolicy.content._xContentTypeOptions();
if (contentTypeOptions) {
res.setHeader("X-Content-Type-Options", contentTypeOptions);
}
next();
});