JavaEE has some excellent built-in security mechanisms, but they don’t come close to covering all the threats that your applications will face.  Many common attacks like Cross-Site Scripting (XSS), SQL Injection, Cross-Site Request Forgery (CSRF), and XML eXternal Entities (XXE) aren’t covered at all.  You can prevent your web applications and web services from being vulnerable to these attacks, but it’s going to take some work and testing.  Fortunately, the Open Web Application Security Project (OWASP) has issued the “Ten Most Critical Web Application Security Risks” report.

Let’s take a look at how these important risks apply to JavaEE web applications and web services:

1. Injection - Injection happens any time a developers takes  untrusted information, such as request.getParameter(), request.getCookie(), or request.getHeader(), and uses it in a command interface.  For example, SQL injection happens if you concatenate untrusted data into a regular SQL query, like “SELECT * FROM users WHERE username=‘“ + request.getParameter(“user”) + “‘ AND password=‘“ + request.getParameter(“pass”) = “‘“;  Developers should use PreparedStatement to keep attackers from changing the meaning of queries and taking over database hosts.  There are many other types of injection such as Command Injection, LDAP Injection, and Expression Language (EL) Injection, and all of them are devastatingly dangerous, so be careful when sending data to these interpreters.

2. Broken Authentication and Session Management – JavaEE has support for authentication and session management, but there are many ways to go wrong here. You’ll have to make sure that all authenticated traffic goes over SSL, no exceptions.  If you ever expose a JSESSIONID it can be used to hijack a user’s session without their knowledge.  You should rotate the JSESSIONID when the user authenticates to prevent Session Fixation attacks.  And you should avoid the use of response.encodeURL() which adds the user’s JSESSIONID to the URL where it can be more easily disclosed or stolen.

3. Cross-Site Scripting (XSS) - XSS occurs when JavaEE developers take untrusted information from the HTTP request and put it in the HTTP response without proper contextual output encoding.  The attacker can use this behavior to inject their scripts into a website where they can hijack sessions and steal data.  To prevent these attacks, developers need to perform context-sensitive output encoding.  If you’re putting data into HTML, use &#xx; format. Be sure to quote your HTML attributes, as unquoted attributes can be terminated with many different characters.  If you’re putting untrusted data into Javascript, URLs, or CSS, use the appropriate escaping technique for each.  And be very careful when dealing with nested contexts, such as a URL in Javascript in an HTML attribute. You'll want an encoding library like OWASP ESAPI to help.

4. Insecure Direct Object References – Anytime your application exposes an internal identifier, such as a database key, a filename, or hashmap index, attackers may attempt to manipulate those identifiers to access unauthorized data.  For example, if you pass untrusted data from the HTTP request to the Java File constructor, the attacker may use "../" or null byte attacks to trick your validation. You should consider using indirect references to your data, to prevent this type of attack. The ESAPI library has support for ReferenceMaps that facilitate this indirection.

5. Security Misconfiguration – There are a lot of security settings in modern JavaEE applications and frameworks like Struts and Spring. Be sure you have reviewed them and set things up the way you want.  For example, beware the <http-method> tag in a <security-constraint>.  This indicates that the security-constraint only applies to the listed methods, allowing attackers to use other HTTP methods, like HEAD and PUT, to bypass the entire security constraint.  Most likely you should delete <http-method> tags from your web.xml.

6. Sensitive Data Exposure – Java has extensive cryptographic libraries, but they are not easy to use correctly. You should find a library that builds on top of JCE to provide easily and safely usable cryptographic methods. Some examples are Jasypt and ESAPI.  You should be using strong algorithms like AES for encryption and SHA256 for hashes.  Be careful with password hashes as they can be reversed using a Rainbow Table, so use adaptive algorithms like bcrypt or PBKDF2.

7. Missing Function Level Access Control – JavaEE supports both declarative and programmatic access control, but many applications still choose to create their own scheme. Frameworks like Spring also have annotation-based access control primitives. The most important thing is to be sure that every exposed endpoint has the appropriate access control check, including web services.  Don’t assume that your client can control anything, as attackers will access your endpoints directly.

8. Cross Site Request Forgery (CSRF) - Every state-changing endpoint needs to verify that requests are not forged. Developers should put a random token in each user’s session and then verify it when requests arrive. Otherwise, attackers can create "attack" pages by including malicious IMG, SCRIPT, FRAME, or FORM tags that link to the unprotected application. When the victim views such a page, their browser will generate a "forged" HTTP request to whatever URL is specified in the tag, and will automatically include the victim’s credentials.

9. Using Components with Known Vulnerabilities – Modern JavaEE applications have hundreds of libraries. Dependency resolution tools like Maven have caused this number to explode in the past five years.  Many widely used Java libraries haveknown vulnerabilities that can allow a web application using them to be completely subverted.  The solution is to stay on top of your libraries and keep them up to date. Don't just run a single scan, as new vulnerabilities are released every day.

10. Unvalidated Redirects and Forwards — Anytime your application uses untrusted data, such as a request.getParameter() or request.getCookie(), in a call to response.sendRedirect(), the attacker may be able to force a victim’s browser to an untrusted website designed to install malware.  A similar problem exists with forwards, except that the attacker may be able to forward himself to unauthorized functionality, such as administrative pages.  Be sure to carefully validate redirect and forward targets.

You should stay on top of these problems continuously. New attacks and vulnerabilities are identified all the time. Ideally, you'll integrate security checks into your existing build, test, and deployment process.

