Skip to content

Commit

Permalink
Added very basic crsf protection, will add more
Browse files Browse the repository at this point in the history
  • Loading branch information
jogramming committed Aug 1, 2016
1 parent a0f083b commit f2c6e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
AddGuildRedir string `json:"add_guild_redirect"`
BotToken string `json:"bot_token"`
Redis string `json:"redis"`
Host string `json:"host"`
}

func LoadConfig(path string) (c *Config, err error) {
Expand Down
10 changes: 10 additions & 0 deletions web/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"net/http"
"net/url"
"strings"
)

// Will put a redis client in the context if available
Expand Down Expand Up @@ -118,6 +119,15 @@ func RequireSessionMiddleware(inner goji.Handler) goji.Handler {
}
return
}

origin := r.Header.Get("Origin")
if origin != "" {
if !strings.EqualFold(Config.Host, origin) {
http.Redirect(w, r, "/?err=bad_origin", http.StatusTemporaryRedirect)
return
}
}

inner.ServeHTTPC(ctx, w, r)
}
return goji.HandlerFunc(mw)
Expand Down

0 comments on commit f2c6e59

Please sign in to comment.