[core] V0.1: parse, compose, reply/forward, safe names, threading, rules + Sieve, sanitiser, search (55 tests green)

This commit is contained in:
2026-11-08 14:11:27 +01:00
parent c59480a0c0
commit e98e626c76
14 changed files with 1276 additions and 75 deletions
+93 -10
View File
@@ -9,11 +9,47 @@ fn clean(html: &str) -> String {
/// Anything executable, anything that loads something, anything that navigates by itself.
const FORBIDDEN: &[&str] = &[
"<script", "javascript:", "vbscript:", "onerror", "onload", "onclick", "onmouseover", "onfocus",
"onbegin", "ontoggle", "expression(", "<form", "<input", "<button", "<textarea", "<select",
"<meta", "http-equiv", "refresh", "<iframe", "<frame", "<object", "<embed", "<applet", "<base",
"<link", "<style", "@import", "url(", "behavior:", "-moz-binding", "<svg", "<math", "srcdoc",
"formaction", "data:text/html", "evil.example", "<template", "<noscript", "<xml", "xlink:href",
"<script",
"javascript:",
"vbscript:",
"onerror",
"onload",
"onclick",
"onmouseover",
"onfocus",
"onbegin",
"ontoggle",
"expression(",
"<form",
"<input",
"<button",
"<textarea",
"<select",
"<meta",
"http-equiv",
"refresh",
"<iframe",
"<frame",
"<object",
"<embed",
"<applet",
"<base",
"<link",
"<style",
"@import",
"url(",
"behavior:",
"-moz-binding",
"<svg",
"<math",
"srcdoc",
"formaction",
"data:text/html",
"evil.example",
"<template",
"<noscript",
"<xml",
"xlink:href",
];
const CORPUS: &[&str] = &[
@@ -98,13 +134,22 @@ fn tags(out: &str) -> Vec<(String, Vec<(String, String)>)> {
let mut end = rest.len();
loop {
while let Some(&(_, c)) = chars.peek() {
if c.is_whitespace() || c == '/' { chars.next(); } else { break; }
if c.is_whitespace() || c == '/' {
chars.next();
} else {
break;
}
}
let Some(&(i, c)) = chars.peek() else { break };
if c == '>' { end = i + 1; break; }
if c == '>' {
end = i + 1;
break;
}
let mut attr = String::new();
while let Some(&(_, c)) = chars.peek() {
if c == '=' || c == '>' || c.is_whitespace() { break; }
if c == '=' || c == '>' || c.is_whitespace() {
break;
}
attr.push(c);
chars.next();
}
@@ -114,7 +159,9 @@ fn tags(out: &str) -> Vec<(String, Vec<(String, String)>)> {
if let Some(&(_, '"')) = chars.peek() {
chars.next();
for (_, c) in chars.by_ref() {
if c == '"' { break; }
if c == '"' {
break;
}
value.push(c);
}
}
@@ -140,9 +187,45 @@ fn dangerous(out: &str) -> Option<String> {
}
let compact: String = value.chars().filter(|c| !c.is_whitespace() && !c.is_control()).collect();
let compact = compact.to_ascii_lowercase();
if compact.starts_with("javascript:") || compact.starts_with("vbscript:") || compact.starts_with("data:text") {
let url_attribute = matches!(
attr.as_str(),
"href"
| "src"
| "action"
| "formaction"
| "background"
| "poster"
| "data"
| "srcset"
| "lowsrc"
| "dynsrc"
| "cite"
| "xlink:href"
| "longdesc"
| "usemap"
| "codebase"
);
if url_attribute
&& (compact.starts_with("javascript:")
|| compact.starts_with("vbscript:")
|| compact.starts_with("data:text"))
{
return Some(format!("url in {attr}"));
}
if attr == "style"
&& ["expression", "url(", "javascript", "@import", "behavior", "binding"]
.iter()
.any(|b| compact.contains(b))
{
return Some("css".into());
}
if url_attribute
&& attr != "href"
&& (compact.starts_with("http:") || compact.starts_with("https:"))
&& !compact.contains("cdn.example")
{
return Some(format!("remote load in {attr}"));
}
}
}
None