Menu

argv lists killed shell injection in my code. Then ls -l showed me the other half.
📰

argv lists killed shell injection in my code. Then ls -l showed me the other half.

DEV Community: cybersecurity·Aurum Revenue·11 days ago
#P7BExabV
#devtocybersecurity#devto#dev#shell#value
Long article (662 words) — no AI summary yet.
Reading 0:00
15s threshold

For months I've been telling people the same thing: stop building shell strings, pass a list.

subprocess.run(["echo", user_text]) with the default shell=False keeps parentheses, backticks and $(...) as plain characters. That is CWE-78, and an argv list really does close it. I even shipped a small library, shellguard, that refuses shell=True and bare-string commands so nobody on my team can slip back into the old habit.

Then a reviewer asked me a fair question: "What if the user's text is a flag?"

I had a good answer in theory and no demo. So I made one.

The demo that changed my answer

I created two files in a temp directory: one literally named -l , one named normal.txt . Then I called ls with the untrusted value as its only argument:

subprocess .…

Continue reading — create a free account

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