From b783602786dc61ee5640a5be5e242d2266b2adde Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Tue, 14 Apr 2020 12:55:58 +1000 Subject: [PATCH] Support ipv6 address as a origin header, hopefully fixes #149 --- backend/lib/express/cors.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/lib/express/cors.js b/backend/lib/express/cors.js index bb4ca89..c9befee 100644 --- a/backend/lib/express/cors.js +++ b/backend/lib/express/cors.js @@ -4,11 +4,21 @@ module.exports = function (req, res, next) { if (req.headers.origin) { + const originSchema = { + oneOf: [ + { + type: 'string', + pattern: '^[a-z\\-]+:\\/\\/(?:[\\w\\-\\.]+(:[0-9]+)?/?)?$' + }, + { + type: 'string', + pattern: '^[a-z\\-]+:\\/\\/(?:\\[([a-z0-9]{0,4}\\:?)+\\])?/?(:[0-9]+)?$' + } + ] + }; + // very relaxed validation.... - validator({ - type: 'string', - pattern: '^[a-z\\-]+:\\/\\/(?:[\\w\\-\\.]+(:[0-9]+)?/?)?$' - }, req.headers.origin) + validator(originSchema, req.headers.origin) .then(function () { res.set({ 'Access-Control-Allow-Origin': req.headers.origin,