This commit is contained in:
tsmethurst 2021-08-19 15:40:33 +02:00
commit accc8971d1
53 changed files with 896 additions and 486 deletions

View file

@ -6,8 +6,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-fed/httpsig"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@ -33,13 +31,13 @@ func (m *Module) SignatureCheck(c *gin.Context) {
// we managed to parse the url!
// if the domain is blocked we want to bail as early as possible
blockedDomain, err := m.blockedDomain(requestingPublicKeyID.Host)
blocked, err := m.db.IsURIBlocked(requestingPublicKeyID)
if err != nil {
l.Errorf("could not tell if domain %s was blocked or not: %s", requestingPublicKeyID.Host, err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}
if blockedDomain {
if blocked {
l.Infof("domain %s is blocked", requestingPublicKeyID.Host)
c.AbortWithStatus(http.StatusForbidden)
return
@ -50,20 +48,3 @@ func (m *Module) SignatureCheck(c *gin.Context) {
}
}
}
func (m *Module) blockedDomain(host string) (bool, error) {
b := &gtsmodel.DomainBlock{}
err := m.db.GetWhere([]db.Where{{Key: "domain", Value: host, CaseInsensitive: true}}, b)
if err == nil {
// block exists
return true, nil
}
if err == db.ErrNoEntries {
// there are no entries so there's no block
return false, nil
}
// there's an actual error
return false, err
}