Merge tag '3.14.0'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parents ec5b9f5, 916c537 · Browse files · 5 files·+133 added−51 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+133 added−51 removed
- tests:+60 added−31 removed
- other:+73 added−20 removed
Provenance
- Commit
4ea6f21- Tree
d00a2b9- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
ec5b9f5- Parent 2
916c537
5 files changed+133 added−51 removed
modified:lib/response.js+30 added-16 removed
98 unmodified lines99 body = arguments[1];100 }101 }102 103+ // disambiguate res.send(status) and res.send(status, num)104+ if (typeof body === 'number' && arguments.length === 1) {105+ // res.send(status) will set status message as text string106+ this.get('Content-Type') || this.type('txt');107+ this.statusCode = body;108+ body = http.STATUS_CODES[body];109+ }110+111 switch (typeof body) {104- // response status105- case 'number':106- this.get('Content-Type') || this.type('txt');107- this.statusCode = body;108- body = http.STATUS_CODES[body];109- break;112 // string defaulting to html113 case 'string':114 if (!this.get('Content-Type')) this.type('html');115 break;116 case 'boolean':117+ case 'number':118 case 'object':119 if (null == body) {120 body = '';121 } else if (Buffer.isBuffer(body)) {124 unmodified lines246 // settings247 var app = this.app;248 var replacer = app.get('json replacer');249 var spaces = app.get('json spaces');247- var body = JSON.stringify(obj, replacer, spaces)248- .replace(/\u2028/g, '\\u2028')249- .replace(/\u2029/g, '\\u2029');250+ var body = JSON.stringify(obj, replacer, spaces);251 var callback = this.req.query[app.get('jsonp callback name')];252 253 // content-type254+ if (!this.get('Content-Type')) {255+ this.set('X-Content-Type-Options', 'nosniff');253- this.get('Content-Type') || this.set('Content-Type', 'application/json');256+ this.set('Content-Type', 'application/json');257+ }258 259 // fixup callback260 if (Array.isArray(callback)) {261 callback = callback[0];262 }263 264 // jsonp261- if (callback && 'string' === typeof callback) {265+ if (typeof callback === 'string' && callback.length !== 0) {266+ this.charset = 'utf-8';267+ this.set('X-Content-Type-Options', 'nosniff');268 this.set('Content-Type', 'text/javascript');263- var cb = callback.replace(/[^\[\]\w$.]/g, '');264- body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';269+270+ // restrict callback charset271+ callback = callback.replace(/[^\[\]\w$.]/g, '');272+273+ // replace chars not allowed in JavaScript that are in JSON274+ body = body275+ .replace(/\u2028/g, '\\u2028')276+ .replace(/\u2029/g, '\\u2029');277+278+ // the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"279+ // the typeof check is just to reduce client error noise280+ body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';281 }282 283 return this.send(body);284 };417 unmodified lines702 *703 * res.redirect('/foo/bar');704 * res.redirect('http://example.com');705 * res.redirect(301, 'http://example.com');690- * res.redirect('http://example.com', 301);706 * res.redirect('../login'); // /blog/post/1 -> /blog/login707 *693- * @param {String} url694- * @param {Number} code708 * @api public709 */710 711 res.redirect = function(url){6 unmodified lines718 if ('number' == typeof url) {719 status = url;720 url = arguments[1];721 } else {722+ deprecate('res.redirect(ur, status): Use res.redirect(status, url) instead');723 status = arguments[1];724 }725 }726 83 unmodified linesmodified:test/res.jsonp.js+45 added-31 removed
12 unmodified lines13 });14 15 request(app)16 .get('/?callback=something')17- .end(function(err, res){18- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');19- res.text.should.equal('typeof something === \'function\' && something({"count":1});');20- done();21- })17+ .expect('Content-Type', 'text/javascript; charset=utf-8')18+ .expect(200, /something\(\{"count":1\}\);/, done);19 })20 21 it('should use first callback parameter with jsonp', function(done){22 var app = express();2 unmodified lines25 res.jsonp({ count: 1 });26 });27 28 request(app)32- .get('/?callback=something&callback=somethingelse')33- .end(function(err, res){34- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');35- res.text.should.equal('typeof something === \'function\' && something({"count":1});');36- done();37- })29+ .get('/?callback=something&callback=somethingelse')30+ .expect('Content-Type', 'text/javascript; charset=utf-8')31+ .expect(200, /something\(\{"count":1\}\);/, done);32 })33 34 it('should ignore object callback parameter with jsonp', function(done){35 var app = express();18 unmodified lines54 });55 56 request(app)57 .get('/?clb=something')64- .end(function(err, res){65- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');66- res.text.should.equal('typeof something === \'function\' && something({"count":1});');67- done();68- })58+ .expect('Content-Type', 'text/javascript; charset=utf-8')59+ .expect(200, /something\(\{"count":1\}\);/, done);60 })61 62 it('should allow []', function(done){63 var app = express();3 unmodified lines67 });68 69 request(app)70 .get('/?callback=callbacks[123]')80- .end(function(err, res){81- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');82- res.text.should.equal('typeof callbacks[123] === \'function\' && callbacks[123]({"count":1});');83- done();84- })71+ .expect('Content-Type', 'text/javascript; charset=utf-8')72+ .expect(200, /callbacks\[123\]\(\{"count":1\}\);/, done);73 })74 75 it('should disallow arbitrary js', function(done){76 var app = express();3 unmodified lines80 });81 82 request(app)83 .get('/?callback=foo;bar()')96- .end(function(err, res){97- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');98- res.text.should.equal('typeof foobar === \'function\' && foobar({});');99- done();100- })84+ .expect('Content-Type', 'text/javascript; charset=utf-8')85+ .expect(200, /foobar\(\{\}\);/, done);86 })87 88 it('should escape utf whitespace', function(done){89 var app = express();3 unmodified lines93 });94 95 request(app)96 .get('/?callback=foo')112- .end(function(err, res){113- res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');114- res.text.should.equal('typeof foo === \'function\' && foo({"str":"\\u2028 \\u2029 woot"});');115- done();97+ .expect('Content-Type', 'text/javascript; charset=utf-8')98+ .expect(200, /foo\(\{"str":"\\u2028 \\u2029 woot"\}\);/, done);99+ });100+101+ it('should not escape utf whitespace for json fallback', function(done){102+ var app = express();103+104+ app.use(function(req, res){105+ res.jsonp({ str: '\u2028 \u2029 woot' });106 });107+108+ request(app)109+ .get('/')110+ .expect('Content-Type', 'application/json; charset=utf-8')111+ .expect(200, '{"str":"\u2028 \u2029 woot"}', done);112 });113 114+ it('should include security header and prologue', function (done) {115+ var app = express();116+117+ app.use(function(req, res){118+ res.jsonp({ count: 1 });119+ });120+121+ request(app)122+ .get('/?callback=something')123+ .expect('Content-Type', 'text/javascript; charset=utf-8')124+ .expect('X-Content-Type-Options', 'nosniff')125+ .expect(200, /^\/\*\*\//, done);126+ })127+128 it('should not override previous Content-Types with no callback', function(done){129 var app = express();130 131 app.get('/', function(req, res){3 unmodified lines135 136 request(app)137 .get('/')138 .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')130- .expect(200, '{"hello":"world"}', done);139+ .expect(200, '{"hello":"world"}', function (err, res) {140+ if (err) return done(err);141+ res.headers.should.not.have.property('x-content-type-options');142+ done();143+ });144 })145 146 it('should override previous Content-Types with callback', function(done){147 var app = express();5 unmodified lines153 154 request(app)155 .get('/?callback=cb')156 .expect('Content-Type', 'text/javascript; charset=utf-8')157+ .expect('X-Content-Type-Options', 'nosniff')158 .expect(200, /cb\(\{"hello":"world"\}\);$/, done);159 })160 161 describe('when given primitives', function(){186 unmodified linesmodified:test/res.send.js+15 added
79 unmodified lines80 .expect(400, done);81 })82 })83 84+ describe('.send(code, number)', function(){85+ it('should send number as json', function(done){86+ var app = express();87+88+ app.use(function(req, res){89+ res.send(200, 0.123);90+ });91+92+ request(app)93+ .get('/')94+ .expect('Content-Type', 'application/json; charset=utf-8')95+ .expect(200, '0.123', done);96+ })97+ })98+99 describe('.send(String)', function(){100 it('should send as html', function(done){101 var app = express();102 447 unmodified linesmodified:History.md+39 added
1+unreleased2+==========3+4+ * add explicit "Rosetta Flash JSONP abuse" protection5+ - previous versions are not vulnerable; this is just explicit protection6+ * deprecate `res.redirect(url, status)` -- use `res.redirect(status, url)` instead7+ * fix `res.send(status, num)` to send `num` as json (not error)8+ * remove unnecessary escaping when `res.jsonp` returns JSON response9+ * deps: debug@1.0.310+ - Add support for multiple wildcards in namespaces11+ * deps: methods@1.1.012+ - add `CONNECT`13+ * deps: parseurl@~1.1.314+ - faster parsing of href-only URLs15+16 4.5.1 / 2014-07-0617 ==================18 19 * fix routing regression when altering `req.method`231 unmodified lines251 - `app.router()` - returns the app Router instance252 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route253 - Router & Route - public API254 255+3.14.0 / 2014-07-11256+===================257+258+ * add explicit "Rosetta Flash JSONP abuse" protection259+ - previous versions are not vulnerable; this is just explicit protection260+ * deprecate `res.redirect(url, status)` -- use `res.redirect(status, url)` instead261+ * fix `res.send(status, num)` to send `num` as json (not error)262+ * remove unnecessary escaping when `res.jsonp` returns JSON response263+ * deps: basic-auth@1.0.0264+ - support empty password265+ - support empty username266+ * deps: connect@2.23.0267+ - deps: debug@1.0.3268+ - deps: express-session@~1.6.4269+ - deps: method-override@~2.1.0270+ - deps: parseurl@~1.1.3271+ - deps: serve-static@~1.3.1272+ * deps: debug@1.0.3273+ - Add support for multiple wildcards in namespaces274+ * deps: methods@1.1.0275+ - add `CONNECT`276+ * deps: parseurl@~1.1.3277+ - faster parsing of href-only URLs278+279 3.13.0 / 2014-07-03280 ===================281 282 * add deprecation message to `app.configure`1504 unmodified linesmodified:package.json+4 added-4 removed
25 unmodified lines2627282930303132333435363536373839408 unmodified lines4950515253535455565722 unmodified lines25 unmodified lines "license": "MIT", "dependencies": { "accepts": "~1.0.7", "buffer-crc32": "0.2.3", "debug": "1.0.2", "debug": "1.0.3", "depd": "0.3.0", "escape-html": "1.0.1", "finalhandler": "0.0.2", "media-typer": "0.2.0", "methods": "1.0.1", "parseurl": "1.0.1", "methods": "1.1.0", "parseurl": "~1.1.3", "proxy-addr": "1.0.1", "range-parser": "1.0.0", "send": "0.5.0", "serve-static": "~1.3.0",8 unmodified lines "path-to-regexp": "0.1.2" }, "devDependencies": { "after": "0.8.1", "istanbul": "0.2.14", "istanbul": "0.3.0", "mocha": "~1.20.1", "should": "~4.0.4", "supertest": "~0.13.0", "connect-redis": "~2.0.0",22 unmodified lines