mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
request has been deprecated since 2020 with an unfixed SSRF advisory and pins vulnerable copies of form-data (critical), qs, tough-cookie and uuid - 8 of the 13 remaining production audit findings, none fixable by version bumps (issue #1634, item 1). All 36 backend files that imported request-promise now use a small compatibility wrapper (server/utils/request.ts) backed by axios, which is already a production dependency. The wrapper accepts the existing options shape (qs, form - object or pre-encoded string, body, baseUrl/uri, rejectUnauthorized, json), resolves with the response body directly, and rejects with a plain object mirroring request-promise's StatusCodeError/RequestError shape, so CommonService.handleError works unchanged (ECONNREFUSED -> 503, Eclair StatusCodeError -> 500, nested error body extraction). Auth headers are excluded from rejected errors so they cannot leak into logs. Callers without json: true (block explorer, currency rates) still get raw text bodies, and LND's line-delimited /v2/router/send stream still surfaces as a string for the existing parser. Only behavioral code change: CLN verifyMessage used request-promise's callback style and was ported to the same promise style as signMessage; four Eclair handlers gained explicit returns to satisfy noImplicitReturns once the import became typed. Production npm audit drops from 13 findings (2 critical) to 6 low, all in the crypto-browserify/elliptic chain tracked in #1634. Verified against the docker regtest fixture with 43 API checks across LND, Core Lightning and Eclair: reads, invoice creation, a routed LND payment over the streaming endpoint, cross-implementation payments from CLN and Eclair, message sign/verify, channel backup to disk, and bad-invoice/node-unreachable error mapping. Lint and both production builds are clean.
109 lines
6.2 KiB
JavaScript
109 lines
6.2 KiB
JavaScript
import request from '../../utils/request.js';
|
|
import { Logger } from '../../utils/logger.js';
|
|
import { Common } from '../../utils/common.js';
|
|
let options = null;
|
|
const logger = Logger;
|
|
const common = Common;
|
|
export const getAliasForPeers = (selNode, peer) => {
|
|
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + peer.pub_key;
|
|
return request(options).then((aliasBody) => {
|
|
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Peers', msg: 'Alias Received', data: aliasBody.node.alias });
|
|
peer.alias = aliasBody.node.alias;
|
|
return aliasBody.node.alias;
|
|
}).catch((err) => {
|
|
peer.alias = peer.pub_key.slice(0, 20);
|
|
return peer.pub_key;
|
|
});
|
|
};
|
|
export const getPeers = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Getting Peers..' });
|
|
options = common.getOptions(req);
|
|
if (options.error) {
|
|
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
|
}
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
|
request(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
|
const peers = !body.peers ? [] : body.peers;
|
|
// Bound concurrent alias lookups so a node with many peers can't fire one graph/node
|
|
// request per peer at once and overwhelm the backend (parity with the CLN fix, #1501).
|
|
const getPeerAliasesTasks = peers.map((peer) => () => getAliasForPeers(req.session.selectedNode, peer));
|
|
common.runWithConcurrencyLimit(getPeerAliasesTasks, 20, () => {
|
|
// Guard the response-send: the limiter invokes this outside the surrounding .catch.
|
|
try {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Sorted Peers List Received', data: body.peers });
|
|
res.status(200).json(body.peers);
|
|
}
|
|
catch (e) {
|
|
const err = common.handleError(e, 'Peers', 'List Peers Error', req.session.selectedNode);
|
|
if (!res.headersSent) {
|
|
res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
}
|
|
}
|
|
});
|
|
}).catch((errRes) => {
|
|
const err = common.handleError(errRes, 'Peers', 'List Peers Error', req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
});
|
|
};
|
|
export const postPeer = (req, res, next) => {
|
|
const { host, pubkey, perm } = req.body;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Connecting Peer..' });
|
|
options = common.getOptions(req);
|
|
if (options.error) {
|
|
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
|
}
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
|
options.form = JSON.stringify({
|
|
addr: { host: host, pubkey: pubkey },
|
|
perm: perm
|
|
});
|
|
request.post(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: body });
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
|
request(options).then((body) => {
|
|
const peers = (!body.peers) ? [] : body.peers;
|
|
// Bound concurrent alias lookups (parity with the CLN fix, #1501).
|
|
const getPeerAliasesTasks = peers.map((peer) => () => getAliasForPeers(req.session.selectedNode, peer));
|
|
common.runWithConcurrencyLimit(getPeerAliasesTasks, 20, () => {
|
|
// Guard the response-send: the limiter invokes this outside the surrounding .catch, and
|
|
// this replaced an explicit inner .catch — a throw here must not hang the POST (#1629 F4).
|
|
try {
|
|
if (body.peers) {
|
|
body.peers = common.newestOnTop(body.peers, 'pub_key', pubkey);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peers List after Connect Received', data: body });
|
|
}
|
|
res.status(201).json(body.peers);
|
|
}
|
|
catch (e) {
|
|
const err = common.handleError(e, 'Peers', 'Connect Peer Error', req.session.selectedNode);
|
|
if (!res.headersSent) {
|
|
res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
}
|
|
}
|
|
});
|
|
}).catch((errRes) => {
|
|
const err = common.handleError(errRes, 'Peers', 'Connect Peer Error', req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
});
|
|
}).catch((errRes) => {
|
|
const err = common.handleError(errRes, 'Peers', 'Connect Peer Error', req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
});
|
|
};
|
|
export const deletePeer = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconnecting Peer..' });
|
|
options = common.getOptions(req);
|
|
if (options.error) {
|
|
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
|
}
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers/' + req.params.peerPubKey;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnect Pubkey', data: req.params.peerPubKey });
|
|
request.delete(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconneted', data: body });
|
|
res.status(204).json({});
|
|
}).catch((errRes) => {
|
|
const err = common.handleError(errRes, 'Peers', 'Disconnect Peer Error', req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
});
|
|
};
|