nosurf Go 的 CSRF 中间件开源项目

我要开发同款
匿名用户2013年11月21日
80阅读

技术信息

开源地址
https://github.com/justinas/nosurf
授权协议
MIT

作品详情

osurf是Go语言的一个CSRF跨站请求伪造(CrossSiteRequestForgery)中间件,可嵌入到et/http中使用,可方便与Gorilla和Martii框架结合使用。

示例代码:

packagemaiimport("fmt""github.com/justias/osurf""html/template""et/http")vartemplateStrigstrig=`<!doctypehtml><html><body>{{if.ame}}<p>Yourame:{{.ame}}</p>{{ed}}<formactio="/"method="POST"><iputtype="text"ame="ame"><!--Tryremovigthisorchagigitsvalueadseewhathappes--><iputtype="hidde"ame="csrf_toke"value="{{.toke}}"><iputtype="submit"value="Sed"></form></body></html>`vartempl=template.Must(template.New("t1").Parse(templateStrig))fucmyFuc(whttp.ResposeWriter,r*http.Request){cotext:=make(map[strig]strig)cotext["toke"]=osurf.Toke(r)ifr.Method=="POST"{cotext["ame"]=r.FormValue("ame")}templ.Execute(w,cotext)}fucmai(){myHadler:=http.HadlerFuc(myFuc)fmt.Pritl("Listeigohttps://127.0.0.1:8000/")http.ListeAdServe(":8000",osurf.New(myHadler))}

功能介绍

nosurf 是 Go 语言的一个 CSRF 跨站请求伪造(Cross Site Request Forgery) 中间件,可嵌入到 net/http 中使用,可方便与 Gorilla 和 Ma...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论