tommy351 / gin-csrf Goto Github PK
View Code? Open in Web Editor NEWCSRF protection middleware for Gin.
License: MIT License
CSRF protection middleware for Gin.
License: MIT License
Using the example from your README:
package main
import (
"github.com/gin-gonic/gin"
"github.com/tommy351/gin-sessions"
"github.com/tommy351/gin-csrf"
)
func main(){
g := gin.New()
store := sessions.NewCookieStore([]byte("secret123"))
g.Use(sessions.Middleware("my_session", store))
g.Use(csrf.Middleware(csrf.Options{
Secret: "secret123",
ErrorFunc: func(c *gin.Context){
c.String(400, "invalid csrf")
c.Abort()
},
}))
g.GET("/protected", func(c *gin.Context){
csrf.GetToken(c)
c.String(200, csrf.GetToken(c))
})
g.POST("/protected", func(c *gin.Context){
csrf.GetToken(c)
c.String(200, "CSRF token is valid")
})
g.Run(":3000")
}
I am able to POST to /protected
without any cookies and I receive a message that the CSRF token is valid.
Hi http://gin-gonic.github.io/gin/ seems does not exist
I was already using gin-contrib sessions in a project, but then when I needed csrf token support and found this library, I find out that this needs your session library instead of the gin-contrib one I was already using.
Is there much difference between your session library and the one from gin-contrib? both seem to be based on gorilla/session and look pretty much identical. Can the gin-csrf library be made compatible with gin-contrib sessions or not really?
Is there any reason why gorilla/csrf was not used as a foundation? I am just looking at the code and it looks like this library implements csrf from scratch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.