GithubHelp home page GithubHelp logo

yohgaki / no-cross-site-requests Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3 KB

Sample code that disables cross site attacks (i.e. CSRF, XSS) against your PHP app.

License: MIT License

PHP 100.00%

no-cross-site-requests's Introduction

Reject all cross site requests - CSRF/XSS

This is sample PHP script that rejects all cross site requests. You wrote your own private PHP tools to help development and operations and don't want cross site attacks, i.e. CSRF/XSS, then this script may be for you.

You can use URL rewriter to protect your entire app from cross site attack, simple and easy with PHP.

How to use sample

  1. Clone this repository
  2. Run built in web server like "php -d auto_prepend_file=site_protect.php -S 127.0.0.1:8888" in the cloned repository directory.
  3. Access http://127.0.0.1:8888/index.php from you browser
  4. Click "protected.php" link
  5. Then try to access without rtoken or broken token in URL. You should get error for invalid rtoken for protected.php. (index.php is not protected by config. You need at least one entry point to enter your web app.)

To use with real web servers, use php.ini's "auto_prepend_file" setting or include site_protect.php from your entry point script. A few configuration parameters can be used, refer to site_protect.php for details.

JavaScript Note

If you have JavaScirpt in your pages, you should get token from query string and append it to all URL links. Do not make API to get the token, instead you must get token value from query string. i.e. GET

How it works?

  • Create request validation token from session ID. (i.e. sha1(session_id())
  • Add request token to any and tags by output_add_rewrite_var()
  • Verify request token except PHP scripts defined in $entry_points

CSRF and XSS is common vulnerability. If your app uses single index.php entry point, modify script so that certain REQUEST_URI is protected. Your private sites/apps could be more secure with this.

Enjoy better security!

no-cross-site-requests's People

Contributors

yohgaki avatar

Watchers

 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.