To check your applications for these problems, try the FREE Contrast for Eclipse plugin. It’s not a simple static analysis tool.  Instead, C4E takes advantage of the Java Instrumentation API to monitor everything in your application related to security.  C4E even does full data flow analysis in realtime, so it can trace data from the request through a complex application.  For example, imagine that your code takes a parameter value, base64 decode it, store it in a map, put the map in a data bean, store the bean in a session attribute, fetch the bean value in a JSP and insert it into the webpage using EL. Contrast for Eclipse will trace that data and report the XSS vulnerability.  Even if you are using complex frameworks and libraries.  No other tool comes close in terms of speed, accuracy, and ease of use.

You can find Contrast for Eclipse in the Eclipse Marketplace.  Then just go to the Servers tab and “Start with Contrast” — we’ll do the rest.

reference from:

http://eclipse.dzone.com/articles/10-most-important-security

The 10 Most Important Security Controls Missing in JavaEE--reference的更多相关文章

  1. APPLE-SA-2019-3-25-2 macOS Mojave 10.14.4,Security Update 2019-002 High Sierra, Security Update 2019-002 Sierra

    APPLE-SA-2019-3-25-2 macOS Mojave 10.14.4, Security Update2019-002 High Sierra, Security Update 2019 ...

  2. Asp.net - The type or namespace name 'App_Code' does not exist in the namespace 'xxx' (are you missing an assembly reference?)

    我在 项目 下面创建一个 App_Code的文件夹,然后在其下创建自定义的类,但是当我在该项目下别的地方使用时报错: The type or namespace name 'App_Code' doe ...

  3. unity3d MonoDevelop引用外部自定义dll文件报错:are you missing an assembly reference?

    在unity3d 编辑器 MonoDevelop 中引用外部自定义dll文件报错:are you missing an assembly reference? 因为unity还停留在.NET Fram ...

  4. The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)

    The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing ...

  5. The 10 Most Important Linux Commands/10个最经常使用的命令行

    1. ls 命令:to show all of the major directiories filed under a given file system. for example: ls /app ...

  6. The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

    应该说是 .net4 的bug,没有所谓的 System.Web.Extensions.dll 库文件,需要将项目的 Target Framework修改为 3.5版本,才能加载System.Web. ...

  7. A Study of WebRTC Security

    转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...

  8. The Ultimate List of Open Source Static Code Analysis Security Tools

    https://www.checkmarx.com/2014/11/13/the-ultimate-list-of-open-source-static-code-analysis-security- ...

  9. SQL Server: Top 10 Secrets of a SQL Server Expert

    转载自:http://technet.microsoft.com/en-us/magazine/gg299551.aspx Many companies have downsized their IT ...

随机推荐

  1. 解决win8.1右键菜单出现在左边

    这个问题估计很少有人遇到,当在桌面上单击鼠标右键时,如果正常情况下,应该是在鼠标光标的右侧弹出来,除非右边的空间不够了,才在左侧弹出.但遇到故障,就是不论在桌面的哪里点右键,菜单都在左侧弹出,虽然不影 ...

  2. 优化 Android 线程和后台任务开发

    在 Android 开发中,你不应该做任何阻碍主线程的事情.但这究竟意味着什么呢?在这次海湾 Android 开发者大会讲座中,Ari Lacenski 认为对于长时间运行或潜在的复杂任务要特别小心. ...

  3. IDM和ODM

    DM (Integrated Data Multiplexer):综合数据复用器[1]  综合数据复用器是一种数据复用设备,它可以将多路RS232.RS485及数字语音等多种数据复用到E1传输通道或光 ...

  4. CSS+DIV之强化background属性

    1.背景颜色属性(background-color),设定背景颜色=html中bgcolor属性.我来写一个红色背景的body,(也可以定义某个特定区域) 示例写法:body {} 2.背景图片属性( ...

  5. asp.net 使用 MongoDB 初体验

    首先:驱动 如果asp.net 想使用MongoDB,.net没有自带的链接类.得用第三方或官方的链接类. 当然有很多种驱动,我就不一一介绍了. 今天我就介绍一个我比较常用的驱动-----MongoD ...

  6. [Raobin] Ext.net在前端直接将对象转为json形式传入后台

    d.Render.ExtraParams.Add(Html.Y().Parameter("Json", new JavaScriptSerializer().Serialize(e ...

  7. 快速定位隐蔽的sql性能问题及调优【转载】

    在前几天,有个开发同事问我一个问题,其实也算是技术救援,他说在有个job数据处理的频率比较高,在测试环境中很难定位出在哪有问题,而且速度也还能接 受,但是在生产环境中总是会慢一些,希望我能在测试环境中 ...

  8. sed写的命令收集

    1. 替换一行字符串. <title name= > <param name="root", value="haha"/> <pa ...

  9. 判断是否已安装.net framework

    1.检测 %SystemRoot%\System 目录下的MSCorEE.dll文件,如果存在,则表明.net framework 已安装. 2.检测一下注册表项的子项: KEY_LOCAL_MACH ...

  10. 【Java基础】Java多线程之线程组和线程池

    在上一篇文章中,讲述了线程的基本概念和用法,这里将继续讲述线程组和线程池的一些东西. 线程组:java.lang.ThreadGroup 1. 线程组的介绍 线程组表示一个线程的集合.此外,线程组也可 ...