Avoid labelling requests on non-standard ports as malformed.

This commit is contained in:
Azareal 2019-03-31 11:50:59 +10:00
parent 0bbdb6482e
commit c8a8de95ae
2 changed files with 6 additions and 2 deletions

View File

@ -702,6 +702,7 @@ func (r *GenRouter) SuspiciousRequest(req *http.Request, prepend string) {
func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Redirect www. requests to the right place
if req.Host == "www." + common.Site.Host {
// TODO: Abstract the redirect logic?
w.Header().Set("Connection", "close")
var s string
if common.Site.EnableSsl {
@ -716,7 +717,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
// Deflect malformed requests
if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' || req.Host != common.Site.Host {
shost := strings.Split(req.Host,":")
if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' || shost[0] != common.Site.Host || len(shost) > 2 {
w.WriteHeader(200) // 400
w.Write([]byte(""))
r.DumpRequest(req,"Malformed Request")

View File

@ -481,6 +481,7 @@ func (r *GenRouter) SuspiciousRequest(req *http.Request, prepend string) {
func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Redirect www. requests to the right place
if req.Host == "www." + common.Site.Host {
// TODO: Abstract the redirect logic?
w.Header().Set("Connection", "close")
var s string
if common.Site.EnableSsl {
@ -495,7 +496,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
// Deflect malformed requests
if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' || req.Host != common.Site.Host {
shost := strings.Split(req.Host,":")
if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' || shost[0] != common.Site.Host || len(shost) > 2 {
w.WriteHeader(200) // 400
w.Write([]byte(""))
r.DumpRequest(req,"Malformed Request")