Information Security Stack Exchange is a question and answer site for information security professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Based on this discussion, closures in C# promote private variables to public variables at compile time.

Suppose a closure was implemented on a Username or Password string. Would there be any security issue with this at run time? Is this an issue in any other language?

If so, is there any way I can prevent this (via attributes)?

share|improve this question
up vote 5 down vote accepted

Despite the visibility promotion, Closures do not present any new security issue.

This is because of the simple reason, that visibility (i.e. private/public) is not a security mechanism in the first place.
Just because you marked your password field as private, doesnt mean it is not accessible. It's not accessible, but only to code that behaves nicely.
It's still accessible easily in code, e.g. via reflection. (Of course, consumers of your class shouldn't do that...)

And that's even without going into things like debugging, memory inspection, etc...

So - as I said, it doesnt affect the level of security. You'd need to protect that Password field, but you'd need to do that anyway.
(Suggestion: store passwords as SecureString instead of strings... )

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.