brokerd: inherit parent taint for a new subagent
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -72,7 +72,9 @@ impl StateStore {
|
||||
let path = self.path(session);
|
||||
let text = match fs::read_to_string(&path) {
|
||||
Ok(text) => text,
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(SessionState::default()),
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
||||
return inherit_or_default(self, session);
|
||||
}
|
||||
Err(err) => return Err(StateError::Unreadable(path, err.to_string())),
|
||||
};
|
||||
let file = match serde_json::from_str::<StateFile>(&text) {
|
||||
@@ -140,6 +142,31 @@ impl StateStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// A missing `sub-<parent>-<n>` file copies the parent's taint and untrusted flag (M6 spec 3.4).
|
||||
fn inherit_or_default(store: &StateStore, session: &SessionId) -> Result<SessionState, StateError> {
|
||||
let Some(parent) = parent_of_sub(session) else {
|
||||
return Ok(SessionState::default());
|
||||
};
|
||||
let inherited = store.read(&parent)?;
|
||||
store.raise(
|
||||
session,
|
||||
SessionState::default(),
|
||||
Label {
|
||||
class: inherited.taint,
|
||||
untrusted: inherited.untrusted,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn parent_of_sub(session: &SessionId) -> Option<SessionId> {
|
||||
let rest = session.as_str().strip_prefix("sub-")?;
|
||||
let (parent, n) = rest.rsplit_once('-')?;
|
||||
if n.is_empty() || !n.bytes().all(|b| b.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
SessionId::new(parent).ok()
|
||||
}
|
||||
|
||||
/// One line on disk: the taint and the untrusted flag.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
Reference in New Issue
Block a user