commit b1ecaba

default  ·  2023-12-11 15:59:33 +0000 UTC
parent e78f0bf
Added a special drop for Delete messages from unknown actors.
1 files changed,  +15, -7
+15, -7
 1@@ -1470,9 +1470,11 @@ int update_question(snac *user, const char *id)
 2 
 3 int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
 4 /* processes an ActivityPub message from the input queue */
 5+/* return values: -1, fatal error; 0, transient error, retry;
 6+   1, processed and done; 2, propagate to users (only when no user is set) */
 7 {
 8-    char *actor  = xs_dict_get(msg, "actor");
 9-    char *type   = xs_dict_get(msg, "type");
10+    char *actor = xs_dict_get(msg, "actor");
11+    char *type  = xs_dict_get(msg, "type");
12     xs *actor_o = NULL;
13     int a_status;
14     int do_notify = 0;
15@@ -1500,13 +1502,21 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
16     else
17         utype = "(null)";
18 
19+    /* special case for Delete messages */
20+    if (strcmp(type, "Delete") == 0) {
21+        /* if the actor is not here, do not even try */
22+        if (!object_here(actor)) {
23+            srv_debug(0, xs_fmt("dropped 'Delete' message from unknown actor '%s'", actor));
24+            return -1;
25+        }
26+    }
27+
28     /* bring the actor */
29     a_status = actor_request(actor, &actor_o);
30 
31     /* do not retry permanent failures */
32     if (a_status == 404 || a_status == 410 || a_status < 0) {
33         srv_debug(1, xs_fmt("dropping message due to actor error %s %d", actor, a_status));
34-
35         return -1;
36     }
37 
38@@ -1519,7 +1529,6 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
39 
40         /* other actor download errors may need a retry */
41         srv_debug(1, xs_fmt("error requesting actor %s %d -- retry later", actor, a_status));
42-
43         return 0;
44     }
45 
46@@ -1530,13 +1539,12 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
47         srv_log(xs_fmt("bad signature %s (%s)", actor, sig_err));
48 
49         srv_archive_error("check_signature", sig_err, req, msg);
50-
51         return -1;
52     }
53 
54-    /* if no user is set, no further checks can be done */
55+    /* if no user is set, no further checks can be done; propagate */
56     if (snac == NULL)
57-        return 1;
58+        return 2;
59 
60     /* reject messages that are not for this user */
61     if (!is_msg_for_me(snac, msg)) {