fix webmention validation content-type with charset would fail

This commit is contained in:
Wouter Groeneveld 2022-05-16 14:47:04 +02:00
parent 56b84125c4
commit d2cffd68b0
3 changed files with 10 additions and 3 deletions

View File

@ -8,7 +8,6 @@ import (
"brainbaking.com/go-jamming/rest"
"encoding/xml"
"fmt"
"github.com/rs/zerolog/log"
"io/ioutil"
"net/http"
)
@ -94,7 +93,8 @@ func pingbackError(w http.ResponseWriter, err error) {
</value>
</fault>
</methodResponse>`
log.Error().Err(err).Msg("Pingback receive went wrong")
// No longer interested in pingback errors, these are 99.9% badly formatted spam that clog up syslog
// log.Error().Err(err).Msg("Pingback receive went wrong")
w.WriteHeader(200)
w.Write([]byte(xml))
}

View File

@ -29,7 +29,7 @@ func isValidTargetUrl(url string, httpClient rest.Client) bool {
}
func validate(r rest.HttpReq, h rest.HttpHeader, conf *common.Config) bool {
return h.Get("Content-Type") == "application/x-www-form-urlencoded" &&
return strings.HasPrefix(h.Get("Content-Type"), "application/x-www-form-urlencoded") &&
isValidUrl(r.FormValue("source")) &&
isValidUrl(r.FormValue("target")) &&
r.FormValue("source") != r.FormValue("target") &&

View File

@ -56,6 +56,13 @@ func TestValidate(t *testing.T) {
contentType string
expected bool
}{
{
"is valid if encoded as form including the charset",
"https://brainbaking.com/bla1",
"https://jefklakscodex.com/bla",
"application/x-www-form-urlencoded; charset=utf-8",
true,
},
{
"is valid if source and target https urls",
"http://brainbaking.com/bla1",