Skip to content
Myr

fix jsonp callback char restrictions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 2bba69f · Browse files · 2 files+18 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+18 added−1 removed

  • tests:+17 added−0 removed
  • other:+1 added−1 removed

2 files+18 added−1 removed

modified:lib/response.js+1 added-1 removed
194 unmodified lines
195 196 // jsonp197 if (callback && jsonp) {198 this.set('Content-Type', 'text/javascript');199 body = callback.replace(/[^[]\w$.]/g, '') + '(' + body + ');';199 body = callback.replace(/[^\[\]\w$.]/g, '') + '(' + body + ');';200 }201202 return this.send(body);203};
475 unmodified lines
modified:test/res.json.js+17 added
57 unmodified lines
58 res.text.should.equal('callbacks[123]({"count":1});');59 done();60 })61 })6263 it('should disallow arbitrary js', function(done){64 var app = express();6566 app.enable('jsonp callback');67 app.use(function(req, res){68 res.json({});69 });7071 request(app)72 .get('/?callback=foo;bar()')73 .end(function(err, res){74 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');75 res.text.should.equal('foobar({});');76 done();77 })78 })79 })8081 describe('when given primitives', function(){82 it('should respond with json', function(done){
145 unmodified lines