Skip to content

Commit

Permalink
fix(security): don't follow redirects (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
billiegoose authored Jan 7, 2022
1 parent 617b73f commit 1b1c91e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ jobs:
- job: Linux

pool:
vmImage: 'Ubuntu 16.04'
vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
Expand Down
Empty file modified bin.js
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const exposeHeaders = [
'etag',
'expires',
'last-modified',
'location',
'pragma',
'server',
'transfer-encoding',
Expand Down Expand Up @@ -125,10 +126,16 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
`${protocol}://${pathdomain}/${remainingpath}`,
{
method: req.method,
redirect: 'manual',
headers,
body: (req.method !== 'GET' && req.method !== 'HEAD') ? req : undefined
}
).then(f => {
if (f.headers.has('location')) {
// Modify the location so the client continues to use the proxy
let newUrl = f.headers.get('location').replace(/^https?:\//, '')
f.headers.set('location', newUrl)
}
res.statusCode = f.status
for (let h of exposeHeaders) {
if (h === 'content-length') continue
Expand Down

0 comments on commit 1b1c91e

Please sign in to comment.