Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security impact of access modifiers (public, private, internal, protected)

Do the access modifiers of classes, properties or methods in C#, Java and other programming languages actually have an impact on the security of an application? Do they also protect against unauthorized access in some way? Or are they just a tool for clear and propper programming?

like image 929
Claudio P Avatar asked Jul 08 '15 11:07

Claudio P


2 Answers

No, access modifiers don't offer security protection. They are merely there for developer convenience, e.g. they help to enforce good coding practices and help with programming patterns.

It's easy to access otherwise inaccessible modifiers by using reflection in Java/C# and other languages.

like image 81
oleksii Avatar answered Sep 19 '22 04:09

oleksii


The main purpose of the access modifiers is to enforce a specific design, not any kind of security.

like image 44
Jan Avatar answered Sep 23 '22 04:09

Jan