Skip to content
Myr

Strip unsafe chars from jsonp callbacks

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 b1004b6 · Browse files · 2 files+5 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+5 added−1 removed

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

2 files+5 added−1 removed

modified:lib/express/response.js+1 added-1 removed
83 unmodified lines
84 }85 body = JSON.stringify(body);86 if (this.req.query.callback && this.app.settings['jsonp callback']) {87 this.header('Content-Type', 'text/javascript');88 body = this.req.query.callback + '(' + body + ');';88 body = this.req.query.callback.replace(/[^\w$.]/g, '') + '(' + body + ');';89 }90 }91 break;92 }
301 unmodified lines
modified:test/response.test.js+4 added
64 unmodified lines
65 { url: '/jsonp?callback=baz' },66 { body: 'baz({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});6768 assert.response(app,69 { url: '/jsonp?callback=invalid()[]' },70 { body: 'invalid({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});7172 assert.response(app,73 { url: '/json?callback=test' },74 { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});7576 assert.response(app,
341 unmodified lines