Use setprototypeof module to replace __proto__ setting
Before adoption: this commit came in with the history the project adopted, so no landing records it.
closes #1967 closes #2613 closes #3103 closes #3164
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 12ff56e · Browse files · 5 files·+20 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+20 added−9 removed
- other:+20 added−9 removed
Provenance
- Commit
6022567- Tree
ab98f32- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
12ff56e
5 files changed+20 added−9 removed
modified:lib/middleware/init.js+9 added-2 removed
7 unmodified lines89101112131415161718192021228 unmodified lines3132333428293536373839403 unmodified lines7 unmodified lines
'use strict';
/** * Module dependencies. * @private */
var setPrototyeOf = require('setprototypeof')
/** * Initialization middleware, exposing the * request and response to each other, as well * as defaulting the X-Powered-By header field. *8 unmodified lines req.res = res; res.req = req; req.next = next;
req.__proto__ = app.request; res.__proto__ = app.response; setPrototyeOf(req, app.request) setPrototyeOf(res, app.response)
res.locals = res.locals || Object.create(null);
next();3 unmodified linesmodified:lib/router/index.js+2 added-1 removed
19 unmodified lines20 var debug = require('debug')('express:router');21 var deprecate = require('depd')('express');22 var flatten = require('array-flatten');23 var parseUrl = require('parseurl');24+var setPrototypeOf = require('setprototypeof')25 26 /**27 * Module variables.28 * @private18 unmodified lines47 router.handle(req, res, next);48 }49 50 // mixin Router class functions50- router.__proto__ = proto;51+ setPrototypeOf(router, proto)52 53 router.params = {};54 router._params = [];55 router.caseSensitive = opts.caseSensitive;600 unmodified linesmodified:lib/application.js+7 added-6 removed
26 unmodified lines27 var deprecate = require('depd')('express');28 var flatten = require('array-flatten');29 var merge = require('utils-merge');30 var resolve = require('path').resolve;31+var setPrototyeOf = require('setprototypeof')32 var slice = Array.prototype.slice;33 34 /**35 * Application prototype.58 unmodified lines94 delete this.settings['trust proxy fn'];95 }96 97 // inherit protos97- this.request.__proto__ = parent.request;98- this.response.__proto__ = parent.response;99- this.engines.__proto__ = parent.engines;100- this.settings.__proto__ = parent.settings;98+ setPrototyeOf(this.request, parent.request)99+ setPrototyeOf(this.response, parent.response)100+ setPrototyeOf(this.engines, parent.engines)101+ setPrototyeOf(this.settings, parent.settings)102 });103 104 // setup locals105 this.locals = Object.create(null);121 unmodified lines227 // restore .app property on req and res228 router.use(path, function mounted_app(req, res, next) {229 var orig = req.app;230 fn.handle(req, res, function (err) {230- req.__proto__ = orig.request;231- res.__proto__ = orig.response;231+ setPrototyeOf(req, orig.request)232+ setPrototyeOf(res, orig.response)233 next(err);234 });235 });236 408 unmodified linesmodified:History.md+1 added
4 unmodified lines5 * Remove usage of `res._headers` private field6 - Improves compatibility with Node.js 8 nightly7 * Skip routing when `req.url` is not set8 * Use `Object.create` to setup request & response prototypes9+ * Use `setprototypeof` module to replace `__proto__` setting10 * Use `statuses` instead of `http` module for status messages11 * deps: debug@2.6.112 - Allow colors in workers13 - Deprecated `DEBUG_FD` environment variable set to `3` or higher3192 unmodified linesmodified:package.json+1 added
48 unmodified lines49505152535455565738 unmodified lines48 unmodified lines "qs": "6.3.1", "range-parser": "~1.2.0", "send": "0.14.2", "serve-static": "~1.11.2", "setprototypeof": "1.0.3", "statuses": "~1.3.1", "type-is": "~1.6.14", "utils-merge": "1.0.0", "vary": "~1.1.0"38 unmodified lines