Skip to content

Commit 9230b60

Browse files
committed
fix: CORS does not enforce configured origin policies
1 parent f92e93a commit 9230b60

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

src/cors.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ const setResponseHeaders = (res, responseHeaders=[]) => responseHeaders.forEach(
3636

3737
const getRequestOrigin = req => {
3838
const origin = (req.headers.origin || '').toLowerCase()
39-
const host = (req.headers.host || '').toLowerCase()
4039
const referer = (req.headers.referer || req.headers.referrer || '').toLowerCase()
41-
const https = req.secure !== undefined ? req.secure : (req.url || '').trim().match(/^https:/)
4240
const refUrl = url.parse(referer)
4341

4442
if (origin)
4543
return origin
46-
else if (host)
47-
return `${https ? 'https:' : 'http:'}//${host}`
4844
else if (referer && refUrl.host)
49-
return refUrl.protocol ? `${refUrl.protocol}//${refUrl.host}` : `${https ? 'https:' : 'http:'}//${refUrl.host}`
45+
return `${refUrl.protocol}//${refUrl.host}`
5046
else
5147
return null
5248
}

test/cors.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,6 @@ describe('cors', () =>
113113
headers: {
114114
referer: 'http://localhost:8080'
115115
}
116-
}),
117-
httpMocks.createRequest({
118-
headers: {
119-
host: 'localhost:8080'
120-
},
121-
secure: false
122-
}),
123-
httpMocks.createRequest({
124-
headers: {
125-
host: 'localhost:8080'
126-
},
127-
url: 'http://localhost:8080'
128116
})]
129117

130118
requests.forEach(req => {

0 commit comments

Comments
 (0)