Add defensive auth guards and cleanup iteration usage

This commit is contained in:
Cosimo Ricciardi 2026-05-14 11:39:11 +02:00 committed by Suheb
parent 40bd25d921
commit bd0f515a6e
4 changed files with 52 additions and 46 deletions

View file

@ -201,17 +201,19 @@ export const updateNodeSettings = (req, res, next) => {
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.settings) {
node.settings = { ...node.settings, ...req.body.settings };
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete node.authentication.swapMacaroonPath;
if (node.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete node.authentication.swapMacaroonPath;
}
}
}
try {
@ -219,17 +221,19 @@ export const updateNodeSettings = (req, res, next) => {
const selectedNode = common.findNode(req.session.selectedNode.index);
if (selectedNode && selectedNode.settings) {
selectedNode.settings = { ...selectedNode.settings, ...req.body.settings };
if (req.body.authentication.boltzMacaroonPath) {
selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete selectedNode.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete selectedNode.authentication.swapMacaroonPath;
if (selectedNode.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete selectedNode.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete selectedNode.authentication.swapMacaroonPath;
}
}
common.replaceNode(req, selectedNode);
}

View file

@ -55,7 +55,7 @@ export class CommonService {
delete config.multiPass;
delete config.multiPassHashed;
delete config.secret2FA;
config.nodes?.map((node) => this.removeAuthSecureData(node));
config.nodes?.forEach((node) => this.removeAuthSecureData(node));
return config;
};
this.addSecureData = (config) => {
@ -70,7 +70,7 @@ export class CommonService {
config.secret2FA = this.appConfig.secret2FA;
}
const appConfigNodes = new Map(this.appConfig.nodes?.map((node) => [node.index, node]));
config.nodes.map((node) => {
config.nodes.forEach((node) => {
const appConfigNode = appConfigNodes.get(node.index);
if (appConfigNode?.authentication) {
if (appConfigNode.authentication.macaroonPath) {
@ -83,7 +83,6 @@ export class CommonService {
node.authentication.lnApiPassword = appConfigNode.authentication.lnApiPassword;
}
}
return node;
});
return config;
};