Skip to content

Allow storage proxy to work with IPv4 #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: release/5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const auth = require('./auth');
const consumer = require('./consumer');
const isIp = require('is-ip');
const isLocalhost = require('is-localhost');
const mail = require('./mail');
const parse = require('url-parse');
Expand All @@ -15,6 +16,8 @@ const port = resolvePort();
const origin = resolveOrigin(hostname, protocol, port);
const previewUrl = process.env.PREVIEW_URL;

validateStorageProxy(storage.proxy, hostname);

module.exports = {
protocol,
hostname,
Expand Down Expand Up @@ -58,3 +61,9 @@ function resolveOriginPort(hostname) {
if (REVERSE_PROXY_PORT === '80' || REVERSE_PROXY_PORT === '443') return '';
return `:${REVERSE_PROXY_PORT}`;
}

function validateStorageProxy(proxy, hostname) {
if (isIp.v4(hostname) && /cloudfront/i.test(proxy.provider)) {
throw new Error('CloudFront storage proxy cannot be used alongside IPv4 host name');
}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"humanize-string": "^2.1.0",
"ioredis": "^4.24.2",
"is-iexplorer": "^1.0.0",
"is-ip": "^3.1.0",
"is-localhost": "0.0.2",
"is-safari": "^1.0.0",
"is-url": "^1.2.2",
Expand Down
8 changes: 7 additions & 1 deletion server/shared/storage/proxy/mw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

const config = require('../../../../config/server');
const { FORBIDDEN } = require('http-status-codes');
const isIp = require('is-ip');
const miss = require('mississippi');
const path = require('path');
const router = require('express').Router();
const psl = require('psl');

function getDomain() {
if (isIp.v4(config.hostname)) return null;
return psl.parse(config.hostname).domain;
}

module.exports = (storage, proxy) => {
function getFile(req, res, next) {
const key = req.params[0];
Expand All @@ -24,7 +30,7 @@ module.exports = (storage, proxy) => {
if (proxy.hasCookies(req.cookies, repositoryId)) return next();
const maxAge = 1000 * 60 * 60; // 1 hour in ms
const cookies = proxy.getSignedCookies(repositoryId, maxAge);
const { domain } = psl.parse(config.hostname);
const domain = getDomain();
const cookieOptions = { domain, maxAge, httpOnly: true };
Object.entries(cookies).forEach(([cookie, value]) => {
res.cookie(cookie, value, cookieOptions);
Expand Down