diff options
| -rw-r--r-- | format.c | 11 | ||||
| -rw-r--r-- | html.c | 12 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 17 insertions, 7 deletions
| @@ -260,7 +260,7 @@ xs_str *sanitize(const char *content) | |||
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | 262 | ||
| 263 | xs_str *encode_html(const char *str) | 263 | xs_str *encode_html_strict(const char *str) |
| 264 | /* escapes html characters */ | 264 | /* escapes html characters */ |
| 265 | { | 265 | { |
| 266 | xs_str *encoded = xs_replace(str, "&", "&"); | 266 | xs_str *encoded = xs_replace(str, "&", "&"); |
| @@ -269,6 +269,15 @@ xs_str *encode_html(const char *str) | |||
| 269 | encoded = xs_replace_i(encoded, "\"", """); | 269 | encoded = xs_replace_i(encoded, "\"", """); |
| 270 | encoded = xs_replace_i(encoded, "'", "'"); | 270 | encoded = xs_replace_i(encoded, "'", "'"); |
| 271 | 271 | ||
| 272 | return encoded; | ||
| 273 | } | ||
| 274 | |||
| 275 | |||
| 276 | xs_str *encode_html(const char *str) | ||
| 277 | /* escapes html characters */ | ||
| 278 | { | ||
| 279 | xs_str *encoded = encode_html_strict(str); | ||
| 280 | |||
| 272 | /* Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. */ | 281 | /* Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. */ |
| 273 | encoded = xs_replace_i(encoded, "<br>", "<br>"); | 282 | encoded = xs_replace_i(encoded, "<br>", "<br>"); |
| 274 | 283 | ||
| @@ -2075,10 +2075,10 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2075 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); | 2075 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); |
| 2076 | char *p, *v; | 2076 | char *p, *v; |
| 2077 | 2077 | ||
| 2078 | xs *es1 = encode_html(xs_dict_get(snac.config, "name")); | 2078 | xs *es1 = encode_html_strict(xs_dict_get(snac.config, "name")); |
| 2079 | xs *es2 = encode_html(snac.uid); | 2079 | xs *es2 = encode_html_strict(snac.uid); |
| 2080 | xs *es3 = encode_html(xs_dict_get(srv_config, "host")); | 2080 | xs *es3 = encode_html_strict(xs_dict_get(srv_config, "host")); |
| 2081 | xs *es4 = encode_html(bio); | 2081 | xs *es4 = encode_html_strict(bio); |
| 2082 | rss = xs_fmt( | 2082 | rss = xs_fmt( |
| 2083 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 2083 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 2084 | "<rss version=\"0.91\">\n" | 2084 | "<rss version=\"0.91\">\n" |
| @@ -2106,7 +2106,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2106 | if (!xs_startswith(id, snac.actor)) | 2106 | if (!xs_startswith(id, snac.actor)) |
| 2107 | continue; | 2107 | continue; |
| 2108 | 2108 | ||
| 2109 | xs *content = sanitize(xs_dict_get(msg, "content")); | 2109 | xs *content = encode_html_strict(xs_dict_get(msg, "content")); |
| 2110 | 2110 | ||
| 2111 | // We SHOULD only use sanitized one for description. | 2111 | // We SHOULD only use sanitized one for description. |
| 2112 | // So, only encode for feed title, while the description just keep it sanitized as is. | 2112 | // So, only encode for feed title, while the description just keep it sanitized as is. |
| @@ -2115,7 +2115,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2115 | xs *title = xs_str_new(NULL); | 2115 | xs *title = xs_str_new(NULL); |
| 2116 | int i; | 2116 | int i; |
| 2117 | 2117 | ||
| 2118 | for (i = 0; es_title[i] && es_title[i] != '\n' && i < 50; i++) | 2118 | for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++) |
| 2119 | title = xs_append_m(title, &es_title[i], 1); | 2119 | title = xs_append_m(title, &es_title[i], 1); |
| 2120 | 2120 | ||
| 2121 | xs *s = xs_fmt( | 2121 | xs *s = xs_fmt( |
| @@ -262,6 +262,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, | |||
| 262 | 262 | ||
| 263 | xs_str *not_really_markdown(const char *content, xs_list **attach); | 263 | xs_str *not_really_markdown(const char *content, xs_list **attach); |
| 264 | xs_str *sanitize(const char *content); | 264 | xs_str *sanitize(const char *content); |
| 265 | xs_str *encode_html_strict(const char *str); | ||
| 265 | xs_str *encode_html(const char *str); | 266 | xs_str *encode_html(const char *str); |
| 266 | 267 | ||
| 267 | xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more); | 268 | xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more); |