Skip to content
Myr

Prevent open redirect allow list bypass due to encodeurl

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

authored by FDrag0n · committed by Wes Todd · parent 567c9c6 · Browse files · 2 files+64 added−2 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: Jon Church <me@jonchurch.com>

Diff stats

2 files+64 added−2 removed

  • tests:+45 added−1 removed
  • other:+19 added−1 removed

2 files+64 added−2 removed

modified:lib/response.js+19 added-1 removed
32 unmodified lines
33var extname = path.extname;34var mime = send.mime;35var resolve = path.resolve;36var vary = require('vary');37var urlParse = require('url').parse;3839/**40 * Response prototype.41 * @public
869 unmodified lines
911 if (url === 'back') {912 loc = this.req.get('Referrer') || '/';913 }914915 var lowerLoc = loc.toLowerCase();916 var encodedUrl = encodeUrl(loc);917 if (lowerLoc.indexOf('https://') === 0 || lowerLoc.indexOf('http://') === 0) {918 try {919 var parsedUrl = urlParse(loc);920 var parsedEncodedUrl = urlParse(encodedUrl);921 // Because this can encode the host, check that we did not change the host922 if (parsedUrl.host !== parsedEncodedUrl.host) {923 // If the host changes after encodeUrl, return the original url924 return this.set('Location', loc);925 }926 } catch (e) {927 // If parse fails, return the original url928 return this.set('Location', loc);929 }930 }931932 // set location915 return this.set('Location', encodeUrl(loc));933 return this.set('Location', encodedUrl);934};935936/**937 * Redirect to the given `url` with optional response `status`
250 unmodified lines
modified:test/res.location.js+45 added-1 removed