commit c8d535a

default  ·  2023-08-13 14:09:20 +0000 UTC
parent d3de540
Ignore 'Add' activities ASAP.
1 files changed,  +10, -5
+10, -5
 1@@ -1412,6 +1412,12 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
 2     if (xs_is_null(type))
 3         type = "Note";
 4 
 5+    /* reject uninteresting messages right now */
 6+    if (strcmp(type, "Add") == 0) {
 7+        snac_debug(snac, 0, xs_fmt("Ignored message of type '%s'", type));
 8+        return 1;
 9+    }
10+
11     if (xs_is_null(actor)) {
12         snac_debug(snac, 0, xs_fmt("malformed message"));
13         return 1;
14@@ -2084,9 +2090,9 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
15 
16     /* decode the message */
17     xs *msg = xs_json_loads(payload);
18-    const char *id;
19+    const char *id = xs_dict_get(msg, "id");
20 
21-    if (msg == NULL || xs_is_null(id = xs_dict_get(msg, "id"))) {
22+    if (msg == NULL) {
23         srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
24 
25         srv_archive_error("activitypub_post_handler", "JSON error", req, payload);
26@@ -2096,7 +2102,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
27         return 400;
28     }
29 
30-    if (is_instance_blocked(id)) {
31+    if (id && is_instance_blocked(id)) {
32         srv_debug(1, xs_fmt("full instance block for %s", id));
33 
34         *body  = xs_str_new("blocked");
35@@ -2106,7 +2112,6 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
36 
37     /* get the user and path */
38     xs *l = xs_split_n(q_path, "/", 2);
39-    char *uid;
40 
41     if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) {
42         /* strange q_path */
43@@ -2114,7 +2119,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
44         return 404;
45     }
46 
47-    uid = xs_list_get(l, 1);
48+    const char *uid = xs_list_get(l, 1);
49     if (!user_open(&snac, uid)) {
50         /* invalid user */
51         srv_debug(1, xs_fmt("activitypub_post_handler bad user %s", uid));