Skip to content

Commit d61b516

Browse files
mcfiredrillkiwiupover
authored andcommitted
Replace
hostWhitelist -> hostAllowList moduleWhitelist -> moduleAllowlist Adding a warning when a developer users `hostWhitelist`
1 parent b6b17af commit d61b516

File tree

68 files changed

+4390
-4341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4390
-4341
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ server.start();
9292

9393
## Using Node/npm Dependencies
9494

95-
### Whitelisting Packages
95+
### Allowlisting Packages
9696

9797
When your app is running in FastBoot, it may need to use Node packages
9898
to replace features that are available only in the browser.
9999

100100
For security reasons, your Ember app running in FastBoot can only access
101-
packages that you have explicitly whitelisted.
101+
packages that you have explicitly listed as allowed.
102102

103103
To allow your app to require a package, add it to the
104104
`fastbootDependencies` array in your app's `package.json`:
@@ -132,14 +132,14 @@ hash.** Built-in modules (`path`, `fs`, etc.) only need to be added to
132132

133133
From your Ember.js app, you can run `FastBoot.require()` to require a
134134
package. This is identical to the CommonJS `require` except it checks
135-
all requests against the whitelist first.
135+
all requests against the allowlist first.
136136

137137
```js
138138
let path = FastBoot.require('path');
139139
let filePath = path.join('tmp', session.getID());
140140
```
141141

142-
If you attempt to require a package that is not in the whitelist,
142+
If you attempt to require a package that is not in the allowlist,
143143
FastBoot will raise an exception.
144144

145145
Note that the `FastBoot` global is **only** available when running in
@@ -273,23 +273,23 @@ module.exports = function(environment) {
273273
},
274274

