mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 05:22:04 -07:00
refact: refactored api.rest module to use GIN and have better security (fixes #11)
This commit is contained in:
parent
2454a669bb
commit
fd18dffd1a
5 changed files with 164 additions and 155 deletions
35
modules/api_rest_security.go
Normal file
35
modules/api_rest_security.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/unrolled/secure.v1"
|
||||
)
|
||||
|
||||
func SecurityMiddleware() gin.HandlerFunc {
|
||||
rules := secure.New(secure.Options{
|
||||
FrameDeny: true,
|
||||
ContentTypeNosniff: true,
|
||||
BrowserXssFilter: true,
|
||||
ReferrerPolicy: "same-origin",
|
||||
})
|
||||
|
||||
return func(c *gin.Context) {
|
||||
err := rules.Process(c.Writer, c.Request)
|
||||
if err != nil {
|
||||
who := strings.Split(c.Request.RemoteAddr, ":")[0]
|
||||
req := fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.Path)
|
||||
log.Warning("%s > %s | Security exception: %s", who, req, err)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if status := c.Writer.Status(); status > 300 && status < 399 {
|
||||
c.Abort()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue