Skip to content

Commit 2c97326

Browse files
In domain-task, avoid use of "new Function" because of CSP. Fixes aspnet#345
1 parent 1b4dd93 commit 2c97326

File tree

1 file changed

+2
-2
lines changed
  • src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src

1 file changed

+2
-2
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src/fetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as url from 'url';
22
import * as domain from 'domain';
33
import * as domainContext from 'domain-context';
44
const isomorphicFetch = require('isomorphic-fetch');
5-
const isBrowser: boolean = (new Function('try { return this === window; } catch (e) { return false; }'))();
5+
const isNode = typeof process === 'object' && process.versions && !!process.versions.node;
66

77
// Not using a symbol, because this may need to run in a version of Node.js that doesn't support them
88
const domainTaskStateKey = '__DOMAIN_TASK_INTERNAL_FETCH_BASEURL__DO_NOT_REFERENCE_THIS__';
@@ -17,7 +17,7 @@ function issueRequest(baseUrl: string, req: string | Request, init?: RequestInit
1717
} else {
1818
req = url.resolve(baseUrl, req as string);
1919
}
20-
} else if (!isBrowser) {
20+
} else if (isNode) {
2121
// TODO: Consider only throwing if it's a relative URL, since absolute ones would work fine
2222
throw new Error(`
2323
When running outside the browser (e.g., in Node.js), you must specify a base URL

0 commit comments

Comments
 (0)