diff options
| author | 2024-10-19 18:29:58 +0200 | |
|---|---|---|
| committer | 2024-10-19 18:29:58 +0200 | |
| commit | bfb6c26f62b0306809d200d99ff24241ec4f203d (patch) | |
| tree | 7826e8a4f0dcbcb896b6688f2168fc9b6241495a | |
| parent | Tweaked HTML for the timeline pages. (diff) | |
| download | penes-snac2-bfb6c26f62b0306809d200d99ff24241ec4f203d.tar.gz penes-snac2-bfb6c26f62b0306809d200d99ff24241ec4f203d.tar.xz penes-snac2-bfb6c26f62b0306809d200d99ff24241ec4f203d.zip | |
Added some checks.
| -rw-r--r-- | activitypub.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c index 66d7f10..0a4419d 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1772,7 +1772,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1772 | if (xs_type(obj_id) == XSTYPE_DICT) | 1772 | if (xs_type(obj_id) == XSTYPE_DICT) |
| 1773 | obj_id = xs_dict_get(obj_id, "id"); | 1773 | obj_id = xs_dict_get(obj_id, "id"); |
| 1774 | 1774 | ||
| 1775 | if (!object_here(obj_id)) { | 1775 | if (xs_is_null(obj_id) || !object_here(obj_id)) { |
| 1776 | srv_debug(1, xs_fmt("dropped 'Delete' message from unknown object '%s'", obj_id)); | 1776 | srv_debug(1, xs_fmt("dropped 'Delete' message from unknown object '%s'", obj_id)); |
| 1777 | return -1; | 1777 | return -1; |
| 1778 | } | 1778 | } |
| @@ -1871,6 +1871,12 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1871 | } | 1871 | } |
| 1872 | 1872 | ||
| 1873 | if (strcmp(type, "Follow") == 0) { /** **/ | 1873 | if (strcmp(type, "Follow") == 0) { /** **/ |
| 1874 | const char *id = xs_dict_get(msg, "id"); | ||
| 1875 | |||
| 1876 | if (xs_is_null(id)) { | ||
| 1877 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 1878 | } | ||
| 1879 | else | ||
| 1874 | if (!follower_check(snac, actor)) { | 1880 | if (!follower_check(snac, actor)) { |
| 1875 | /* ensure the actor object is here */ | 1881 | /* ensure the actor object is here */ |
| 1876 | if (!object_here(actor)) { | 1882 | if (!object_here(actor)) { |
| @@ -1890,7 +1896,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1890 | f_msg = xs_dict_set(f_msg, "published", date); | 1896 | f_msg = xs_dict_set(f_msg, "published", date); |
| 1891 | } | 1897 | } |
| 1892 | 1898 | ||
| 1893 | timeline_add(snac, xs_dict_get(f_msg, "id"), f_msg); | 1899 | timeline_add(snac, id, f_msg); |
| 1894 | 1900 | ||
| 1895 | follower_add(snac, actor); | 1901 | follower_add(snac, actor); |
| 1896 | 1902 | ||
| @@ -1988,6 +1994,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1988 | if (strcmp(utype, "Question") == 0) { /** **/ | 1994 | if (strcmp(utype, "Question") == 0) { /** **/ |
| 1989 | const char *id = xs_dict_get(object, "id"); | 1995 | const char *id = xs_dict_get(object, "id"); |
| 1990 | 1996 | ||
| 1997 | if (xs_is_null(id)) | ||
| 1998 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 1999 | else | ||
| 1991 | if (timeline_add(snac, id, object)) | 2000 | if (timeline_add(snac, id, object)) |
| 1992 | snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id)); | 2001 | snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id)); |
| 1993 | } | 2002 | } |
| @@ -1995,6 +2004,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1995 | if (strcmp(utype, "Video") == 0) { /** **/ | 2004 | if (strcmp(utype, "Video") == 0) { /** **/ |
| 1996 | const char *id = xs_dict_get(object, "id"); | 2005 | const char *id = xs_dict_get(object, "id"); |
| 1997 | 2006 | ||
| 2007 | if (xs_is_null(id)) | ||
| 2008 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 2009 | else | ||
| 1998 | if (timeline_add(snac, id, object)) | 2010 | if (timeline_add(snac, id, object)) |
| 1999 | snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id)); | 2011 | snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id)); |
| 2000 | } | 2012 | } |
| @@ -2037,10 +2049,13 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2037 | if (xs_type(object) == XSTYPE_DICT) | 2049 | if (xs_type(object) == XSTYPE_DICT) |
| 2038 | object = xs_dict_get(object, "id"); | 2050 | object = xs_dict_get(object, "id"); |
| 2039 | 2051 | ||
| 2052 | if (xs_is_null(object)) | ||
| 2053 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 2054 | else | ||
| 2040 | if (timeline_admire(snac, object, actor, 1) == HTTP_STATUS_CREATED) | 2055 | if (timeline_admire(snac, object, actor, 1) == HTTP_STATUS_CREATED) |
| 2041 | snac_log(snac, xs_fmt("new '%s' %s %s", type, actor, object)); | 2056 | snac_log(snac, xs_fmt("new '%s' %s %s", type, actor, object)); |
| 2042 | else | 2057 | else |
| 2043 | snac_log(snac, xs_fmt("repeated 'Like' from %s to %s", actor, object)); | 2058 | snac_log(snac, xs_fmt("repeated '%s' from %s to %s", type, actor, object)); |
| 2044 | 2059 | ||
| 2045 | do_notify = 1; | 2060 | do_notify = 1; |
| 2046 | } | 2061 | } |
| @@ -2049,6 +2064,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2049 | if (xs_type(object) == XSTYPE_DICT) | 2064 | if (xs_type(object) == XSTYPE_DICT) |
| 2050 | object = xs_dict_get(object, "id"); | 2065 | object = xs_dict_get(object, "id"); |
| 2051 | 2066 | ||
| 2067 | if (xs_is_null(object)) | ||
| 2068 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 2069 | else | ||
| 2052 | if (is_muted(snac, actor) && !xs_startswith(object, snac->actor)) | 2070 | if (is_muted(snac, actor) && !xs_startswith(object, snac->actor)) |
| 2053 | snac_log(snac, xs_fmt("dropped 'Announce' from muted actor %s", actor)); | 2071 | snac_log(snac, xs_fmt("dropped 'Announce' from muted actor %s", actor)); |
| 2054 | else | 2072 | else |
| @@ -2101,6 +2119,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2101 | if (xs_match(utype, "Note|Page|Article|Video")) { /** **/ | 2119 | if (xs_match(utype, "Note|Page|Article|Video")) { /** **/ |
| 2102 | const char *id = xs_dict_get(object, "id"); | 2120 | const char *id = xs_dict_get(object, "id"); |
| 2103 | 2121 | ||
| 2122 | if (xs_is_null(id)) | ||
| 2123 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 2124 | else | ||
| 2104 | if (object_here(id)) { | 2125 | if (object_here(id)) { |
| 2105 | object_add_ow(id, object); | 2126 | object_add_ow(id, object); |
| 2106 | timeline_touch(snac); | 2127 | timeline_touch(snac); |
| @@ -2115,13 +2136,17 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2115 | const char *id = xs_dict_get(object, "id"); | 2136 | const char *id = xs_dict_get(object, "id"); |
| 2116 | const char *closed = xs_dict_get(object, "closed"); | 2137 | const char *closed = xs_dict_get(object, "closed"); |
| 2117 | 2138 | ||
| 2118 | object_add_ow(id, object); | 2139 | if (xs_is_null(id)) |
| 2119 | timeline_touch(snac); | 2140 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); |
| 2141 | else { | ||
| 2142 | object_add_ow(id, object); | ||
| 2143 | timeline_touch(snac); | ||
| 2120 | 2144 | ||
| 2121 | snac_log(snac, xs_fmt("%s poll %s", closed == NULL ? "updated" : "closed", id)); | 2145 | snac_log(snac, xs_fmt("%s poll %s", closed == NULL ? "updated" : "closed", id)); |
| 2122 | 2146 | ||
| 2123 | if (closed != NULL) | 2147 | if (closed != NULL) |
| 2124 | do_notify = 1; | 2148 | do_notify = 1; |
| 2149 | } | ||
| 2125 | } | 2150 | } |
| 2126 | else { | 2151 | else { |
| 2127 | srv_archive_error("unsupported_update", "unsupported_update", req, msg); | 2152 | srv_archive_error("unsupported_update", "unsupported_update", req, msg); |
| @@ -2134,6 +2159,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2134 | if (xs_type(object) == XSTYPE_DICT) | 2159 | if (xs_type(object) == XSTYPE_DICT) |
| 2135 | object = xs_dict_get(object, "id"); | 2160 | object = xs_dict_get(object, "id"); |
| 2136 | 2161 | ||
| 2162 | if (xs_is_null(object)) | ||
| 2163 | snac_log(snac, xs_fmt("malformed message: no 'id' field")); | ||
| 2164 | else | ||
| 2137 | if (object_here(object)) { | 2165 | if (object_here(object)) { |
| 2138 | timeline_del(snac, object); | 2166 | timeline_del(snac, object); |
| 2139 | snac_debug(snac, 1, xs_fmt("new 'Delete' %s %s", actor, object)); | 2167 | snac_debug(snac, 1, xs_fmt("new 'Delete' %s %s", actor, object)); |
| @@ -2147,11 +2175,15 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2147 | } | 2175 | } |
| 2148 | else | 2176 | else |
| 2149 | if (strcmp(type, "Ping") == 0) { /** **/ | 2177 | if (strcmp(type, "Ping") == 0) { /** **/ |
| 2178 | const char *id = xs_dict_get(msg, "id"); | ||
| 2179 | |||
| 2150 | snac_log(snac, xs_fmt("'Ping' requested from %s", actor)); | 2180 | snac_log(snac, xs_fmt("'Ping' requested from %s", actor)); |
| 2151 | 2181 | ||
| 2152 | xs *rsp = msg_pong(snac, actor, xs_dict_get(msg, "id")); | 2182 | if (!xs_is_null(id)) { |
| 2183 | xs *rsp = msg_pong(snac, actor, id); | ||
| 2153 | 2184 | ||
| 2154 | enqueue_output_by_actor(snac, rsp, actor, 0); | 2185 | enqueue_output_by_actor(snac, rsp, actor, 0); |
| 2186 | } | ||
| 2155 | } | 2187 | } |
| 2156 | else | 2188 | else |
| 2157 | if (strcmp(type, "Block") == 0) { /** **/ | 2189 | if (strcmp(type, "Block") == 0) { /** **/ |