Java Security Programming

Source: Internet
Author: User

Java Security Program is actually a point a little defensive programming means inside, actually Java as a programming language, more c,c++, itself is considered relatively safe, with c,c++ such as the lower-level programming language than, Java less display pointer calls. The memory release on the program is missing. Recovery. These are all given to the JVM. Also, some tests have been made on memory allocations, such as the cross-examination of Arrayindexoutof. There are also null pointers to save NullPointerException, all of which makes Java use a lot simpler and avoids the possibility of a lot of insecurity on the language itself. But while Java is programmatically safe, it does not mean that program apes can write code arbitrarily.

A previous report from an organization showed that in recent thousands of vulnerabilities, 64% of the vulnerabilities were due to programs written. Program apes if they don't pay enough attention to their programming habits. Must be paid for.

This article I want to talk about is in security, there may be a few security vulnerabilities, here I say a lot of other is the language of the Java platform, but I believe that the same applies to any other language, security issues are common existence. The same.

1. Misplaced Trust. A software system can be divided into multiple subsystems, each subsystem has its own access module, so that each sub-module has its own trusted domain, but they themselves can not give themselves to the letter level, should be determined by the deployer of the program, so here we say. Divide the trusted domain of each module and ensure that each submodule is active in its own module. A good security design pattern should in fact be a combination of non-trust decoupling and permission separation.

2. Injection attacks, this is too common, usually said the most is the SQL injection attack. Some data can be malicious data when a component or system accepts an external data source. Assume that no validation is processed at this time. The injection attack will be imported. Here we advocate the practice is (1) verification. For example, the validation of various numerical values is within a given range of requirements (2). Purification, which refers to avoiding exposure to sensitive data. Ability to remove special characters, or transcode them.

(3). Finally, standardization and normalization. Converts the form of input into the simplest form. This is, in fact, a process of lossy loading and swapping.

Experienced the above process. Don't think you can do everything without worry. When a complex instruction string is accepted, a special character that exists in these strings, such as "Delete, insert," and other keywords that trigger the action, must also be processed. Otherwise, a security vulnerability can occur. Here are some ways to resolve this situation:

(1). command interpreter for operating system

(2). Detailed SQL-compatible interface database

(3). XML interpreter

(4). XPath evaluators

(5). Folder service based on Lightweight folder Access Protocol, commonly known as LDAP

(6). Scripting engine

(7). The Regular table-type (regex) compiler

Some of us have heard.

Some, indeed I have not heard.

3. Sensitive data leaks. Sensitive data refers to a very wide range, we often say that the user information, of course, is sensitive data, there are numbers. Account. Not to mention the various secret keys. So in the process of transmitting data, we generally reduce the transmission of sensitive data, but really need this data interaction, but also to filter processing, in the transmission to non-trusted components. Come to a demo diagram:


How does this work in Java, in Java. We are through the class. Interface, members implement access control.

Class and class members to give the lowest possible access.

The interface is also as open as possible to the method of agreeing to public access.

4. Performance leaks. First explain what performance is, performance refers to the identity of the authorization can communicate without forgetting. Every Java object has an identity that will not be forgotten. So what we can naturally relate to these objects is the fact that these objects are labeled, that is, performance. For references to objects that will run sensitive operations. They simply agree that the performance of their holders to run these operations is an object reference, so the reference itself must ensure that performance cannot be compromised to untrusted code.

5. Denial of service.

Commonly known as Dos attacks.

Now there is DDoS, distributed denial of attack. The reason for rejecting the attack is very easy, that is, some malicious programs occupy the system, resulting in the normal program is not resources, and eventually lead to system paralysis. Resources have been exhausted for no reason.

Some examples of Dos attacks are mentioned in the <<java Security Coding Specification >> book:

(1). Request a large vector image, such as an SVG file or font file

(2). " ZIP "bombs, those Zip,gzip compressed HTML files, will be extracted by the use of huge resources

(3). " XML parsing bombs. " When parsing an XML document. Assuming that there are so many nodes, there will be a lot of memory space to be quickly paid.

(4). Excessive use of disk space

(5). Multiple keys are inserted in a hash table. While these keys use the same hash code, this results in the worst performance O (N*n), not the average performance O (n)

(6). Initiates many connections, and the server allocates a large amount of resources such as flooding attacks for each connection.


6. Principle of least privilege.

This is reflected in some of the methods mentioned above. The Java flexible security model gives the application a lot of other permissions, which can be done by defining the security policy yourself. Privileged operations should only be provided to the least privileged code. Java's accesscontroller mechanism agrees that only the required code can get permission to ascend. When a class needs to change his permissions. The ability to invoke the Dopriviliged () method of Accesscontroller to gain temporary privileges, but to avoid a security vulnerability by appearing as little as possible with the dopriviliged () method.

7. Security Manager. Here's what the security manager says. Refers to the SecurityManager in Java. When using the Java API, the system will report a SecurityException error when running a security policy violation.

When we use Java to code, we use the system's default SecurityManager, when our team's security requirements are higher. We inspire many others to implement a security manager of our own definition, and in code we often think of using acsesscontroller to help us limit or get some privileged code.

The above is my view of Java security programming, finally still have to look at the individual, said more. If you don't do it, it's useless, or hopefully there are a lot of other program apes that can be added to the security programming team to improve their coding level.

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Java Security Programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.