275275
fastboot: {
276-
hostWhitelist: ['example.com', 'subdomain.example.com', /^localhost:\d+$/]
276+
hostAllowlist: ['example.com', 'subdomain.example.com', /^localhost:\d+$/]
277277
}
278278
};
279279
// ...
280280
};
281281
```
282282

283-
The `hostWhitelist` can be a string or RegExp to match multiple hosts.
283+
The `hostAllowlist` can be a string or RegExp to match multiple hosts.
284284
Care should be taken when using a RegExp, as the host function relies on
285285
the `Host` HTTP header, which can be forged. You could potentially allow
286286
a malicious request if your RegExp is too permissive when using the `host`
287287
when making subsequent requests.
288288

289289
Retrieving `host` will error on 2 conditions:
290290

291-
1. you do not have a `hostWhitelist` defined
292-
2. the `Host` header does not match an entry in your `hostWhitelist`
291+
1. you do not have a `hostAllowlist` defined
292+
2. the `Host` header does not match an entry in your `hostAllowlist`
293293

294294
### Query Parameters
295295

packages/ember-cli-fastboot/fastboot/initializers/ajax.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var nodeAjax = function(options) {
1414
try {
1515
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
1616
} catch (fbError) {
17-
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
17+
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostAllowlist property for in your environment.js. FastBoot Error: ' + fbError.message);
1818
}
1919
}
2020

packages/ember-cli-fastboot/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ module.exports = {
237237

238238
/**
239239
* Need to handroll our own clone algorithm since JSON.stringy changes regex
240-
* to empty objects which breaks hostWhiteList property of fastboot.
240+
* to empty objects which breaks hostAllowList property of fastboot.
241241
*
242242
* @param {Object} config
243243
*/

packages/ember-cli-fastboot/lib/broccoli/fastboot-config.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* eslint-env node */
22
'use strict';
33

4-
const fs = require('fs');
5-
const fmt = require('util').format;
6-
const uniq = require('ember-cli-lodash-subset').uniq;
7-
const merge = require('ember-cli-lodash-subset').merge;
8-
const md5Hex = require('md5-hex');
9-
const path = require('path');
10-
const Plugin = require('broccoli-plugin');
11-
4+
const fs = require('fs');
5+
const fmt = require('util').format;
6+
const uniq = require('ember-cli-lodash-subset').uniq;
7+
const merge = require('ember-cli-lodash-subset').merge;
8+
const md5Hex = require('md5-hex');
9+
const path = require('path');
10+
const Plugin = require('broccoli-plugin');
1211
const stringify = require('json-stable-stringify');
1312

1413
const LATEST_SCHEMA_VERSION = 3;
@@ -50,7 +49,7 @@ module.exports = class FastBootConfig extends Plugin {
5049
this.buildConfig();
5150
this.buildDependencies();
5251
this.buildManifest();
53-
this.buildHostWhitelist();
52+
this.buildHostAllowList();
5453

5554
let outputPath = path.join(this.outputPath, 'package.json');
5655
this.writeFileIfContentChanged(outputPath, this.toJSONString());
@@ -85,7 +84,7 @@ module.exports = class FastBootConfig extends Plugin {
8584

8685
buildDependencies() {
8786
let dependencies = {};
88-
let moduleWhitelist = [];
87+
let moduleAllowlist = [];
8988
let ui = this.ui;
9089

9190
eachAddonPackage(this.project, pkg => {
@@ -101,7 +100,7 @@ module.exports = class FastBootConfig extends Plugin {
101100
return;
102101
}
103102

104-
moduleWhitelist.push(dep);
103+
moduleAllowlist.push(dep);
105104

106105
if (version) {
107106
dependencies[dep] = version;
@@ -115,7 +114,7 @@ module.exports = class FastBootConfig extends Plugin {
115114

116115
if (projectDeps) {
117116
projectDeps.forEach(dep => {
118-
moduleWhitelist.push(dep);
117+
moduleAllowlist.push(dep);
119118

120119
let version = pkg.dependencies && pkg.dependencies[dep];
121120
if (version) {
@@ -125,7 +124,7 @@ module.exports = class FastBootConfig extends Plugin {
125124
}
126125

127126
this.dependencies = dependencies;
128-
this.moduleWhitelist = uniq(moduleWhitelist);
127+
this.moduleAllowlist = uniq(moduleAllowlist);
129128
}
130129

131130
updateFastBootManifest(manifest) {
@@ -160,32 +159,35 @@ module.exports = class FastBootConfig extends Plugin {
160159
this.manifest = this.updateFastBootManifest(manifest);
161160
}
162161

163-
buildHostWhitelist() {
162+
buildHostAllowList() {
164163
if (this.fastbootAppConfig) {
165-
this.hostWhitelist = this.fastbootAppConfig.hostWhitelist;
164+
if ('hostWhitelist' in this.fastbootAppConfig) {
165+
this.ui.writeLine('Please update your fastboot config to use `hostAllowList` of the deprecated `hostWhitelist`');
166+
}
167+
this.hostAllowList = this.fastbootAppConfig.hostAllowList || this.fastbootAppConfig.hostWhitelist
166168
}
167169
}
168170

169171
toJSONString() {
170172
return stringify({
171173
dependencies: this.dependencies,
172174
fastboot: {
173-
moduleWhitelist: this.moduleWhitelist,
175+
moduleAllowlist: this.moduleAllowlist,
174176
schemaVersion: LATEST_SCHEMA_VERSION,
175177
manifest: this.manifest,
176-
hostWhitelist: this.normalizeHostWhitelist(),
178+
hostAllowList: this.normalizeHostAllowList(),
177179
config: this.fastbootConfig,
178180
appName: this.appName,
179181
}
180182
}, null, 2);
181183
}
182184

183-
normalizeHostWhitelist() {
184-
if (!this.hostWhitelist) {
185+
normalizeHostAllowList() {
186+
if (!this.hostAllowList) {
185187
return;
186188
}
187189

188-
return this.hostWhitelist.map(function(entry) {
190+
return this.hostAllowList.map(function(entry) {
189191
// Is a regex
190192
if (entry.source) {
191193
return '/' + entry.source + '/';

packages/ember-cli-fastboot/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"body-parser": "^1.18.3",
4747
"broccoli-asset-rev": "^3.0.0",
4848
"broccoli-test-helper": "^1.5.0",
49-
"co": "4.6.0",
5049
"chai": "^4.1.2",
5150
"chai-fs": "^2.0.0",
5251
"chai-string": "^1.4.0",
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
1+
/* eslint-env node */
12
'use strict';
23

3-
const expect = require('chai').use(require('chai-string')).expect;
4-
const RSVP = require('rsvp');
5-
const request = RSVP.denodeify(require('request'));
6-
7-
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
8-
9-
describe('FastBoot config', function() {
10-
this.timeout(400000);
4+
const expect = require('chai').expect;
5+
const helpers = require('broccoli-test-helper');
6+
const MockUI = require('console-ui/mock')
7+
const createBuilder = helpers.createBuilder;
8+
const createTempDir = helpers.createTempDir;
9+
const FastbootConfig = require('../lib/broccoli/fastboot-config');
10+
11+
12+
describe('FastbootConfig', function() {
13+
let input;
14+
let output;
15+
let subject;
16+
let project;
17+
18+
beforeEach(async function() {
19+
input = await createTempDir();
20+
project = {
21+
addons: [],
22+
pkg: {},
23+
};
24+
subject = new FastbootConfig(input.path(), {
25+
project,
26+
outputPaths: {
27+
app: { js: 'app.js' },
28+
vendor: { js: 'vendor.js' },
29+
},
30+
appConfig: {
31+
modulePrefix: 'app',
32+
},
33+
ui: new MockUI(),
34+
fastbootAppConfig: {
35+
hostWhitelist: ['example.com', 'subdomain.example.com']
36+
}
37+
});
38+
output = createBuilder(subject);
39+
});
1140

12-
let app;
41+
afterEach(async function() {
42+
await input.dispose();
43+
await output.dispose();
44+
});
1345

14-
before(function() {
15-
app = new AddonTestApp();
46+
it('it replace hostWhitelist with hostAllowList and warns user to update the config to hostAllowList', async function() {
47+
input.write({});
1648

17-
return app.create('fastboot-config', { emberVersion: 'latest'})
18-
.then(function() {
19-
return app.startServer({
20-
command: 'serve'
21-
});
22-
});
23-
});
49+
await output.build();
2450

25-
after(function() {
26-
return app.stopServer();
27-
});
51+
expect(
52+
output.read()
53+
).to.deep.equal({
54+
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"hostAllowList":["example.com","subdomain.example.com"],"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleAllowlist":[],"schemaVersion":3}}`
55+
});
2856

