fix(anatomy): R5.3 __proto__ field segments refused, seed identity guard over the whole seed tree, hashed id comparisons
This commit is contained in:
1 parent
3ece1a64b1
commit
f245b3ec25
7 files changed
+86
-33
No files matched your search
@@ -101,6 +101,13 @@ pub fn split_field(field: &str) -> Result<Vec<&str>, PipelineError> {
|
||||
if let Some(key) = path.iter().find(|key| key.starts_with('\0')) {
|
||||
return Err(fail(format!("reserved key {key:?} in field \"{field}\"")));
|
||||
}
|
||||
// A JavaScript assignment through `__proto__` never wrote a key: it set a prototype,
|
||||
// polluted `Object.prototype` or did nothing. No faithful reading exists, so it is refused.
|
||||
if path.contains(&"__proto__") {
|
||||
return Err(fail(format!(
|
||||
"reserved key \"__proto__\" in field \"{field}\""
|
||||
)));
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
//! its target, edits the working document in place and records what it changed; anything it
|
||||
//! cannot do exactly as written refuses (the applier adds the change id and op index).
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use super::fields::{FieldKind, is_settable, read_field, write_field};
|
||||
@@ -353,7 +355,7 @@ fn apply_move(
|
||||
|
||||
/// Every cited id must be declared in the document references.
|
||||
pub fn assert_declared(doc: &Value, ids: &[String]) -> Result<(), PipelineError> {
|
||||
let declared: Vec<&str> = list_at(doc, &top_collection_path(TargetKind::Reference))?
|
||||
let declared: HashSet<&str> = list_at(doc, &top_collection_path(TargetKind::Reference))?
|
||||
.iter()
|
||||
.filter_map(|reference| reference.get("id").and_then(Value::as_str))
|
||||
.collect();
|
||||
@@ -373,13 +375,8 @@ pub fn assert_declared(doc: &Value, ids: &[String]) -> Result<(), PipelineError>
|
||||
|
||||
/// `[...new Set(ids)]`: first occurrences, in order.
|
||||
fn distinct(ids: &[String]) -> Vec<&String> {
|
||||
let mut out: Vec<&String> = Vec::new();
|
||||
for id in ids {
|
||||
if !out.contains(&id) {
|
||||
out.push(id);
|
||||
}
|
||||
}
|
||||
out
|
||||
let mut seen: HashSet<&str> = HashSet::new();
|
||||
ids.iter().filter(|id| seen.insert(id.as_str())).collect()
|
||||
}
|
||||
|
||||
/// Appends citations in order, never twice on the same item.
|
||||
|
||||
@@ -367,16 +367,8 @@ fn non_negative_int<'de, D: serde::Deserializer<'de>>(d: D) -> Result<u64, D::Er
|
||||
}
|
||||
|
||||
fn duplicates<'a>(ids: impl Iterator<Item = &'a str>) -> Vec<&'a str> {
|
||||
let mut seen: Vec<&str> = Vec::new();
|
||||
let mut repeated = Vec::new();
|
||||
for id in ids {
|
||||
if seen.contains(&id) {
|
||||
repeated.push(id);
|
||||
} else {
|
||||
seen.push(id);
|
||||
}
|
||||
}
|
||||
repeated
|
||||
let mut seen: std::collections::HashSet<&str> = std::collections::HashSet::new();
|
||||
ids.filter(|id| !seen.insert(id)).collect()
|
||||
}
|
||||
|
||||
fn refuse(file: &str, error: impl std::fmt::Display) -> PipelineError {
|
||||
|
||||
Reference in new issue
Block a user