The Owasp top 10 webapp vulnerability list is due to update soon; I wager its top three won’t change from the 2013 list:
- Injection [mainly sql injection]
- Broken Authentication and Session Management
- Cross-Site Scripting (XSS)
What do two of the top three vulnerabilities have in common? Cross-site scripting is a form of injection attack that is so popular it deserves its own category; both cross-site scripting and “injection” often result from unsafe string concatenation:
"select name from students where " + ... html = "<div>" + ...
I bet one simple rule would stop most webapp compromises:
Avoid string concatenation.
Production code should very rarely concatenate strings; when it must be done, it should be written to make it obvious that the concatenation is safe.
Assuming most programmers do not intend to write vulnerable code, it is safe to say that they consider the vulnerable code they are writing to be obviously safe. That is just a special case of “programmers don’t think about the bugs they are writing.” By extension, they don’t think about the vulnerabilities they are writing.
So, I dislike rigid coding standards, but if I were to implement one, it would be to say that any place string concatenation is used must be accompanied by comments to answer:
- Where is the data coming from?
- What could happen if a malicious actor provided the data?
- What makes this safe?
If you have so much string concatenation in your webapp that this seems onerous, I guarantee your site is full of security holes.
One thought on “Beware string concatenation”