Skip to content
Myr

fix: don't render redirect values in anchor href

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

authored by Chris de Almeida · committed by Ulises Gascón · parent 125bb74 · Browse files · 2 files+22 added−4 removed
This commit

State

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

Trailers

  • Co-authored-by: Ulises Gascón <ulisesgascongonzalez@gmail.com>

Diff stats

2 files+22 added−4 removed

  • tests:+21 added−3 removed
  • other:+1 added−1 removed

2 files+22 added−4 removed

modified:lib/response.js+1 added-1 removed
967 unmodified lines
968 },969970 html: function(){971 var u = escapeHtml(address);972 body = '<p>' + statuses.message[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'972 body = '<p>' + statuses.message[status] + '. Redirecting to ' + u + '</p>'973 },974975 default: function(){976 body = '';
202 unmodified lines
modified:test/res.redirect.js+21 added-3 removed
104 unmodified lines
105 .get('/')106 .set('Accept', 'text/html')107 .expect('Content-Type', /html/)108 .expect('Location', 'http://google.com')109 .expect(302, '<p>Found. Redirecting to <a href="http://google.com">http://google.com</a></p>', done)109 .expect(302, '<p>Found. Redirecting to http://google.com</p>', done)110 })111112 it('should escape the url', function(done){113 var app = express();
7 unmodified lines
121 .set('Host', 'http://example.com')122 .set('Accept', 'text/html')123 .expect('Content-Type', /html/)124 .expect('Location', '%3Cla\'me%3E')125 .expect(302, '<p>Found. Redirecting to <a href="%3Cla&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)125 .expect(302, '<p>Found. Redirecting to %3Cla&#39;me%3E</p>', done)126 })127128 it('should not render evil javascript links in anchor href (prevent XSS)', function(done){129 var app = express();130 var xss = 'javascript:eval(document.body.innerHTML=`<p>XSS</p>`);';131 var encodedXss = 'javascript:eval(document.body.innerHTML=%60%3Cp%3EXSS%3C/p%3E%60);';132133 app.use(function(req, res){134 res.redirect(xss);135 });136137 request(app)138 .get('/')139 .set('Host', 'http://example.com')140 .set('Accept', 'text/html')141 .expect('Content-Type', /html/)142 .expect('Location', encodedXss)143 .expect(302, '<p>Found. Redirecting to ' + encodedXss +'</p>', done);144 });145146 it('should include the redirect type', function(done){147 var app = express();148149 app.use(function(req, res){
4 unmodified lines
154 .get('/')155 .set('Accept', 'text/html')156 .expect('Content-Type', /html/)157 .expect('Location', 'http://google.com')140 .expect(301, '<p>Moved Permanently. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);158 .expect(301, '<p>Moved Permanently. Redirecting to http://google.com</p>', done);159 })160 })161162 describe('when accepting text', function(){
67 unmodified lines