瀏覽代碼

Merge pull request #601 from kellda/escape-brackets

Escape `<`, `>` and `&` to avoid type parameters being parsed as HTML
Mark Rousskov 4 年之前
父節點
當前提交
811bda4aa6
共有 1 個文件被更改,包括 15 次插入2 次删除
  1. 15 2
      src/notification_listing.rs

+ 15 - 2
src/notification_listing.rs

@@ -27,10 +27,23 @@ pub async fn render(db: &DbClient, user: &str) -> String {
             notification
                 .short_description
                 .as_ref()
-                .unwrap_or(&notification.origin_url),
+                .unwrap_or(&notification.origin_url)
+                .replace('&', "&amp;")
+                .replace('<', "&lt;")
+                .replace('>', "&gt;")
+                .replace('"', "&quot;")
+                .replace('\'', "&#39;"),
         ));
         if let Some(metadata) = &notification.metadata {
-            out.push_str(&format!("<ul><li>{}</li></ul>", metadata));
+            out.push_str(&format!(
+                "<ul><li>{}</li></ul>",
+                metadata
+                    .replace('&', "&amp;")
+                    .replace('<', "&lt;")
+                    .replace('>', "&gt;")
+                    .replace('"', "&quot;")
+                    .replace('\'', "&#39;"),
+            ));
         }
         out.push_str("</li>");
     }