Skip to content
Myr

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

5 files+133 added−51 removed

modified:lib/response.js+30 added-16 removed
98 unmodified lines
99 body = arguments[1];100 }101 }102103 // 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 }110111 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 lines
246 // 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')];252253 // 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 }258259 // fixup callback260 if (Array.isArray(callback)) {261 callback = callback[0];262 }263264 // 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 + ');';269270 // restrict callback charset271 callback = callback.replace(/[^\[\]\w$.]/g, '');272273 // replace chars not allowed in JavaScript that are in JSON274 body = body275 .replace(/\u2028/g, '\\u2028')276 .replace(/\u2029/g, '\\u2029');277278 // 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 }282283 return this.send(body);284};
417 unmodified lines
702 *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 */710711res.redirect = function(url){
6 unmodified lines
718 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 lines
modified:test/res.jsonp.js+45 added-31 removed
12 unmodified lines
13 });1415 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 })2021 it('should use first callback parameter with jsonp', function(done){22 var app = express();
2 unmodified lines
25 res.jsonp({ count: 1 });26 });2728 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 })3334 it('should ignore object callback parameter with jsonp', function(done){35 var app = express();
18 unmodified lines
54 });5556 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 })6162 it('should allow []', function(done){63 var app = express();
3 unmodified lines
67 });6869 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 })7475 it('should disallow arbitrary js', function(done){76 var app = express();
3 unmodified lines
80 });8182 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 })8788 it('should escape utf whitespace', function(done){89 var app = express();
3 unmodified lines
93 });9495 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 });100101 it('should not escape utf whitespace for json fallback', function(done){102 var app = express();103104 app.use(function(req, res){105 res.jsonp({ str: '\u2028 \u2029 woot' });106 });107108 request(app)109 .get('/')110 .expect('Content-Type', 'application/json; charset=utf-8')111 .expect(200, '{"str":"\u2028 \u2029 woot"}', done);112 });113114 it('should include security header and prologue', function (done) {115 var app = express();116117 app.use(function(req, res){118 res.jsonp({ count: 1 });119 });120121 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 })127128 it('should not override previous Content-Types with no callback', function(done){129 var app = express();130131 app.get('/', function(req, res){
3 unmodified lines
135136 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 })145146 it('should override previous Content-Types with callback', function(done){147 var app = express();
5 unmodified lines
153154 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 })160161 describe('when given primitives', function(){
186 unmodified lines
modified:test/res.send.js+15 added
79 unmodified lines
80 .expect(400, done);81 })82 })8384 describe('.send(code, number)', function(){85 it('should send number as json', function(done){86 var app = express();8788 app.use(function(req, res){89 res.send(200, 0.123);90 });9192 request(app)93 .get('/')94 .expect('Content-Type', 'application/json; charset=utf-8')95 .expect(200, '0.123', done);96 })97 })9899 describe('.send(String)', function(){100 it('should send as html', function(done){101 var app = express();102
447 unmodified lines
modified:History.md+39 added
1unreleased2==========34 * 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 URLs15164.5.1 / 2014-07-0617==================1819 * fix routing regression when altering `req.method`
231 unmodified lines
251 - `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 API2542553.14.0 / 2014-07-11256===================257258 * 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 URLs2782793.13.0 / 2014-07-03280===================281282 * add deprecation message to `app.configure`
1504 unmodified lines
modified:package.json+4 added-4 removed