Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any coding security issues specific to C#?

Tags:

c#

.net

security

In C++ world there is a variety of ways to make an exploitable vulnerability: buffer overflow, unsafe sting handling, various arithmetic tricks, printf issues, strings not ending with '\0' and many more. Despite most of these problems were solved in java, there are some things to talk about. But is there any list of typical C#-specific coding vulnerabilities? (and not related to .NET platform itself)

like image 733
Secure Avatar asked Mar 03 '10 18:03

Secure


2 Answers

Here are a few issues you can run into:

  1. If you've got any sort of language interpreter (HTML, JavaScript, and SQL being the big three) then you can still have injection or XSS vulnerabilities.
  2. P/Invoke can cause problems, especially if you're doing any custom marshalling. Even if you're calling a "safe" API through P/Invoke, your marshalling code could contain a bug that corrupts or exposes memory.
  3. If you're doing file access then you need to make sure your files are always in acceptable directories. Be sure to sanitize against bad absolute and relative paths.
  4. Cryptography. Good cryptographic programming is really hard, and .Net's various safety features do nothing against crypto attacks.
like image 121
Kennet Belenky Avatar answered Sep 27 '22 23:09

Kennet Belenky


C# is based on .NET and .NET is supposed to be type-safe, which means none of your list of horrors applies to C# or any .NET language.

But then again, C# has an unsafe keyword and after that all bets are off.
It allows real pointers and everything that comes with them.

like image 34
Henk Holterman Avatar answered Sep 27 '22 21:09

Henk Holterman