diff --git a/format.c b/format.c index 7117e48..cfe2294 100644 --- a/format.c +++ b/format.c @@ -260,7 +260,7 @@ xs_str *sanitize(const char *content) } -xs_str *encode_html(const char *str) +xs_str *encode_html_strict(const char *str) /* escapes html characters */ { xs_str *encoded = xs_replace(str, "&", "&"); @@ -269,6 +269,15 @@ xs_str *encode_html(const char *str) encoded = xs_replace_i(encoded, "\"", """); encoded = xs_replace_i(encoded, "'", "'"); + return encoded; +} + + +xs_str *encode_html(const char *str) +/* escapes html characters */ +{ + xs_str *encoded = encode_html_strict(str); + /* Restore only
. Probably safe. Let's hope nothing goes wrong with this. */ encoded = xs_replace_i(encoded, "<br>", "
"); diff --git a/html.c b/html.c index 58319c6..175a214 100644 --- a/html.c +++ b/html.c @@ -2075,10 +2075,10 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); char *p, *v; - xs *es1 = encode_html(xs_dict_get(snac.config, "name")); - xs *es2 = encode_html(snac.uid); - xs *es3 = encode_html(xs_dict_get(srv_config, "host")); - xs *es4 = encode_html(bio); + xs *es1 = encode_html_strict(xs_dict_get(snac.config, "name")); + xs *es2 = encode_html_strict(snac.uid); + xs *es3 = encode_html_strict(xs_dict_get(srv_config, "host")); + xs *es4 = encode_html_strict(bio); rss = xs_fmt( "\n" "\n" @@ -2106,7 +2106,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, if (!xs_startswith(id, snac.actor)) continue; - xs *content = sanitize(xs_dict_get(msg, "content")); + xs *content = encode_html_strict(xs_dict_get(msg, "content")); // We SHOULD only use sanitized one for description. // 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, xs *title = xs_str_new(NULL); int i; - for (i = 0; es_title[i] && es_title[i] != '\n' && i < 50; i++) + for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++) title = xs_append_m(title, &es_title[i], 1); xs *s = xs_fmt( diff --git a/snac.h b/snac.h index 7cf3d7e..5bb5ecb 100644 --- a/snac.h +++ b/snac.h @@ -262,6 +262,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, xs_str *not_really_markdown(const char *content, xs_list **attach); xs_str *sanitize(const char *content); +xs_str *encode_html_strict(const char *str); xs_str *encode_html(const char *str); xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more);