Skip to content
Myr

Merge pull request #1425 from gmethvin/encode_text_redirect

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

Escape URLs in text/plain res.redirect response

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parents c70db96, ea5e254 · 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
653 unmodified lines
654655 // Support text/{plain,html} by default656 this.format({657 text: function(){658 body = statusCodes[status] + '. Redirecting to ' + url;658 body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);659 },660661 html: function(){662 var u = utils.escape(url);
54 unmodified lines
modified:test/res.redirect.js+17 added
285 unmodified lines
286 res.text.should.equal('Moved Temporarily. Redirecting to http://google.com');287 done();288 })289 })290291 it('should encode the url', function(done){292 var app = express();293294 app.use(function(req, res){295 res.redirect('http://example.com/?param=<script>alert("hax");</script>');296 });297298 request(app)299 .get('/')300 .set('Host', 'http://example.com')301 .set('Accept', 'text/plain, */*')302 .end(function(err, res){303 res.text.should.equal('Moved Temporarily. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E');304 done();305 })306 })307 })308309 describe('when accepting neither text or html', function(){310 it('should respond with an empty body', function(done){
20 unmodified lines