Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

Quote every value in generated shell scripts

Shell scripts built from template strings need every interpolated value quoted, and quoting has a cost: "~/x" stops meaning your home folder. Decide per variable, and test with a space and a tilde.

01 · Before and afterThe pattern

TypeScript
// before: word-splits on spaces, glob-expands, runs whatever the string becomes
const script = `chmod +x ${file} && ${file}`;

// after: quote each value as one shell word; expand ~ yourself before quoting
const q = (s: string) => `'${s.replace(/'/g, `'\\''`)}'`;
const path = file.startsWith('~/') ? `"$HOME"/${q(file.slice(2))}` : q(file);
const script = `chmod +x ${path} && ${path}`;

02 · Run it on your appThe check

If a user's path contains a space, does every shell command your app generates still work?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.