[SOLVED] How would we run commands in the console?

I want to run some commands in the console remotely from Discord using a command.
(Suppose that the command filters out dangerous executions such as rm -rf / --no-preserve-root)
How would I execute the command in the console?
If I type refresh how could make it run in the console?
I am thinking about child_process package’s .exec() but am not too sure!

Hi @XenoCraftMC you’re on exactly the right track; using Node’s child_process.exec() is the right way to go.

Obviously as you noted you’ll want to avoid allowing arbitrary commands, since the can be destructive to your project’s container and make your project non-runnable. In a case like this it’s almost always better to approach the problem with a whitelisting philosophy (choose a few commands that you know to be safe) rather than blacklisting (filtering out dangerous commands) because there will always be someone out there who knows more than you (or at least that knows more than me!) and if they’re malicious they can find their way around whatever filters you put in.

Happy Glitching!

1 Like