Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure protocolForUrl works in fastboot@3.1.0 environment #1155

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Sep 2, 2020

fastboot creates a sandboxed VM context that has a URL global set to the result of require('url'), and does not expose a global require method at all (for security reasons).

That means that the changes made to protocolForUrl (which landed Ember 3.22.0-beta.2+) break the usage of fastboot with an error like the following:

/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:58488
    var nodeURL = _nodeModule.module.require('url');
                                     ^

TypeError: Cannot read property 'require' of null
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/@glimmer/runtime.js:288:1
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:54:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at require (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:87:1)
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:76572:1
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:76573:2
    at Script.runInContext (vm.js:127:20)
    at VMSandbox.eval (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/vm-sandbox.js:14:16)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:190:15
    at Array.forEach (<anonymous>)
    at EmberApp.loadAppFiles (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:187:21)
    at EmberApp.retrieveSandboxedApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:235:10)
    at new EmberApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:61:21)
    at FastBoot._buildEmberApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/index.js:114:17)
    at new FastBoot (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/index.js:52:10)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/ember-cli-fastboot/index.js:335:29
    at Layer.handle [as handle_request] (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:317:13)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:275:10)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/ember-cli/lib/tasks/server/middleware/broccoli-watcher/index.js:54:11
    at watcher.then.errorHandler.buildError (/Users/marcoow/Code/ember-simple-auth/node_modules/broccoli-middleware/lib/watcher-middleware.js:35:7)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

This refactors things to leverages the native JS URL global (which is available in all environments that we support except IE11).

Fixes #1140

@rwjblue rwjblue force-pushed the refactor-protocolForUrl branch from ba9cdae to 2a802fb Compare September 2, 2020 22:33
`fastboot` creates a sandboxed VM context that has a `URL` global set to
the result of `require('url')`, and does **not** expose a global
`require` method at all (for security reasons).

That means that the changes made to `protocolForUrl` (which landed Ember
3.22.0-beta.2+) break the usage of `fastboot` with an error like the
following:

```
/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:58488
    var nodeURL = _nodeModule.module.require('url');
                                     ^

TypeError: Cannot read property 'require' of null
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/@glimmer/runtime.js:288:1
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:54:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at internalRequire (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:50:1)
    at require (/var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/loader.js:87:1)
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:76572:1
    at /var/folders/cx/h0pn1kjn4971gtp4_5mrm3940000gn/T/broccoli-70503kLAdbxQD1YdI/out-423-broccoli_merge_trees/assets/vendor.js:76573:2
    at Script.runInContext (vm.js:127:20)
    at VMSandbox.eval (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/vm-sandbox.js:14:16)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:190:15
    at Array.forEach (<anonymous>)
    at EmberApp.loadAppFiles (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:187:21)
    at EmberApp.retrieveSandboxedApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:235:10)
    at new EmberApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/ember-app.js:61:21)
    at FastBoot._buildEmberApp (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/index.js:114:17)
    at new FastBoot (/Users/marcoow/Code/ember-simple-auth/node_modules/fastboot/src/index.js:52:10)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/ember-cli-fastboot/index.js:335:29
    at Layer.handle [as handle_request] (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:317:13)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/marcoow/Code/ember-simple-auth/node_modules/express/lib/router/index.js:275:10)
    at /Users/marcoow/Code/ember-simple-auth/node_modules/ember-cli/lib/tasks/server/middleware/broccoli-watcher/index.js:54:11
    at watcher.then.errorHandler.buildError (/Users/marcoow/Code/ember-simple-auth/node_modules/broccoli-middleware/lib/watcher-middleware.js:35:7)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
```

---

This refactors things to leverages the native JS `URL` global (which is
available in all environments that we support **except** IE11).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in FastBoot: "Cannot read property 'require' of null" Remove require('url') usage
2 participants