Most Dangerous Software Weaknesses
cwe.mitre.org
cwe.mitre.org
Most of the times (let's exclude embedded/iot which can be different, I'm talking about "classical" web applications or API backends) you don't need to validate arbitrary data. You need to use the proper API to handle such data.
If an input string contains '); DROP TABLE Students; -- you don't need to "sanitize" the string. You just need to use the proper function (usually provided by your db driver), and it will quote it for you. There's no input that can create a SQL injection.
Similarly, when you output something for the web, always use a context-aware templating engine (e.g. Thymeleaf) so that the appropriate escaping function is used when rendering an HTML element, javascript, an attribute, whatever. XSS is impossible, unless "unsafe" functions (those that dump the raw string into the text) are used.
For sure, if any "active" content (not just an opaque string that needs to be rendered back somehow) is passed to the application (e.g. a direct reference to an object which may require an ACL to be visualized), then you need to "validate" the input. But it is very important to understand the difference between "validate something which is strictly related to your application logic" and "use the appropriate data manipulation functions for arbitrary data".
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.
I wonder if this shows we can get outsized impact by focusing on just a couple of types of issues, or if it is an artifact of how the data is collected (e.g. out-of-bounds write is easy to find by fuzzing but severe enough to always warrant a CVE)
I know Content Security Policy can help mitigate XSS, but I wonder if there are any existing tools to help you discover what kind of rules your website would need currently to even function as intended?
If you write new software these C-isms seem easy to avoid, especially with Rust as another compelling option. But I doubt that makes a big dent on the statistics in the next decade.