29-
it('provides sandbox globals', function() {
30-
return request({
31-
url: 'http://localhost:49741/',
32-
headers: {
33-
'Accept': 'text/html'
34-
}
35-
})
36-
.then(function(response) {
37-
expect(response.statusCode).to.equal(200);
38-
expect(response.headers['content-type']).to.equalIgnoreCase('text/html; charset=utf-8');
39-
expect(response.body).to.contain('<h1>My Global</h1>');
40-
});
57+
expect(output.builder.outputNode.ui.output).to.contain('Please update your fastboot config to use `hostAllowList` of the deprecated `hostWhitelist`');
4158
});
4259
});

packages/ember-cli-fastboot/test/fixtures/fastboot-config/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function(environment) {
1919
},
2020

2121
fastboot: {
22-
hostWhitelist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
22+
hostAllowlist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
2323
}
2424
};
2525

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(environment) {
88
modulePrefix: 'fastboot-location-config',
99
fastboot: {
1010
fastbootHeaders: false,
11-
hostWhitelist: [/localhost:\d+/],
11+
hostAllowlist: [/localhost:\d+/],
1212
redirectCode: 302,
1313
}
1414
};

packages/ember-cli-fastboot/test/fixtures/fastboot-location/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(environment) {
88
modulePrefix: 'fastboot-location',
99
fastboot: {
1010
fastbootHeaders: true,
11-
hostWhitelist: [/localhost:\d+/]
11+
hostAllowlist: [/localhost:\d+/]
1212
}
1313
};
1414

packages/ember-cli-fastboot/test/fixtures/request/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function(environment) {
1919
},
2020

2121
fastboot: {
22-
hostWhitelist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
22+
hostAllowlist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
2323
}
2424
};
2525

packages/ember-cli-fastboot/test/new-package-json-test.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const expect = require('chai').expect;
55
const helpers = require('broccoli-test-helper');
66
const createBuilder = helpers.createBuilder;
77
const createTempDir = helpers.createTempDir;
8-
const co = require('co');
98
const FastbootConfig = require('../lib/broccoli/fastboot-config');
109

1110
describe('FastbootConfig', function() {
@@ -50,8 +49,10 @@ describe('FastbootConfig', function() {
5049

5150
await output.build();
5251

53-
expect(output.read()).to.deep.equal({
54-
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":[],"schemaVersion":3}}`,
52+
expect(
53+
output.read()
54+
).to.deep.equal({
55+
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleAllowlist":[],"schemaVersion":3}}`
5556
});
5657

5758
await output.build();
@@ -72,8 +73,10 @@ describe('FastbootConfig', function() {
7273
'package.json': 'change',
7374
});
7475

75-
expect(output.read()).to.deep.equal({
76-
'package.json': `{"dependencies":{"apple":"*","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`,
76+
expect(
77+
output.read()
78+
).to.deep.equal({
79+
'package.json': `{"dependencies":{"apple":"*","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleAllowlist":["apple","orange"],"schemaVersion":3}}`
7780
});
7881

7982
project.pkg.fastbootDependencies = ['apple', 'orange'];
@@ -88,8 +91,10 @@ describe('FastbootConfig', function() {
8891

8992
await output.build();
9093

91-
expect(output.read()).to.deep.equal({
92-
'package.json': `{"dependencies":{"apple":"^3.0.0","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`,
94+
expect(
95+
output.read()
96+
).to.deep.equal({
97+
'package.json': `{"dependencies":{"apple":"^3.0.0","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleAllowlist":["apple","orange"],"schemaVersion":3}}`
9398
});
9499
});
95100
});

packages/fastboot-app-server/test/fixtures/basic-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {},
33
"fastboot": {
4-
"moduleWhitelist": [],
4+
"moduleAllowlist": [],
55
"manifest": {
66
"appFile": "assets/fastboot-test.js",
77
"htmlFile": "index.html",

packages/fastboot-app-server/test/fixtures/broken-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {},
33
"fastboot": {
4-
"moduleWhitelist": [],
4+
"moduleAllowlist": [],
55
"manifest": {
66
"appFile": "assets/fastboot-test.js",
77
"htmlFile": "index.html",

packages/fastboot-app-server/test/fixtures/global-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {},
33
"fastboot": {
4-
"moduleWhitelist": [],
4+
"moduleAllowlist": [],
55
"manifest": {
66
"appFile": "assets/fastboot-test.js",
77
"htmlFile": "index.html",

0 commit comments

Comments
 (0)