Skip to content

Commit 610974a

Browse files
committed
Allow storage proxy to work with IPv4
Storage proxy signed cookies would get assigned to wrong domain if configured host name is IPv4 address, thus blocking display of assets. Problem is in `psl` package which parses IPv4 addresses, thus producing wrong domains. Fix detects IPv4 addresses using regular expression and just returns `null` for domain.
1 parent b57a81e commit 610974a

File tree

1 file changed

+8
-1
lines changed
  • server/shared/storage/proxy

1 file changed

+8
-1
lines changed

server/shared/storage/proxy/mw.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const path = require('path');
77
const router = require('express').Router();
88
const psl = require('psl');
99

10+
const IPV4_REGEX = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/;
11+
12+
function getDomain() {
13+
if (IPV4_REGEX.test(config.hostname)) return null;
14+
return psl.parse(config.hostname).domain;
15+
}
16+
1017
module.exports = (storage, proxy) => {
1118
function getFile(req, res, next) {
1219
const key = req.params[0];
@@ -24,7 +31,7 @@ module.exports = (storage, proxy) => {
2431
if (proxy.hasCookies(req.cookies, repositoryId)) return next();
2532
const maxAge = 1000 * 60 * 60; // 1 hour in ms
2633
const cookies = proxy.getSignedCookies(repositoryId, maxAge);
27-
const { domain } = psl.parse(config.hostname);
34+
const domain = getDomain();
2835
const cookieOptions = { domain, maxAge, httpOnly: true };
2936
Object.entries(cookies).forEach(([cookie, value]) => {
3037
res.cookie(cookie, value, cookieOptions);

0 commit comments

Comments
 (0)