fix(anatomy): V1-2.2 read url() references in their strict spelling only
Security review BLOCK(1): url(#%61) passed the dangling check and the per-view scoping and resolved in browsers. One strict reading now, other spellings are active content; glued names are other functions; the composer refuses an unscoped reference; owner export procedure.
This commit is contained in:
1 parent
5281337412
commit
a678faaa23
13 files changed
+553
-70
No files matched your search
@@ -274,3 +274,71 @@ fn composition_is_deterministic_and_repeatable() {
|
||||
);
|
||||
assert_eq!(preview.drawing_reads(), 2);
|
||||
}
|
||||
|
||||
/// Every reference of `text` as a browser reads it, written apart from the core's reader:
|
||||
/// each `href="…"` and each `url(…)` (any case), quotes and CSS whitespace trimmed, tab and
|
||||
/// newline removed and `%XX` decoded as the URL parser does. Answers the fragment ids.
|
||||
fn browser_references(text: &str) -> Vec<String> {
|
||||
let normalise = |raw: &str| {
|
||||
let trimmed = raw.trim_matches(|c: char| c.is_ascii_whitespace() || c == '\'' || c == '"');
|
||||
let cleaned: String = trimmed
|
||||
.chars()
|
||||
.filter(|c| !matches!(c, '\t' | '\n' | '\r'))
|
||||
.collect();
|
||||
let mut bytes = Vec::new();
|
||||
let raw = cleaned.as_bytes();
|
||||
let mut i = 0;
|
||||
while i < raw.len() {
|
||||
let hex = raw
|
||||
.get(i + 1..i + 3)
|
||||
.and_then(|h| std::str::from_utf8(h).ok());
|
||||
match (raw[i], hex.and_then(|h| u8::from_str_radix(h, 16).ok())) {
|
||||
(b'%', Some(byte)) => {
|
||||
bytes.push(byte);
|
||||
i += 3;
|
||||
}
|
||||
(byte, _) => {
|
||||
bytes.push(byte);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
String::from_utf8_lossy(&bytes).into_owned()
|
||||
};
|
||||
let mut out = Vec::new();
|
||||
for (index, _) in text.match_indices("href=\"") {
|
||||
let rest = &text[index + 6..];
|
||||
out.push(normalise(&rest[..rest.find('"').unwrap()]));
|
||||
}
|
||||
let lower = text.to_ascii_lowercase();
|
||||
for (index, _) in lower.match_indices("url(") {
|
||||
let rest = &text[index + 4..];
|
||||
out.push(normalise(&rest[..rest.find(')').unwrap_or(rest.len())]));
|
||||
}
|
||||
out.into_iter()
|
||||
.map(|reference| reference.strip_prefix('#').unwrap_or(&reference).to_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_reference_a_browser_reads_stays_in_its_view() {
|
||||
let preview = preview(&detail_drawing());
|
||||
for view in ["main", "detail"] {
|
||||
let text = canvas(&preview, view);
|
||||
let references = browser_references(&text);
|
||||
assert!(references.len() >= 2, "{view}");
|
||||
for reference in references {
|
||||
assert!(
|
||||
reference.starts_with(&format!("fv.{view}.")),
|
||||
"{view}: {reference}"
|
||||
);
|
||||
}
|
||||
}
|
||||
// The hostile spellings never reach a canvas: the drawing is refused, nothing composed.
|
||||
for value in ["url(#%66v.main.g)", "url(\'#\tg\')", "url(#%67)"] {
|
||||
let hostile =
|
||||
format!("{OPEN}<radialGradient id=\"g\"/><path fill=\"{value}\" d=\"M0 0\"/></svg>");
|
||||
let refused = canvas_outcome(&self::preview(&hostile), "detail");
|
||||
assert_eq!(refused["kind"], json!("svg_rejected"), "{value}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user