Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Escaping Problem of Passwords on Import #2165

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions launcher/src/backend/ValidatorAccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export class ValidatorAccountManager {
}
return readFileSync(file.path, { encoding: "utf8" });
});

//escape all passwords for shell
passwords = passwords.map((p) => {
let pass = p;
if (pass.includes('"')) pass = pass.replaceAll(/"/g, '\\"');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use a library to escape all potential special characters rather than manually escaping only some of them? For example: require('shell-escape')

Copy link
Member Author

@NeoPlays NeoPlays Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're escaped by JSON.stringify. The main problem are the double and single quotes. And because JSON.stringify already does escaping i need to remove the extra \ introduced with '\'', which i use to escape single quotes because all other variants i tried didn't work. This means that some library wont help either. This was all more complex then i thought tbh 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i think there is another problem when the password includes \...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so everthing should be fixed now 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍🚀

if (pass.includes("'")) pass = pass.replaceAll(/'/g, `'\\''`);
return pass;
});
for (let i = 0; i < content.length; i += chunkSize) {
const contentChunk = content.slice(i, i + chunkSize);
const passwordChunk = passwords.slice(i, i + chunkSize);
Expand Down Expand Up @@ -315,7 +321,7 @@ export class ValidatorAccountManager {
apiToken ? `-H 'Authorization: Bearer ${apiToken}'` : "",
`-s`,
];
if (data) command.push(`-d '${JSON.stringify(data)}'`);
if (data) command.push(`-d '${JSON.stringify(data).replaceAll(/\\\\/g, "\\")}'`);
command = command.concat(args);
return await this.nodeConnection.sshService.exec(command.join(" "));
}
Expand Down
Loading