Giter VIP home page Giter VIP logo

xss-demo's Introduction

xss-demo

Minimal, flask-powered python web app to demonstrate reflected and stored XSS attacks. Less than 30 lines of Python + 40 lines HTML template.

XSS Demo Screenshot

Quickstart

  • Clone this repository.
  • Create a virtual environment (if you don't want to install flask in your global python environment) and activate it.
  • pip install flask
  • FLASK_ENV=development flask run
  • Open 127.0.0.1:5000 in your webbrowser.

As you started the flask app in development mode, any source changes should apply immediately so you can just refresh the page. If you want to clear the database, just delete the database.db file that is (re-)created on first use.

Making it vulnerable

To demonstrate XSS flaws you can change templates/index.html line 2

{% autoescape false %}

And then try <script>alert('javascript was executed')</script> as inputs both for the search input (reflected XSS) and the write comment input (stored XSS).

To demonstrate that context-aware filtering is important, you can change line 33 in index.html to

      <div title={{ comment }}>

and even with line 2 having autoescape set to true, you can mount a stored XSS attack by adding a comment like this:

tooltip onmouseover=alert(1)

Protection mechanisms

Of course you should never deactivate autoescaping in jinja/flask, so you should never have {% autoescape false %} in your production templates. This way you will always get the standard HTML context filtering for variables in your templates.

The tooltip attack mentioned above can of course be avoided by using quotes correctly on line 33 :

      <div title="{{ comment }}">

You can also test using Content Security Policy headers to disallow unsafe inline javascript by replacing app.py line 16-18 with:

    from flask import make_response
    r = make_response(render_template('index.html',
                      comments=comments,
                      search_query=search_query))
    r.headers.set('Content-Security-Policy', "script-src 'none'")
    return r

xss-demo's People

Contributors

bgres 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

Watchers

 avatar

xss-demo's Issues

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.