2 ms·
However sometimes there are no good, safe APIs commonly available. Number 5 "OS Command Injection" and Number 8 "Path Traversal" fall in that category. Both are
by wongarsu 5y ago
However sometimes there are no good, safe APIs commonly available. Number 5 "OS Command Injection" and Number 8 "Path Traversal" fall in that category. Both are exercises in proper quoting (and in the case of Path Traversal also catching ways to leave the intended base directory). If sane OS APIs for these cases exist at all they are platform-specific, so most languages go with the unsecure platform-agnostic way and provide only rudimentary wrappers that don't solve these problems either.
- alanfranz 5y agoYou're right that some APIs just suck. But it's important to recognize that the problem exists. If you notice that you can't perform an action safely, and there's an injection risk, you can usually try and find a safe way that doesn't involve an error-prone approach. Example for the path traversal: generate a filename within the app, and save the original name somewhere. For command injection, it is more variegated. But resorting to launching an external command (rather than an API in the language you're using) should be a niche requirement, not the standard way to go.