Java Application Vulnerabilities:: What They Are and How To Fix Them
Java Application Vulnerabilities:: What They Are and How To Fix Them
CONTENTS
öö TOP JAVA VULNERABILITIES
öö TOP 3 WINNERS
öö
Java Application
OWASP TOP 10 VULNERABILITIES
öö APPLICATION
MISCONFIGURATION: EXPOSED
SERVELET
Vulnerabilities: öö APPLICATION
MISCONFIGURATION: EXCESSIVE
PERMISSIONS
Half of all enterprise applications written in the last 15 years This Refcard is intended to help Java developers understand the
DZO N E .CO M/ RE FCA RDZ
have been written in Java, making them nearly ubiquitous in the most common Java vulnerabilities and how to fix them early in
enterprise. Unfortunately, this means that Java applications are also the development process.
among the applications hackers most frequently target and attack.
TOP JAVA VULNERABILITIES
Java can be subject to attack based on general vulnerability types,
Below are the most common, prevalent, and significant Java
but there are also some vulnerabilities that are specific to the
vulnerabilities. This list is compiled from the vulnerabilities
Java platform.
found in Java applications as reported in the WhiteHat Security
Application Security Statistics Report for 2017. For each
• Vulnerabilities in standard libraries
vulnerability type, you will find a description of how and where it
• Vulnerabilities introduced by coding errors (e.g., improper occurs, examples of how to fix it, and other general information
construction of a query) about the vulnerability.
1
Stop hiding from
your security officer.
#CoverYourApps with IBM Security’s leading application security solution.
Introduce a strong, security-first mindset into your DevOps culture, without disrupting
agile practices that your organization relies on to produce quality, on-time software.
Start your free trial today!
IBM Application Security on Cloud enhances web and mobile application security, improves application
security program management and strengthens regulatory compliance. Testing web and mobile applications
prior to deployment helps you identify security risks, generate reports and receive fix recommendations.
©
Copyright IBM Corporation 2018. IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide.
Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at “Copyright and trademark
information” at ibm.com/legal/copytrades.html.
JAVA APPLICATION VULNERABILITIES
during development to reduce exposure in production. production, while others like SQLi must
always be remediated in development.
VULNERABILITY RISK RATINGS
A variety of software security testing
Vulnerabilities are rated on five levels of risk – Critical, High,
regimens routinely performed across
Medium, Low, and Note. Critical and high risk vulnerabilities
the SDLC is the best application security
taken together are referred to as “serious” vulnerabilities. There
approach. Platform solutions provide
are three classes of vulnerabilities found to be critical across
this level of visibility and control, leaving
thousands of applications analyzed in development: Insufficient
organizations with enough intelligence to
Transport Layer Protection (ITLP), SQL Injection (SQLi) and
understand how best to fix any software
Unpatched Libraries.
error… for the least cost.
throughout the organization. It is best to have a single solution servlets is the only secure option.
rather than several solutions to the same problem. To further
ADDITIONAL RESOURCES
improve consistency and security assurance, version and patch
axis.apache.org/axis/java/security.html
levels should remain consistent throughout the organization.
APPLICATION MISCONFIGURATION:
• Dependency Management tools (e.g. Maven) EXCESSIVE PERMISSIONS
Low Risk: OWASP A5: Stat Report Rank 2
• WhiteHat Sentinel Source provides information on libraries
and frameworks for covered assets. DESCRIPTION
An application may use custom permissions that can then allow
ADDITIONAL RESOURCES
a separate application to access hardware level functionality
maven.apache.org/guides/introduction/introduction- through its API. These separate applications can bypass the
todependency-mechanism.html#Dependency_Management normal prompting procedures for use of sensitive functionalityby
using the API.
OWASP TOP 10 VULNERABILITIES
SOLUTION
A1 Injection
Applications should only request the minimum permissions
A2 Broken Authentication and Session Management (XSS) needed for stated application functionality. Do not request any
unnecessary permissions. Any unused permissions should not be
A3 Cross Site Scripting (XSS)
requested. Future application updates should prompt the user to
A4 Insecure Direct Object References revoke unneeded permissions.
A5 Security Misconfiguration
APPLICATION MISCONFIGURATION: GLOBAL
A6 Sensitive Data Exposure ERROR HANDLING DISABLED
Medium Risk: OWASP A5: Stat Report Rank 2
A7 Missing Function Level Access Control
DESCRIPTION
A8 Cross Site Request Forgery (CSRF)
Disabling a global error handling mechanism increases the risk
that verbose implementation details will be revealed to attackers application much easier to audit, since it eliminates the need
through a stack trace. to perform time consuming (and expensive) data flow analysis.
It is important to note that there are different output contexts
SOLUTION
which encoding functionality must handle, including HTML, HTML
To minimize the risk of disclosing sensitive implementation
attributes, URLs, CSS, and JavaScript. A single encoding approach
details through error messages, ensure the application
will not necessarily mitigate XSS in every context.
deployment descriptor declares an error-page declaration that
catches all uncaught exceptions thrown by the application. If output encoding isn’t practicable, the next most effective
approach is to carefully filter all input data against a white-list of
EXAMPLES
allowed characters. This approach does have the advantage that
The web.xml should define error handling elements such as:
it can be performed externally without modifying application
<error-page> source code. Data retrieved from third-parties or shared with
<error-code>500</error-code>
<location>/path/to/default_500.jsp</location>
other applications should be filtered along with user input
</error-page> data. The white-list should only include characters which may
<error-page> be a legitimate part of user input. The following characters
<exception-type>java.io.IOException</exception-type>
are especially useful for conducting XSS attacks and should
<location>/path/to/default_exception_handler.jsp</
location> be considered in any encoding or filtering scheme: < > “ ‘ ; & ?
</error-page> One or more of these characters, such as the single quote, may
be required by the application. If it is impracticable to remove
CROSS-SITE SCRIPTING (“XSS”) one or more dangerous characters as part of an input filtering
High Risk: OWASP A3: Stat Report Rank 3
scheme, they must be carefully handled. Such characters could,
for example, be encoded on input, and stored encoded in the
DESCRIPTION
database. Ideally, the application should perform careful input
DZO N E .CO M/ RE FCA RDZ
An attacker can use XSS to send malicious script or other content DESCRIPTION
to an unsuspecting user. Neither the end user nor their browser Insufficient randomness results when software generates
knows that the content was not actually generated by the trusted predictable values when unpredictability is required. When a
website. The malicious script can access any cookies, session security mechanism relies on random, unpredictable values to
tokens, or other sensitive information retained by the browser restrict access to a sensitive resource, such as an initialization
and used by the site. These scripts can even rewrite the content of vector (IV), a seed for generating a cryptographic key, or a
the HTML page. This can result in phishing attacks, identity theft, session ID, then use of insufficiently random numbers may allow
website defacement, denial-of-service, and other attacks. an attacker to access the resource by guessing the value. The
potential consequences of using insufficiently random numbers
SOLUTION
are data theft or modification, account or system compromise,
The most reliable means of thwarting most types of XSS attacks
and loss of accountability – i.e., non-repudation.
is to HTML-encode or URL-encode all output data, regardless of
the data’s source. This ensures that tainted data can’t affect the SOLUTION
output from any source, including user input and information When using random numbers in a security context, use
shared with other applications or originating from third-party cryptographically secure pseudo-random number generators
sources. Consistently encoding all output data also makes the (CSPRNG).
EXAMPLES Java application, and this varies depending on the container. Here
is one example of debug_mode disabled for the jsp servlet:
byte[] randomBytes = new byte[8];
SecureRandom random = new SecureRandom();
<servlet>
random.nextBytes(randomBytes);
<servlet-name>jsp</servlet-name>
<servlet-class>oracle.jsp.runtimev2.JspServlet</servletclass>
observed to bypass authentication or assign administratorlevel code or compiled binaries can extract the credentials in an
permissions for testing purposes. attempt to access the corresponding services. Obscuring
passwords using encoding, such as Base-64, is not sufficient.
SOLUTION Storing passwords in cleartext (e.g. in an application’s properties
Debug mode should be disabled in production. In addition to any
or configuration file) can result in account or system compromise.
debug mode provided by the programming language, developers
This exposes the password to any personnel with access to the
may implement their own custom debug mode. Custom debug
application’s configuration files – developers, architects, testers,
options should be stored in application configuration files rather
auditors, and development managers. Because it is possible that
than source code, but it may be necessary to search the code base
others may have access to a user’s password, the owner of an
to verify there are no hidden debug options.
account can no longer be presumed to be the only person able to
Production code should normally not be capable of entering login to the account.
Frameworks and components used by the application may have application can then read the key (from a known static location),
their own debug options as well. It is important that debug read the encrypted credentials, decode, and use them. The
options are disabled throughout the application before the encryption key should be rotated on a 30- to 90-day basis. User
EXAMPLES read data from a socket or file; however, readLine() reads data
There are many approaches and libraries available for encrypting/ until it encounters a newline or carriage return character in the
ecrypting data in Java. Many common approaches are less than data. If neither of these characters are found, readLine() will
secure. Java developers often encode system passwords in continue reading data indefinitely. If an attacker has any control
Base-64 or encrypt them with DES - neither approach is secure, over the source being read, he or she can inject data that does not
especially encoding. have these characters and cause a denial of service on the system.
Even if the number of lines to be read is limited, an attacker
The following code can be used to encrypt/decrypt using a secure
can supply a large file with no newline characters and cause an
algorithm, AES:
OutOfMemoryError exception.
EXAMPLES
getParameters());
OWASP ESAPI’s safeReadLine() can be used to safely read
byte[] encrypted = cipher.doFinal(value.getBytes());
return byteArrayToHexString(encrypted);
untrusted data as follows.
}
ByteArrayInputStream s = new
ByteArrayInputStream(“testinput”.getBytes());
INJECTION: UNKNOWN INTERPRETER IValidator instance = ESAPI.validator();
Medium Risk: OWASP A5: Stat Report Rank 7 try {
String u = instance.safeReadLine(s, 20);
} catch (ValidationException e) {
DESCRIPTION // Handle exception
The application makes use of untrusted data in conjunction }
with the creation and or use of an interpreter. Untrusted data
is retrieved from the attacker and utilized as an argument to a URL REDIRECTOR ABUSE
dangerous interpreter access method. Failure to properly validate Medium Risk: OWASP A10: Stat Report Rank 9
or encode data utilized by an interpreter increases the risk of
injection attacks. Such injection typically results in the attacker’s DESCRIPTION
ability to execute arbitrary code in the context of the program Applications frequently redirect users to other pages using stored
consuming the interpreter results. URLs. Sometimes the target page is specified in an untrusted
parameter, allowing attackers to choose the destination page or
SOLUTION location. Such redirects may improperly leverage the trust the
Define and enforce a strict set of criteria defining what the user has in the ulnerable website.
application will accept as valid input, and contextually encode all
untrusted data passed to the interpreter prior to execution. SOLUTION
If untrusted data becomes part of a redirect URL, ensure that the
supplied value has been properly validated and was part of a
DENIAL OF SERVICE (DOS): READLINE
legal and authorized request from the user. It is recommended
Medium Risk: OWASP NA: Stat Report Rank 8
that legal redirect destinations be driven by a “destination id”
DESCRIPTION that is mapped to the actual redirect destination server-side,
The java.io.BufferedReader readLine() method can be used to rather than the actual URL or portion of the URL originating from
the user request. Lookup-maps or access controls tables are best MISSING ACCESS STRATEGY
for this purpose. High Risk: OWASP A5: Stat Report Rank 13
User sessions with long or no inactivity timeouts may help you to invoke servlets without any permissions:
As one of the world’s leading experts on application security, Ryan is frequently turned to by the media for commentary on
some of the most pressing cyber security issues.
DZone, Inc.
DZone communities deliver over 6 million pages each 150 Preston Executive Dr. Cary, NC 27513
month to more than 3.3 million software developers, 888.678.0399 919.678.0300
architects and decision makers. DZone offers something
Copyright © 2018 DZone, Inc. All rights reserved. No part of this publication
for everyone, including news, tutorials, cheat sheets,
may be reproduced, stored in a retrieval system, or transmitted, in any form
research guides, feature articles, source code and more. or by means electronic, mechanical, photocopying, or otherwise, without
"DZone is a developer’s dream," says PC Magazine. prior written permission of the publisher.