summaryrefslogtreecommitdiff
path: root/internal/gtserror/error.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-03-04 12:30:12 +0000
committerLibravatar GitHub <noreply@github.com>2024-03-04 12:30:12 +0000
commitd85727e184a8398ce0ffa40dfd01207342889076 (patch)
tree5ee1860f93157bb2e4649fd86224f43eaa61dd7e /internal/gtserror/error.go
parent[bugfix] Sanitize incoming PropertyValue fields (#2722) (diff)
downloadgotosocial-d85727e184a8398ce0ffa40dfd01207342889076.tar.xz
[bugfix] check remote status permissibility (#2703)
* add more stringent checks for remote status permissibility * add check for inreplyto of a remote status being a boost * do not permit inReplyTo boost wrapper statuses * change comment wording * fix calls to NewFederator() * add code comments for NotPermitted() and SetNotPermitted() * improve comment * check that existing != nil before attempting delete * ensure replying account isn't suspended * use a debug log instead of info. check for boost using ID * shorten log string length. make info level * add note that replying to boost wrapper status shouldn't be able to happen anyways * update to use onFail() function
Diffstat (limited to 'internal/gtserror/error.go')
-rw-r--r--internal/gtserror/error.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/internal/gtserror/error.go b/internal/gtserror/error.go
index dc4c5a504..a39b5475c 100644
--- a/internal/gtserror/error.go
+++ b/internal/gtserror/error.go
@@ -39,13 +39,13 @@ const (
malformedKey
notRelevantKey
spamKey
+ notPermittedKey
)
// IsUnretrievable indicates that a call to retrieve a resource
-// (account, status, attachment, etc) could not be fulfilled,
-// either because it was not found locally, or because some
-// prerequisite remote resource call failed, making it impossible
-// to return the item.
+// (account, status, attachment, etc) could not be fulfilled, either
+// because it was not found locally, or because some prerequisite
+// remote resource call failed, making it impossible to return it.
func IsUnretrievable(err error) bool {
_, ok := errors.Value(err, unrtrvableKey).(struct{})
return ok
@@ -57,6 +57,21 @@ func SetUnretrievable(err error) error {
return errors.WithValue(err, unrtrvableKey, struct{}{})
}
+// NotPermitted indicates that some call failed due to failed permission
+// or acceptibility checks. For example an attempt to dereference remote
+// status in which the status author does not have permission to reply
+// to the status it is intended to be replying to.
+func NotPermitted(err error) bool {
+ _, ok := errors.Value(err, notPermittedKey).(struct{})
+ return ok
+}
+
+// SetNotPermitted will wrap the given error to store a "not permitted"
+// flag, returning wrapped error. See NotPermitted() for example use-cases.
+func SetNotPermitted(err error) error {
+ return errors.WithValue(err, notPermittedKey, struct{}{})
+}
+
// IsWrongType checks error for a stored "wrong type" flag.
// Wrong type indicates that an ActivityPub URI returned a
// type we weren't expecting. For example: