Coder Social home page Coder Social logo

anticsrf's Introduction

antiCsrf

功能介绍

  • antiCsrf是openresty进行开发的防御csrf攻击的模块。防御的模式是使用token验证的模式。
  • 只针对POST模式进行防御
  • 对被拦截的请求,将返回http状态403
  • 代码中只针对/xxx的post请求进行拦截

csrf定义

csrf全称为跨站请求伪造(Cross-site request forgery),是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法。CSRF 利用的是网站对用户网页浏览器的信任。维基百科:跨站请求伪造

使用说明

nginx配置修改

  • openresty版本:1.11.2.4, 具体安装请参照openresty.org
  • 在nginx.conf中添加内容
        location /xxx {
          access_by_lua_file conf/access.lua;
          content_by_lua '
            ngx.header.content_type = "text/html"
            ngx.say("<!DOCTYPE html><html><body>test success</body></html>");
          ';
        }

        location / {
            header_filter_by_lua_file conf/header_filter.lua;
            content_by_lua '
                ngx.header.content_type = "text/html"
                local res = "<html><head><meta charset=\'utf-8\'><title>form page</title></head><body><form action=\'http://123.123.123.123:5895/xxx\' method=\'post\'>"
                res = res.."name:<input name=\'name\'><br>csrf token:<input name=\'csrf_token\'><br>"
                res = res.."<input type=\'submit\' value=\'commit\'></form></body></html>"
                ngx.say(res)
            ';
        }

  • 重启nginx或者重新加载nginx配置生效:./nginx -s reload

anticsrf's People

Contributors

crazyleeyang avatar

Watchers

James Cloos 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.