Filter disallowed node conf from user

This commit is contained in:
Michele Marcucci 2024-04-15 17:37:21 +02:00
parent 3c632e5547
commit a90a60a9eb

View File

@ -168,15 +168,17 @@ module.exports.auth = {
} }
if (settings.nodeUserConf) { if (settings.nodeUserConf) {
// Split settings.nodeUserConf and defaultConf into arrays of lines // Extract variable names from settings.nodeUserConf using regex
const userConfLines = settings.nodeUserConf.split('\n'); const userConfVariables = settings.nodeUserConf.match(/^[^=\r\n]+/gm);
const defaultConfLines = defaultConf.split('\n');
// Exclude lines from settings.nodeUserConf that are also present in defaultConf // Extract variable names from defaultConf using regex
const filteredUserConfLines = userConfLines.filter(line => !defaultConfLines.includes(line)); const defaultConfVariables = defaultConf.match(/^[^=\r\n]+/gm);
// Join the remaining lines back into a single string // Remove variables from settings.nodeUserConf that are also present in defaultConf
const filteredUserConf = filteredUserConfLines.join('\n'); const filteredUserConfVariables = userConfVariables.filter(variable => !defaultConfVariables.includes(variable));
// Join the remaining variables back into a single string
const filteredUserConf = filteredUserConfVariables.join('\n');
// Append the filtered user configuration to the overall configuration // Append the filtered user configuration to the overall configuration
conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`;