Giter VIP home page Giter VIP logo

xssrequestfilters's Introduction

XssRequestFilter MIT license

Filter the Cross-site scripting

XssRequestFilter is a spring based framework to filter the cross-site scripting in your Controller/RestController request just using a simple @XxsFilter annotation . Also it's easy to customized you own rule for filter xss request.

Use @XxsFilter annotation on your controller methods where you wish to filter Cross-site scripting. It will remove all xss from request parameter.

example:

@Controller
public class TestController {

    @XxsFilter
    @RequestMapping("/")
    public ModelAndView save(Model model, BindingResult result, Map map) {
        // logic
        return new ModelAndView();
    }
    @XxsFilter
        @RequestMapping("/save"
        public ModelAndView save(Model model, BindingResult result, Map map) {
            // logic
            return new ModelAndView();
    }
    
     @XxsFilter
     @RequestMapping("/update")
     public ModelAndView update(Model model, BindingResult result, Map map) {
            // logic
            return new ModelAndView();
     
}

The filter will pick up only those request whose have annotated with @XxsFilter annotation.

Following regex pattern (most of them are case insensitive Pattern) are used for filter xss value :

  • (<input(.*?)></input>|<input(.*)/>)

  • <span(.*?)</span>

  • <div(.*)</div>

  • <style>(.*?)</style>

  • <script>(.*?)</script>

  • javascript:

  • </script>

  • <script(.*?)>

  • src[\r\n]*=[\r\n]*\\\'(.*?)\\\'

  • eval\((.*?)\)

  • expression\((.*?)\)

  • vbscript:

  • onload(.*?)=

XSS Filter Evasion Cheat Sheet

If above patterns are not enough for you and you want your own custom pattern for filter xss request, then no worry XssRequestFilter also support your custom logic for filter your xss request.

Create your own custom logic for filter xss request:

By default this framework you DefaultRansackXssImpl service for filter the xss request, this service implemented RansackXss interface.

So for your custom logic for filter xss request you just need following steps:

  1. Create a class which will implement the RansackXss interface.
  2. Implement the String ransackXss(String value); method. (value parameter is ServletRequest parameter where client can inject the xss, you need to perform the filter on this value, you can take a reference of DefaultRansackXssImpl class)
  3. Create a bean of this class

done... Now instead of DefaultRansackXssImpl, RansackXss will use your class implementation rules for filter xss

Download it from here

  • Apache Maven

      <dependency>
       <groupId>com.github.techguy-bhushan</groupId>
       <artifactId>xss.filter</artifactId>
       <version>1.0.1</version>
      </dependency> 
  • Gradle/Grails

compile 'com.github.techguy-bhushan:xss.filter:1.0.1'

Here are some useful classes used in XssRequestFilter

XssFiltersConfiguration :

This Component will search all the url's which action are annotated with @XxsFilter (collect the list of urls, which will be pick by CustomXssFilter )

CustomXssFilter:

This filter will only work for request which action have annotated @XxsFilter (with help of XssFiltersConfiguration)

CaptureRequestWrapper :

This class is responsible for filter the XSS in request you can add or remove the XSS handling logic in #stripXSS method in CaptureRequestWrapper, CustomXssFilter use this class for remove xss in request.

FilterConfig :

This component will register CustomXssFilter if there will any @XxsFilte annotation used in url mapping, if there will no @XxsFilte used in application then CustomXssFilter will disable.

Please create a new issue if you found any issue, also you can create a pull request from improvement.

Thank you!

xssrequestfilters's People

Contributors

techguy-bhushan avatar

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.