Menu

🐚 Command Injection: Stop Building Shell Strings (Python and Node)
πŸ“°

🐚 Command Injection: Stop Building Shell Strings (Python and Node)

DEV Community: appsecΒ·Krishna KumarΒ·about 8 hours ago
#TBw3cu2N
#devtoappsec#devto#dev#shell#command
Long article (2805 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Most command injection bugs come from the same line of code: a string that mixes a program name, some flags, and a value from a user, handed to a shell. The shell reads the whole string, and anything in it that looks like syntax is syntax.

This article shows what that looks like in Python and Node, the two-layer fix (no shell, plus validation), the argument-injection gap that "no shell" alone leaves open, and how to prove the fix with a harmless marker instead of trusting a linter. I ran every snippet below locally, on stand-in data.

Only test applications you own or are authorized to test. The "target" here is a tiny script I wrote that pretends to be a legacy stock-report tool, and the only thing I inject is an echo .

What it is

OS command injection (also called shell injection) means user input ends up in a command your server runs, and it can change what that command does. It is CWE-78 .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.