Skip to content

Commit 1d9ad5d

Browse files
committed
Set max chars for meta tags
1 parent 0828ff3 commit 1d9ad5d

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
@@ -99,7 +99,10 @@ impl Default for MetaTags {
9999

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

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

0 commit comments

Comments
 (0)