MCPcopy Create free account
hub / github.com/base/base / validate_value

Method validate_value

acceptance/src/report.rs:706–735  ·  view source on GitHub ↗

Validates bounds and credential patterns recursively in JSON display data.

(value: &Value, depth: usize)

Source from the content-addressed store, hash-verified

704
705 /// Validates bounds and credential patterns recursively in JSON display data.
706 pub fn validate_value(value: &Value, depth: usize) -> Result<()> {
707 if depth > 20 {
708 bail!("JSON value nesting exceeds 20");
709 }
710 match value {
711 Value::String(v) => {
712 Self::bounded("JSON string", v, 65_536)?;
713 Self::reject_secret("JSON string", v)?;
714 }
715 Value::Array(values) => {
716 if values.len() > 10_000 {
717 bail!("JSON array too large");
718 }
719 for v in values {
720 Self::validate_value(v, depth + 1)?;
721 }
722 }
723 Value::Object(values) => {
724 if values.len() > 1_000 {
725 bail!("JSON object too large");
726 }
727 for (k, v) in values {
728 Self::bounded("JSON key", k, 200)?;
729 Self::validate_value(v, depth + 1)?;
730 }
731 }
732 _ => {}
733 }
734 Ok(())
735 }
736}
737
738#[cfg(test)]

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected