Skip to content

Commit d7fc823

Browse files
committed
Set max chars for meta tags
1 parent 3fe97fa commit d7fc823

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

server/src/handlers/single_page_app.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ impl Default for MetaTags {
100100

101101
impl Display for MetaTags {
102102
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
103-
let description = escape_html(&self.description);
103+
let description = escape_html(&self.description)
104+
.chars()
105+
.take(250)
106+
.collect::<String>();
104107
let image = &self.image;
105108
let title = escape_html(&self.title);
106109

@@ -116,6 +119,8 @@ impl Display for MetaTags {
116119
<meta property=\"twitter:image\" content=\"{image}\">"
117120
)?;
118121
if let Some(json_unsafe) = &self.json {
122+
// If we would serialize plain JSON in HTML,
123+
// users might escape the HTML tag and execute arbitrary code.
119124
let json_base64 = base64::encode(json_unsafe);
120125
write!(
121126
f,

0 commit comments

Comments
 (0)