replace load more url.parse #7735

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

si458 committed Apr 1, 2026 at 21:40 UTC 300c8ea99c82aa40cc045a1aa7a83ab3040be52b
10 files changed +33 -31
certoperations.js
+2 -2
@@ -518,7 +518,7 @@ module.exports.CertificateOperations = function (parent) {
518
519 // Return a text file from a remote HTTPS server
520 obj.loadTextFile = function (url, tag, func) {
521 - const u = require('url').parse(url);
521 + const u = new URL(url);
522 if (u.protocol == 'https:') {
523 // Read from HTTPS
524 const https = require('https');
@@ -538,7 +538,7 @@ module.exports.CertificateOperations = function (parent) {
538
539 // Return the certificate of the remote HTTPS server
540 obj.loadCertificate = function (url, hostname, tag, func) {
541 - const u = require('url').parse(url);
541 + const u = new URL(url);
542 if (u.protocol == 'https:') {
543 // Read the certificate from HTTPS
544 if (hostname == null) { hostname = u.hostname; }
meshagent.js
+6 -4
@@ -1237,7 +1237,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1237
1238 // Agent update. The recovery core was loaded in the agent, send a command to update the agent
1239 obj.agentCoreUpdateTaskId = taskid;
1240 - const url = '*' + require('url').parse(obj.agentExeInfo.url).path;
1240 + const getme = new URL(obj.agentExeInfo.url);
1241 + const url = '*' + getme.pathname + getme.search;
1242 var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex };
1243 parent.parent.debug('agentupdate', "Sending agent update url: " + cmd.url);
1244
@@ -1584,7 +1585,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1585
1586 // Agent is requesting an agent update
1587 obj.agentCoreUpdateTaskId = taskid;
1587 - const url = '*' + require('url').parse(obj.agentExeInfo.url).path;
1588 + const getme = new URL(obj.agentExeInfo.url);
1589 + const url = '*' + getme.pathname + getme.search;
1590 var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex, sessionid: agentUpdateFunc.sessionid };
1591 parent.parent.debug('agentupdate', "Sending user requested agent update url: " + cmd.url);
1592
@@ -1630,11 +1632,11 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1632
1633 // parse the URL
1634 var url = null;
1633 - try { url = require('url').parse(command.url); } catch (ex) { }
1635 + try { url = new URL(command.url); } catch (ex) { }
1636 if (url == null) return;
1637
1638 // Decode the cookie
1637 - var urlSplit = url.query.split('&c=');
1639 + var urlSplit = url.search.slice(1).split('&c=');
1640 if (urlSplit.length != 2) return;
1641 const authCookie = parent.parent.decodeCookie(urlSplit[1], null, 1);
1642 if ((authCookie == null) || (typeof authCookie.c != 'string') || (('code=' + authCookie.c) != urlSplit[0])) return;
meshbot.js
+1 -1
@@ -61,7 +61,7 @@ function serverConnect() {
61 // Setup the HTTP proxy if needed
62 if (args.proxy != null) {
63 const HttpsProxyAgent = require('https-proxy-agent');
64 - options.agent = new HttpsProxyAgent(require('url').parse(args.proxy));
64 + options.agent = new HttpsProxyAgent(new URL(args.proxy));
65 }
66
67 // Authentication setup
meshctrl.js
+2 -2
@@ -1326,7 +1326,7 @@ function serverConnect() {
1326 // Setup the HTTP proxy if needed
1327 if (args.proxy != null) {
1328 const HttpsProxyAgent = require('https-proxy-agent');
1329 - options.agent = new HttpsProxyAgent(require('url').parse(args.proxy));
1329 + options.agent = new HttpsProxyAgent(new URL(args.proxy));
1330 }
1331
1332 // Password authentication
@@ -2727,7 +2727,7 @@ function connectTunnel(url) {
2727 var options = { rejectUnauthorized: false, checkServerIdentity: onVerifyServer }
2728
2729 // Setup the HTTP proxy if needed
2730 - if (args.proxy != null) { const HttpsProxyAgent = require('https-proxy-agent'); options.agent = new HttpsProxyAgent(require('url').parse(args.proxy)); }
2730 + if (args.proxy != null) { const HttpsProxyAgent = require('https-proxy-agent'); options.agent = new HttpsProxyAgent(new URL(args.proxy)); }
2731
2732 // Connect the WebSocket
2733 console.log('Connecting...');
meshipkvm.js
+3 -3
@@ -262,10 +262,10 @@ function CreateIPKVMManager(parent) {
262
263 // Parse an incoming HTTP request URL
264 function parseIpKvmUrl(domain, url) {
265 - const q = require('url').parse(url, true);
266 - const i = q.path.indexOf('/ipkvm.ashx/');
265 + const q = new URL(url);
266 + const i = q.pathname.indexOf('/ipkvm.ashx/');
267 if (i == -1) return null;
268 - const urlargs = q.path.substring(i + 12).split('/');
268 + const urlargs = q.pathname.substring(i + 12).split('/');
269 if (urlargs[0].length != 64) return null;
270 const nodeid = 'node/' + domain.id + '/' + urlargs[0];
271 const nid = urlargs[0];
meshmessaging.js
+7 -7
@@ -378,18 +378,18 @@ module.exports.CreateServer = function (parent) {
378 // Convert a CallMeBot URL into a handle
379 obj.callmebotUrlToHandle = function (xurl) {
380 var url = null;
381 - try { url = require('url').parse(xurl); } catch (ex) { return; }
382 - if ((url == null) || (url.host != 'api.callmebot.com') || (url.query == null)) return;
383 - var urlArgs = {}, urlArgs2 = url.query.split('&');
381 + try { url = new URL(xurl); } catch (ex) { return; }
382 + if ((url == null) || (url.host != 'api.callmebot.com') || !url.search) return;
383 + var urlArgs = {}, urlArgs2 = url.search.slice(1).split('&');
384 for (var i in urlArgs2) { var j = urlArgs2[i].indexOf('='); if (j > 0) { urlArgs[urlArgs2[i].substring(0, j)] = urlArgs2[i].substring(j + 1); } }
385 if ((urlArgs['phone'] != null) && (urlArgs['phone'].indexOf('|') >= 0)) return;
386 if ((urlArgs['apikey'] != null) && (urlArgs['apikey'].indexOf('|') >= 0)) return;
387 if ((urlArgs['user'] != null) && (urlArgs['user'].indexOf('|') >= 0)) return;
388 // Signal Messenger, Whatapp, Facebook and Telegram
389 - if (url.path.startsWith('/signal') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:signal|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
390 - if (url.path.startsWith('/whatsapp') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:whatsapp|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
391 - if (url.path.startsWith('/facebook') && (urlArgs['apikey'] != null)) { return 'callmebot:facebook|' + urlArgs['apikey']; }
392 - if (url.path.startsWith('/text') && (urlArgs['user'] != null)) { return 'callmebot:telegram|' + urlArgs['user']; }
389 + if (url.pathname.startsWith('/signal') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:signal|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
390 + if (url.pathname.startsWith('/whatsapp') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:whatsapp|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
391 + if (url.pathname.startsWith('/facebook') && (urlArgs['apikey'] != null)) { return 'callmebot:facebook|' + urlArgs['apikey']; }
392 + if (url.pathname.startsWith('/text') && (urlArgs['user'] != null)) { return 'callmebot:telegram|' + urlArgs['user']; }
393 return null;
394 }
395
meshsms.js
+3 -3
@@ -147,16 +147,16 @@ module.exports.CreateMeshSMS = function (parent) {
147 } else {
148 var sms = parent.config.sms.url.split('{{phone}}').join(encodeURIComponent(to)).split('{{message}}').join(encodeURIComponent(msg));
149 parent.debug('email', 'SMS URL: ' + sms);
150 - sms = require('url').parse(sms);
150 + sms = new URL(sms);
151 if (sms.protocol == 'https:') {
152 // HTTPS GET request
153 - const options = { hostname: sms.hostname, port: sms.port ? sms.port : 443, path: sms.path, method: 'GET', rejectUnauthorized: false };
153 + const options = { hostname: sms.hostname, port: sms.port ? sms.port : 443, path: sms.pathname + sms.search, method: 'GET', rejectUnauthorized: false };
154 const request = require('https').request(options, function (res) { parent.debug('email', 'SMS result: ' + res.statusCode); if (func != null) { func(res.statusCode == 200, (res.statusCode == 200) ? null : res.statusCode, null); } res.on('data', function (d) { }); });
155 request.on('error', function (err) { parent.debug('email', 'SMS error: ' + err); if (func != null) { func(false, err, null); } });
156 request.end();
157 } else {
158 // HTTP GET request
159 - const options = { hostname: sms.hostname, port: sms.port ? sms.port : 80, path: sms.path, method: 'GET' };
159 + const options = { hostname: sms.hostname, port: sms.port ? sms.port : 80, path: sms.pathname + sms.search, method: 'GET' };
160 const request = require('http').request(options, function (res) { parent.debug('email', 'SMS result: ' + res.statusCode); if (func != null) { func(res.statusCode == 200, (res.statusCode == 200) ? null : res.statusCode, null); } res.on('data', function (d) { }); });
161 request.on('error', function (err) { parent.debug('email', 'SMS error: ' + err); if (func != null) { func(false, err, null); } });
162 request.end();
meshuser.js
+5 -5
@@ -994,16 +994,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
994 if (command.type == 'tunnel') {
995 if ((typeof command.value != 'string') || (typeof command.nodeid != 'string')) break;
996 var url = null;
997 - try { url = require('url').parse(command.value, true); } catch (ex) { }
997 + try { url = new URL(command.value); } catch (ex) { }
998 if (url == null) break; // Bad URL
999 - if (url.query && url.query.nodeid && (url.query.nodeid != command.nodeid)) break; // Bad NodeID in URL query string
999 + if (url.searchParams.get('nodeid') && (url.searchParams.get('nodeid') != command.nodeid)) break; // Bad NodeID in URL query string
1000
1001 // Check rights
1002 - if (url.query.p == '1') { requiredNonRights = MESHRIGHT_NOTERMINAL; }
1003 - else if ((url.query.p == '4') || (url.query.p == '5')) { requiredNonRights = MESHRIGHT_NOFILES; }
1002 + if (url.searchParams.get('p') == '1') { requiredNonRights = MESHRIGHT_NOTERMINAL; }
1003 + else if ((url.searchParams.get('p') == '4') || (url.searchParams.get('p') == '5')) { requiredNonRights = MESHRIGHT_NOFILES; }
1004
1005 // If we are using the desktop multiplexor, remove the VIEWONLY limitation. The multiplexor will take care of enforcing that limitation when needed.
1006 - if (((parent.parent.config.settings.desktopmultiplex === true) || (domain.desktopmultiplex === true)) && (url.query.p == '2')) { routingOptions = { removeViewOnlyLimitation: true }; }
1006 + if (((parent.parent.config.settings.desktopmultiplex === true) || (domain.desktopmultiplex === true)) && (url.searchParams.get('p') == '2')) { routingOptions = { removeViewOnlyLimitation: true }; }
1007
1008 // Add server TLS cert hash
1009 var tlsCertHash = null;
pluginHandler.js
+2 -2
@@ -251,9 +251,9 @@ module.exports.pluginHandler = function (parent) {
251 return new Promise(function (resolve, reject) {
252 var http = (configUrl.indexOf('https://') >= 0) ? require('https') : require('http');
253 if (configUrl.indexOf('://') === -1) reject("Unable to fetch the config: Bad URL (" + configUrl + ")");
254 - var options = require('url').parse(configUrl);
254 + var options = new URL(configUrl);
255 if (typeof parent.config.settings.plugins.proxy == 'string' || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']) { // Proxy support
256 - options.agent = new (require('https-proxy-agent').HttpsProxyAgent)(require('url').parse(parent.config.settings.plugins.proxy) || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']);
256 + options.agent = new (require('https-proxy-agent').HttpsProxyAgent)(new URL(parent.config.settings.plugins.proxy) || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']);
257 }
258 http.get(options, function (res) {
259 var configStr = '';
webserver.js
+2 -2
@@ -2970,7 +2970,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
2970
2971 // If set and there is no user logged in, redirect the root page. Make sure not to redirect if /login is used
2972 if ((typeof domain.unknownuserrootredirect == 'string') && ((req.session == null) || (req.session.userid == null))) {
2973 - var q = require('url').parse(req.url, true);
2973 + var q = new URL(req.url, 'http://localhost');
2974 if (!q.pathname.endsWith('/login')) { res.redirect(domain.unknownuserrootredirect + getQueryPortion(req)); return; }
2975 }
2976
@@ -6439,7 +6439,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6439 obj.CheckWebServerOriginName = function (domain, req) {
6440 if (domain.allowedorigin === true) return true; // Ignore origin
6441 if (typeof req.headers.origin != 'string') return true; // No origin in the header, this is a desktop app
6442 - const originUrl = require('url').parse(req.headers.origin, true);
6442 + const originUrl = new URL(req.headers.origin);
6443 if (typeof originUrl.hostname != 'string') return false; // Origin hostname is not valid
6444 if (Array.isArray(domain.allowedorigin)) return (domain.allowedorigin.indexOf(originUrl.hostname) >= 0); // Check if this is an allowed origin from an explicit list
6445 if (obj.isTrustedCert(domain) === false) return true; // This server does not have a trusted certificate.