Call sanitize() as soon as possible.

This commit is contained in:
default 2022-11-16 13:13:31 +01:00
parent 45584746d0
commit 236ca9af6b
3 changed files with 7 additions and 9 deletions

View file

@ -87,7 +87,7 @@ static d_char *format_line(const char *line)
} }
d_char *not_really_markdown(char *content) d_char *not_really_markdown(const char *content)
/* formats a content using some Markdown rules */ /* formats a content using some Markdown rules */
{ {
d_char *s = xs_str_new(NULL); d_char *s = xs_str_new(NULL);
@ -164,11 +164,11 @@ d_char *not_really_markdown(char *content)
const char *valid_tags[] = { const char *valid_tags[] = {
"a", "p", "br", "br/", "img", "blockquote", "ul", "li", "a", "p", "br", "br/", "blockquote", "ul", "li",
"span", "i", "b", "pre", "code", "em", "strong", NULL "span", "i", "b", "pre", "code", "em", "strong", NULL
}; };
d_char *sanitize(d_char *content) d_char *sanitize(const char *content)
/* cleans dangerous HTML output */ /* cleans dangerous HTML output */
{ {
d_char *s = xs_str_new(NULL); d_char *s = xs_str_new(NULL);

6
html.c
View file

@ -627,7 +627,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
} }
{ {
xs *c = xs_dup(xs_dict_get(msg, "content")); xs *c = sanitize(xs_dict_get(msg, "content"));
char *p, *v; char *p, *v;
/* do some tweaks to the content */ /* do some tweaks to the content */
@ -663,9 +663,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
} }
} }
xs *sc = sanitize(c); s = xs_str_cat(s, c);
s = xs_str_cat(s, sc);
} }
s = xs_str_cat(s, "\n"); s = xs_str_cat(s, "\n");

4
snac.h
View file

@ -135,8 +135,8 @@ int activitypub_post_handler(d_char *req, char *q_path,
char *payload, int p_size, char *payload, int p_size,
char **body, int *b_size, char **ctype); char **body, int *b_size, char **ctype);
d_char *not_really_markdown(char *content); d_char *not_really_markdown(const char *content);
d_char *sanitize(d_char *str); d_char *sanitize(const char *str);
int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype); int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype);
int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,