mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-13 09:30:27 -07:00
chore: initial public commit
This commit is contained in:
commit
fc9054b78c
250 changed files with 32809 additions and 0 deletions
24
engine/middleware/hosts.go
Normal file
24
engine/middleware/hosts.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
|
||||
"github.com/gabehf/koito/internal/cfg"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
)
|
||||
|
||||
func AllowedHosts(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
l := logger.Get()
|
||||
if cfg.AllowAllHosts() {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
} else if slices.Contains(cfg.AllowedHosts(), r.Host) {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
l.Warn().Msgf("Request denied from host %s. If you want to allow requests like this, add the host to your %s variable", r.Host, cfg.ALLOWED_HOSTS_ENV)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue