Skip to content

Commit

Permalink
Rename privateIPHandler to privateAccessHandler, and allow loopba…
Browse files Browse the repository at this point in the history
…ck address access
  • Loading branch information
mstmdev committed Jan 12, 2022
1 parent 0b2193a commit d47dfbb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/gofs/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func parseFlags() {
flag.StringVar(&fileServerAddr, "server_addr", server.DefaultAddrHttps, "a file server binding address")
flag.BoolVar(&enableFileServerCompress, "server_compress", true, "enable response compression for the file server")
flag.BoolVar(&enablePprof, "pprof", false, "enable the pprof route")
flag.BoolVar(&pprofPrivate, "pprof_private", true, "allow to access pprof route by private ip only")
flag.BoolVar(&pprofPrivate, "pprof_private", true, "allow to access pprof route by private address and loopback address only")

// tls transfer
flag.BoolVar(&enableTLS, "tls", true, fmt.Sprintf("enable the tls connections, if disable it, server_addr is \"%s\" default", server.DefaultAddrHttp))
Expand Down
2 changes: 1 addition & 1 deletion server/fs/file_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func StartFileServer(opt server.Option) error {
if opt.EnablePprof {
debugGroup := rootGroup.Group("/debug")
if opt.PprofPrivate {
debugGroup.Use(middleware.NewPrivateIPHandler(logger).Handle)
debugGroup.Use(middleware.NewPrivateAccessHandler(logger).Handle)
}
pprof.RouteRegister(debugGroup, "pprof")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
"net/http"
)

type privateIPHandler struct {
type privateAccessHandler struct {
logger log.Logger
}

func NewPrivateIPHandler(logger log.Logger) handler.GinHandler {
return &privateIPHandler{
func NewPrivateAccessHandler(logger log.Logger) handler.GinHandler {
return &privateAccessHandler{
logger: logger,
}
}

func (h *privateIPHandler) Handle(c *gin.Context) {
func (h *privateAccessHandler) Handle(c *gin.Context) {
ip := net.ParseIP(c.ClientIP())
if !ip.IsPrivate() {
if !ip.IsPrivate() && !ip.IsLoopback() {
h.logger.Warn("access deny, client ip is [%s], path is [%s]", c.ClientIP(), c.FullPath())
c.String(http.StatusUnauthorized, "access deny")
c.Abort()
Expand Down

0 comments on commit d47dfbb

Please sign in to comment.