Giter Club home page Giter Club logo

spring-boot-xss's Introduction

Goals

I’m trying to provide a somewhat meaningful example of Why Can’t I Just HTML Entity Encode Untrusted Data?. I’d like the demo to work within a JSP (or other Java Based Templating Technology). Concreely, I’ve currently come up with the following example:

<html>
<head></head>
<body>
<script>
    <c:out value="alert(7)"/>
</script>
<p>
    <c:out value="alert(7)"/>
</p>
</body>
</html>

The example demonstrates how properly HTML encoding an untrusted value alert(7) will be fine in an HTML context, but unsafe in a <script>. However, it is not very realistic because a user would likely place the untrusted value in quotes:

<html>
<head></head>
<body>
<script>
    var v = '<c:out value="alert(7)"/>';
</script>
<p>
    <c:out value="alert(7)"/>
</p>
</body>
</html>

With the value in quotes, the difficulty with getting XSS is that c:out escapes ". For example, the following:

<script>
    var a = "<c:out value="\";alert(7)\\"/>";
</script>

becomes:

<script>
    var a = "&#034;;alert(7)\";
</script>

In summary:

  • I’d like to demo Why Can’t I Just HTML Entity Encode Untrusted Data?.

  • I’d like the demo to work within a JSP (or other Java Based Templating Technology) but within a more realistic context.

  • I’m fine if the attack is simply popping up an alert.

  • It does not need to be html vs script (it could be something like an HTML vs HTML attribute). So long as it is something a somewhat responsible user would do (i.e. I assume the user would put quotes on the attribute, put quotes around the value injected into the JavaScript var v = '${htmlEncodedValue}', etc)

I’ve put together a sample application for playing around with creating the sample at https://github.com/rwinch/spring-boot-xss. The README contains details on the sample.

Running the Sample

To run the sample from the command line use:

$ ./gradlew bootRun

You can also import as an existing project into Eclipse using:

$ ./gradlew eclipse

File→Import→Existing Project into Workspace

Then you can run by right clicking on SpringBootXssApplication.java and selecting Run As→Java Application

Project Structure

The value being injected can be controlled in SpringBootXssApplication. I’m not doing this via URL parameters since many browsers protect against reflective XSS these days.

Below is a guide to manipulating the templates:

Technology Template Location URL

JSP

src/main/webapp/WEB-INF/jsp/jsp.jsp

http://localhost:8080/

Thymeleaf

src/main/resources/templates/thymeleaf.html

http://localhost:8080/thymeleaf

Velocity

src/main/resources/templates/velocity.vm

http://localhost:8080/velocity

spring-boot-xss's People

Stargazers

Thomas Darimont avatar

Watchers

Rob Winch avatar  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.