fix trustedproxy cloudflare setting and added http_proxy for cloudflare ip download

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed May 22, 2026 at 12:54 UTC 8aca5fa5a7733377d42806ed193a64abe2d9cbe3
2 files changed +20 -11
certoperations.js
+11 -4
@@ -522,12 +522,19 @@ module.exports.CertificateOperations = function (parent) {
522 if (u.protocol == 'https:') {
523 // Read from HTTPS
524 const https = require('https');
525 - https.get(url, function(resp) {
525 + const options = { timeout: 10000 };
526 + if (process.env['HTTPS_PROXY'] || process.env['HTTP_PROXY'] || process.env['https_proxy'] || process.env['http_proxy']) {
527 + options.agent = new (require('https-proxy-agent').HttpsProxyAgent)(process.env['HTTPS_PROXY'] || process.env['HTTP_PROXY'] || process.env['https_proxy'] || process.env['http_proxy']);
528 + }
529 + const req = https.get(url, options, function(resp) {
530 + if (resp.statusCode < 200 || resp.statusCode >= 300) { resp.resume(); func(url, null, tag); return; }
531 var data = '';
532 resp.on('data', function(chunk) { data += chunk; });
528 - resp.on('end', function () { func(url, data, tag); });
529 - resp.on('error', function (chunk) { func(url, null, tag); });
530 - }).on('error', function (err) { func(url, null, tag); });
533 + resp.on('end', function() { func(url, data, tag); });
534 + resp.on('error', function() { func(url, null, tag); });
535 + });
536 + req.on('error', function() { func(url, null, tag); });
537 + req.on('timeout', function() { req.destroy(); func(url, null, tag); });
538 } else if (u.protocol == 'file:') {
539 // Read a file
540 obj.fs.readFile(url.substring(7), 'utf8', function (err, data) {
meshcentral.js
+9 -7
@@ -1819,23 +1819,25 @@ function CreateMeshCentralServer(config, args) {
1819 }
1820
1821 // Load CloudFlare trusted proxies list if needed
1822 - if ((obj.config.settings.trustedproxy != null) && (typeof obj.config.settings.trustedproxy == 'string') && (obj.config.settings.trustedproxy.toLowerCase() == 'cloudflare')) {
1822 + const trustedproxyIsCloudflareString = (obj.args.trustedproxy != null) && (typeof obj.args.trustedproxy == 'string') && (obj.args.trustedproxy.toLowerCase() == 'cloudflare');
1823 + const trustedproxyIsCloudflareArray = Array.isArray(obj.args.trustedproxy) && obj.args.trustedproxy.some(function (x) { return (typeof x == 'string') && (x.toLowerCase() == 'cloudflare'); });
1824 + if (trustedproxyIsCloudflareString || trustedproxyIsCloudflareArray) {
1825 obj.config.settings.extrascriptsrc = 'ajax.cloudflare.com'; // Add CloudFlare as a trusted script source. This allows for CloudFlare's RocketLoader feature.
1824 - delete obj.args.trustedproxy;
1825 - delete obj.config.settings.trustedproxy;
1826 + // Preserve any non-'cloudflare' entries already in the array
1827 + const existingProxies = trustedproxyIsCloudflareArray ? obj.args.trustedproxy.filter(function (x) { return !(typeof x == 'string' && x.toLowerCase() == 'cloudflare'); }) : [];
1828 obj.certificateOperations.loadTextFile('https://www.cloudflare.com/ips-v4', null, function (url, data, tag) {
1829 if (data != null) {
1828 - if (Array.isArray(obj.args.trustedproxy) == false) { obj.args.trustedproxy = []; }
1830 + const newProxies = existingProxies.slice();
1831 const ipranges = data.split('\n');
1830 - for (var i in ipranges) { if (ipranges[i] != '') { obj.args.trustedproxy.push(ipranges[i]); } }
1832 + for (var i in ipranges) { if (ipranges[i] != '') { newProxies.push(ipranges[i]); } }
1833 obj.certificateOperations.loadTextFile('https://www.cloudflare.com/ips-v6', null, function (url, data, tag) {
1834 if (data != null) {
1835 var ipranges = data.split('\n');
1834 - for (var i in ipranges) { if (ipranges[i] != '') { obj.args.trustedproxy.push(ipranges[i]); } }
1835 - obj.config.settings.trustedproxy = obj.args.trustedproxy;
1836 + for (var i in ipranges) { if (ipranges[i] != '') { newProxies.push(ipranges[i]); } }
1837 } else {
1838 addServerWarning("Unable to load CloudFlare trusted proxy IPv6 address list.", 16);
1839 }
1840 + obj.args.trustedproxy = newProxies;
1841 obj.StartEx4(); // Keep going
1842 });
1843 } else {