diff --git a/lib/up-storage.js b/lib/up-storage.js index daf6ed6d2..f4c975511 100644 --- a/lib/up-storage.js +++ b/lib/up-storage.js @@ -361,11 +361,19 @@ Storage.prototype.search = function(startkey, options) { Storage.prototype._add_proxy_headers = function(req, headers) { if (req) { - headers['X-Forwarded-For'] = ( - req && req.headers['x-forwarded-for'] - ? req.headers['x-forwarded-for'] + ', ' - : '' - ) + req.connection.remoteAddress + // Only submit X-Forwarded-For field if we don't have a proxy selected + // in the config file. + // + // Otherwise misconfigured proxy could return 407: + // https://github.com/rlidwka/sinopia/issues/254 + // + if (!this.proxy) { + headers['X-Forwarded-For'] = ( + req && req.headers['x-forwarded-for'] + ? req.headers['x-forwarded-for'] + ', ' + : '' + ) + req.connection.remoteAddress + } } // always attach Via header to avoid loops, even if we're not proxying