security(agent): gate elevated MemorySource construction behind a distinct API
Two related trust-boundary gaps, both closed: 1. ConsolidationEngine::add_memory took a plain `source: MemorySource` parameter, so any caller could claim MemorySource::System/Correction — which get elevated importance weighting in score_correction — for content whose actual origin the caller doesn't control or hasn't verified. Split into add_memory(UntrustedSource) for ordinary caller-supplied content (User/Tool/Retrieval only, no elevated variant exists to claim) and add_trusted_memory(TrustedSource) for content whose elevated trust the caller has independently verified (System/ Correction). Updated the one production consumer outside this crate (clawhdf5-bench's consolidation_efficiency benchmark) and all tests. 2. The provenance/anomaly wiring added in the previous commit introduced the same pattern: infer_memory_source mapped source_channel == "system" or "correction" straight to the elevated MemorySource variants. Since MemoryEntry.source_channel is unvalidated caller-supplied text, this let a write dodge check_source_anomaly's User-flood detection by simply self-labeling source_channel = "system". infer_memory_source now never returns System/Correction — only Tool/Retrieval (recognized channel names) or User (everything else, the conservative default). INT-05
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use clawhdf5_agent::bm25::BM25Index;
|
||||
use clawhdf5_agent::consolidation::{ConsolidationConfig, ConsolidationEngine, MemorySource};
|
||||
use clawhdf5_agent::consolidation::{
|
||||
ConsolidationConfig, ConsolidationEngine, TrustedSource, UntrustedSource,
|
||||
};
|
||||
use clawhdf5_agent::hybrid::hybrid_search;
|
||||
|
||||
const EMBEDDING_DIM: usize = 384;
|
||||
@@ -232,7 +234,7 @@ fn run_quality_benchmark() {
|
||||
for i in 0..SIGNAL_KEYWORDS.len() {
|
||||
let chunk = make_signal_content(i);
|
||||
let embedding = make_embedding(i * 1000);
|
||||
let id = engine.add_memory(chunk, embedding, MemorySource::Correction, now);
|
||||
let id = engine.add_trusted_memory(chunk, embedding, TrustedSource::Correction, now);
|
||||
signal_ids.push(id);
|
||||
}
|
||||
|
||||
@@ -240,7 +242,7 @@ fn run_quality_benchmark() {
|
||||
for i in 0..990 {
|
||||
let chunk = make_noise_content(i);
|
||||
let embedding = make_embedding(i + 100);
|
||||
engine.add_memory(chunk, embedding, MemorySource::System, now + i as f64 * 0.1);
|
||||
engine.add_trusted_memory(chunk, embedding, TrustedSource::System, now + i as f64 * 0.1);
|
||||
}
|
||||
|
||||
println!(" → Inserted {} records total", engine.records().len());
|
||||
@@ -333,7 +335,7 @@ fn run_cycle_time_benchmark() {
|
||||
for i in 0..n {
|
||||
let chunk = make_noise_content(i);
|
||||
let embedding = make_embedding(i);
|
||||
engine.add_memory(chunk, embedding, MemorySource::User, now + i as f64);
|
||||
engine.add_memory(chunk, embedding, UntrustedSource::User, now + i as f64);
|
||||
}
|
||||
|
||||
// Warmup
|
||||
@@ -344,7 +346,7 @@ fn run_cycle_time_benchmark() {
|
||||
for i in n..(n * 2) {
|
||||
let chunk = make_noise_content(i);
|
||||
let embedding = make_embedding(i);
|
||||
engine.add_memory(chunk, embedding, MemorySource::User, now + i as f64);
|
||||
engine.add_memory(chunk, embedding, UntrustedSource::User, now + i as f64);
|
||||
}
|
||||
|
||||
// Timed consolidation
|
||||
@@ -410,13 +412,13 @@ fn run_memory_reduction_benchmark() {
|
||||
for i in 0..signal_count {
|
||||
let chunk = make_signal_content(i % SIGNAL_KEYWORDS.len());
|
||||
let emb = make_embedding(i * 999);
|
||||
let id = engine.add_memory(chunk, emb, MemorySource::Correction, now);
|
||||
let id = engine.add_trusted_memory(chunk, emb, TrustedSource::Correction, now);
|
||||
signal_ids.push(id);
|
||||
}
|
||||
for i in 0..noise_count {
|
||||
let chunk = make_noise_content(i);
|
||||
let emb = make_embedding(i + 200);
|
||||
engine.add_memory(chunk, emb, MemorySource::System, now + i as f64 * 0.1);
|
||||
engine.add_trusted_memory(chunk, emb, TrustedSource::System, now + i as f64 * 0.1);
|
||||
}
|
||||
|
||||
// Access signal records heavily
|
||||
|
||||
Reference in New Issue
Block a user