Giter VIP home page Giter VIP logo

coverity-security-library's Introduction

Build Status

Coverity Security Library

The Coverity Security Library (CSL) is a lightweight set of escaping routines for fixing cross-site scripting (XSS), SQL injection, and other security defects in Java web applications.

Here's why it's worth checking out:

  • It's secure: We take the security of CSL seriously. Every change is carefully scrutinized through a process that includes manual code review, static analysis, fuzz testing, and unit testing.

  • It's convenient: CSL contains escapers for XSS and SQL injection that are missing from standard libraries like Apache Commons and Java EE. We use fast, easy to invoke static methods with short, intuitive names. We also provide hooks for Expression Language (EL) to make it easy to use within JSPs.

  • It's small: CSL has no external dependencies and is a minimalist library. This means it's fast and does not require any configuration besides dropping a JAR in the right location or modifying your build to do it.

  • It's free: CSL is distributed under a BSD-style license. We would appreciate patches be sent back to us but it's not required.

Users of Coverity Security Advisor get remediation guidance based on escaping routines in CSL. However, CSL is a standalone project with no dependencies on Security Advisor.

Escape

The Escape class contains several escapers for web content. These escaping functions help remedy common defects (mostly cross-site scripting) that occur when the data is inserted into HTML element, HTML attribute values, URI, JavaScript strings, SQL LIKE clauses, etc. More information are available in the Escape directory.

Before using any of these methods, you should understand the context (or nested contexts) in which the data is inserted. Several mockup examples with explanation are available in the repository, and more will be available on our blog. If you want to test the library to understand how it whistands security attacks, our functional testsuite is the right app to build/deploy/test.

Ready to use it? One last step is to have a look at the latest javadoc directly on github.

To include this library into your Maven project, add the following:

<dependency>
    <groupId>com.coverity.security</groupId>
    <artifactId>coverity-escapers</artifactId>
    <version>1.1.1</version>
</dependency>

or drop the JAR file in the WEB-INF/lib directory.

Then you can use it directly in your JSPs:

<%@ taglib uri="http://coverity.com/security" prefix="cov" %>
<script type="text/javascript">
    var x = '${cov:jsStringEscape(param.tainted)}';
</script>
<div onclick="alert('${cov:htmlEscape(cov:jsStringEscape(param.tainted))}')">
    ${cov:htmlEscape(param.tainted)}
</div>

or in your Java programs:

import com.coverity.security.Escape;
// ...
return "<div onclick='alert(\""
       + Escape.html(Escape.jsString(request.getParameter("tainted")))
       + "\")'>"
       + Escape.html(request.getParameter("tainted"))
       + "</div>";

To contact the SRL, please email us at [email protected]. Fork away, we look forward to your pull requests!

License

Copyright (c) 2012-2016, Coverity, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
- Neither the name of Coverity, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission from Coverity, Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND INFRINGEMENT ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR  CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT,  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.

coverity-security-library's People

Contributors

jpasski avatar neuroo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coverity-security-library's Issues

Add a List<Context> field to a generic escaper and pass in desired context

As the library grows I think we'll start to have a lot of different escapers and subsequently, different method names and tag libraries. This may get confusing and also creates large nesting of methods. E.g. escaperA(escaperB(escaperC(tainted_data))). As an option I'm proposing adding a generic escaping name with a second field (first field is still the input string) that takes a List of Context enums. This would allow the author to declare the intent more succinctly to me. The underlying implementation would then just iterate over the list, calling the respective escaper method. While this adds some overhead, I think there's a benefit for some people.

Proxy issue: U+003C (<) in a JS string context is escaped, increasing the output text size unnecessarily

From Jim Manico via email. (Jim authorized the content of the email to be posted in this bug).

Email:

From: Jim Manico
Subject: Escaper
Date: January 19, 2013 2:36:37 PM PST
To: Andy Chou, Jon Passki, Jeff Ichnowski, Jeremy Long

Andy and Jon,

CSL is remarkable, nice work gentlemen.

I think there are ways to make your JS encoder a bit more efficient (in terms of encoding output containing less characters).

Here is detailed explanation:

"(We think that) '<' is not the dangerous thing in JS, but '</' is.  Of course if you escape '<' then you escape '</', the solution in owasp > encoders is to escape '/' to '/'.  Thus '</script>' is encoded as '</script>' instead of '\x2c/script>' (or as the coverity case '\u002c/sc> ript>'> ).  The net result is saving 4 characters over coverity's unicode and 2 over the shorter hex-encoded alternative to coverity's.  In my experi> ence > though, '<' appears in a lot of JS strings, so it adds up." (from Jeff Ichnowski)>

This is a subtle point, but we wanted to let you know what we see what you are up to, it's awesome, and wanted to throw some feedback your way.

Last note, I really think the universe needs a Encoder test project.

I wanted to use some of your unit tests and Escaper research, and combine that with research from Jeff Williams (ESAPI), Jeff Ichnowski (OWASP > Encoder Project for Java), Mike Samuel (OWASP Java HTML Sanetizer and Google AppSec Lead for CAJA an others), Jeremy Long (Wells Fargo) as well> as > a few others who care about XSS Escaping, and form a working group.>

I am hoping that we can publish a language neutral test suite to check if anyone Escaper/Encoder class has been done in a secure fashion.

I write to you as a non profit board member of OWASP. That hat is 100% on. Please note I compete with you in the business world, and I'm > celebrating your work, providing a potential enhancement to it, and hoping we can all work together to serve the community.>

Aloha,
Jim Manico
OWASP Board Member
@manicode
(808) 652-3805

Add library support for different programming languages.

From some emails and in-person feedback, I've heard about the following requested languages:

  • .NET / C#
  • python

This is a placeholder issue since these other languages probably should be in a different repository. Or, if they're all going to be here, then we'll need to re-organize this repository. I'm open to either since the end-user consumables probably won't be this source code. E.g., for Java it'll probably be Maven artifacts in Sonatype's Central.

Add % to the JS string escaper

The current implementation does not JS string escape '%' and this can cause issues when the wrong sequence of escapers are used in a javascript: URI.
The recommendation is to JS string escape -> URI encode -> HTML escape, but when adding % to JS string escape, we can factor out the URI encoder.

Escape.jsString issue

I hope this is just due to my ignorance, but why is the semi-column (;) not escaped? It seemed open the door for attacks like this,

coverity jsp/el escaping
<!-- Example of usage within a JSP --> 
<!-- http://localhost:8080/HelloJSP/jsp/testcout.jsp?foo=2;alert(1);  -->
<script type="text/javascript">
    // var n1 = <%=Escape.jsString("1.5; alert(1);") %>;
    var n3 = <%=Escape.jsString(request.getParameter("foo")) %>;
</script>

Maybe I'm missing something here. Please advise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.