Go (Gin)
Requirements
Installation & Configuration
1
Install Zen Firewall by Aikido
go run github.com/AikidoSec/firewall-go/cmd/zen-go@latest init
go mod tidyimport "github.com/AikidoSec/firewall-go/zen"
func main() {
err := zen.Protect()
if err != nil {
panic(err)
}
// your existing setup
}go install github.com/AikidoSec/firewall-go/cmd/zen-go@latest
go build -toolexec="zen-go" -o bin/appexport AIKIDO_TOKEN=AIK_RUNTIME_2
4
Enable Rate limiting and User blocking
r.Use(func(c *gin.Context) {
if c.GetHeader("user") != "" {
_, err := zen.SetUser(c, c.GetHeader("user"), "John Doe")
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
}
})
r.Use(func(c *gin.Context) {
blockResult := zen.ShouldBlockRequest(c)
if blockResult != nil {
if blockResult.Type == "rate-limited" {
message := "You are rate limited by Zen."
if blockResult.Trigger == "ip" {
message += " (Your IP: " + *blockResult.IP + ")"
}
c.String(http.StatusTooManyRequests, message)
c.Abort()
return
}
if blockResult.Type == "blocked" {
c.String(http.StatusForbidden, "You are blocked by Zen.")
c.Abort()
return
}
}
c.Next()
})5
Setup rate limiting in the dashboard



You are rate limited by Aikido firewall. (Your IP: 1.2.3.4)Last updated
Was this helpful?
