Skip to content

Commit dcf8364

Browse files
authored
Merge pull request #368 from jc21/develop
Support ipv6 address as a origin header, hopefully fixes #149
2 parents a572553 + b783602 commit dcf8364

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

backend/lib/express/cors.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ module.exports = function (req, res, next) {
44

55
if (req.headers.origin) {
66

7+
const originSchema = {
8+
oneOf: [
9+
{
10+
type: 'string',
11+
pattern: '^[a-z\\-]+:\\/\\/(?:[\\w\\-\\.]+(:[0-9]+)?/?)?$'
12+
},
13+
{
14+
type: 'string',
15+
pattern: '^[a-z\\-]+:\\/\\/(?:\\[([a-z0-9]{0,4}\\:?)+\\])?/?(:[0-9]+)?$'
16+
}
17+
]
18+
};
19+
720
// very relaxed validation....
8-
validator({
9-
type: 'string',
10-
pattern: '^[a-z\\-]+:\\/\\/(?:[\\w\\-\\.]+(:[0-9]+)?/?)?$'
11-
}, req.headers.origin)
21+
validator(originSchema, req.headers.origin)
1222
.then(function () {
1323
res.set({
1424
'Access-Control-Allow-Origin': req.headers.origin,

0 commit comments

Comments
 (0)