CSharpCodeProvider - Is this abuse?

I apologize for the short duration of the question, but I do not think that it needs a lot of development.

Are there any security implications caused by using CSharpCodeProvider and can it open the server for attack?

+7
security c # asp.net-mvc-2
source share
3 answers

It depends on how you use it. Here is a summary sorted from safe use to use that you, of course, do not want to allow (when you run the code on the server or in any environment that you want to control):

  • If you use CSharpCodeProvider only to generate C # source code, you only need permission to save the generated files to any directory or note at all (if you can get the code generated into the memory stream)

  • If you use it to compile the generated C # source, you need permission to run csc.exe (which may not be available in some limited environments, such as shared hosts).

  • If you just generate files and compile them, then this probably will not be harmful (although someone might abuse your application to generate many, many files and attack the server using some kind of DOS attack.

  • If you also download and execute the generated code, it depends on how you create it. If you assume that there are no errors in C # / CodeDOM, and you can guarantee that the generated code is safe, then you should be fine.

  • If your code contains things like CodeSnippetExpression that can be provided by the user (somehow) than the user can write and run whatever he wants on his server, so this is potentially dangerous.

+5
source share

Grade. At first glance, this is not a direct risk, because you are not using code, just compiling it. However, there is nothing to suggest that the C # compiler does not contain any error that, given the correct malicious input, will cause it to escape and start executing commands directly.

However, if you later run the compiled code (and, presumably, you will do it - otherwise, why would you compile it for a start?), It will work in the same context as you. Obviously, this has all sorts of unpleasant security implications, similar to using the quasi-similar function eval() for other languages.

+2
source share

It depends on the source you are compiling. If you have enough control over the source, this may be an acceptable risk. If you allow the compiler to someone outside your scope of supply of the trust code, this may be an unacceptable risk.

+1
source share

All Articles