.net - Why Java is secure compared with other programming languages? - Stack Overflow
windows - Would services or whole operating systems written in pure Python/Java be safer? - Information Security Stack Exchange
java or python?
Which language is best for cyber security?
Videos
There are many reasons why Java is a safe language, and it's definitely safer than some languages, but I think it's a stretch to say that it's safer than all other languages.
Java has a variety of safety features in place:
Automatic null-checking of references, bounds-checking of arrays, verification of casts, etc. to prevent the program from making type errors. Compare this to C or C++, where these same errors (with a few exceptions) cause undefined behavior.
Verification of bytecode prior to execution. This makes it impossible for the program to jump to an undefined instruction, or to try to perform an operation on a nonexistent object, or to make a type error at the instruction level, etc. Compare this to C or assembly, where the program can jump to bad instructions, or try reading nonexistent parameters to functions (think
va_args), etc.)Runtime security checks when loading in new code. The use of
SecurityManagerandClassLoadermake it easy for the Java runtime to prevent arbitrary code from executing on the computer by mediating access to system resources and preventing the program from loading or generating arbitrary code at runtime. Compare this to C or C++, which can read and write arbitrary values, issue arbitrary system calls, generate and execute arbitrary code, etc.Library-level safety of certain features. For example,
Stringis immutable andfinal, so a function that receives aStringcan verify the string and not have to worry about another thread changing its value.
This isn't a complete list of Java's safety features, but it should give you a sense of some of the design considerations in Java that are not present in other languages.
Hope this helps!
You mention you read some where but can you please re-read it because I guess when it was written the author would be comparing the JAVA with C++ / Fortran / C etc.
Also there is an old post you can read about the testability of security in http://www.veracode.com/blog/2010/06/which-tastes-better-for-security-java-or-net/
you can see both are same almost....
Well, unsure for Java, but the standard Python implementation is called C-Python and is written in C language. So (if it was even possible) an OS written in Python would ultimately be built using C.
Moreover, when we think of programming languages, most are targetted at writing applications, not OS and programmers rely on the language implementation to interact with the system. The 2 major exception that I can think of are:
- the assembly languages: they allow to write directly machine instructions and can easily access the hardware - simply you must rewrite everything if you use a processor having a different instruction set ...
- the C language that can easily and with no external library access memory mapped hardware registers, and (provided you use it in real mode) can access the full system memory - C++ can also be used at same level. It was invented by Kernighan and Ritchie to build the first Unix OS, and first C versions really looked closer to a macro assembly language, than to a high level language.
On the other side, Java and Python are not intended to access memory at physical well known addresses and programmers use system libraries (often written in C) to interact with the OS.
Finally the C language has a poor reputation, because it often bites beginners or non cautious programmers because a program with no error or warning can still contains a lot serious mistakes and its power of accessing any memory address allow to easily use wrong ones. And writing a correct and feature rich program is usually much longer in C than in Python or Java.
What follow is just my opinion, only guided by ~40 years of programming in different languages: what makes the security of a program is not its language but the proficiency of the programmer and above all the respect of best practices. Among which:
- tests written against expected and pathological use cases (the program must behave sanely when given correct input, and just protect itself and the system when given garbage)
- extensive peer review - a fellow will point suspect code that you have written a bit too quickly because you were focusing on another point, much better than you would do
- use well established patterns (those will depend on the used language and frameworks) instead of re-inventing oval wheels
- only write code easy to read and understand, and add comments for the rationale and principes for low level optimizations
This indeed adds a noticeable overhead. But robust code comes at a price. And this is indeed a real reason to use Java or Python when C is not required, because you will use less lines of code, and they will be easier to read for peer reviewers. So a robust application program written is Python or Java will be cheaper than the same in C. But I really think that trying to use Java or Python for the low level OS parts is just non sense.
Using Java or Python instead of C or C++ does indeed (almost) completely remove the risk of buffer overflows and similar. That does not automatically make such services safe or even safer - there are whole classes of vulnerabilities (check out OWASP top 10) completely unrelated to memory safety.
So would writing an OS in Python of Java be a good idea? It's not obvious how that would even work. The OS must perform direct memory management, and you can't really do that in such a high level language. Besides, there would be performance issues. A much more viable approach would be to write your OS in a low level language that is memory safe, like Rust.
But at the end of the day, if you hire a lazy web developer like me, I'll just concatenate untrusted data straight into SQL queries anyways. And all the memory safety in the world is not going to help against that.
is there a good reason to have java as your first language over languages like python or js?