Skip to content

Commit 1b1c91e

Browse files
authored
fix(security): don't follow redirects (#10)
1 parent 617b73f commit 1b1c91e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ jobs:
22
- job: Linux
33

44
pool:
5-
vmImage: 'Ubuntu 16.04'
5+
vmImage: 'ubuntu-latest'
66

77
steps:
88
- task: NodeTool@0

bin.js

100644100755
File mode changed.

middleware.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const exposeHeaders = [
3535
'etag',
3636
'expires',
3737
'last-modified',
38+
'location',
3839
'pragma',
3940
'server',
4041
'transfer-encoding',
@@ -125,10 +126,16 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
125126
`${protocol}://${pathdomain}/${remainingpath}`,
126127
{
127128
method: req.method,
129+
redirect: 'manual',
128130
headers,
129131
body: (req.method !== 'GET' && req.method !== 'HEAD') ? req : undefined
130132
}
131133
).then(f => {
134+
if (f.headers.has('location')) {
135+
// Modify the location so the client continues to use the proxy
136+
let newUrl = f.headers.get('location').replace(/^https?:\//, '')
137+
f.headers.set('location', newUrl)
138+
}
132139
res.statusCode = f.status
133140
for (let h of exposeHeaders) {
134141
if (h === 'content-length') continue

0 commit comments

Comments
 (0)