The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(skills): add integrity check for bundled skill materialization
Steven Enamakeld75f3683ab06
diff --git a/src/openhuman/skills/bundled/mod.rs b/src/openhuman/skills/bundled/mod.rsindex 8a88a81943..462f70aa81 100644--- a/src/openhuman/skills/bundled/mod.rs+++ b/src/openhuman/skills/bundled/mod.rs@@ -225,6 +225,58 @@ pub fn install_bundled_skills(workspace_dir: &Path) {let _ = install(workspace_dir);}+/// Whether `dir` contains exactly the bytes compiled for `skill`.+///+/// Discovery must not trust the sidecar alone: a user who can modify the+/// materialised directory must not be able to turn arbitrary instructions into+/// a `Builtin` workflow. Check every compiled file and reject extra entries,+/// symlinks, and non-regular files.+pub fn is_current_materialization(dir: &Path, skill: &BundledSkill) -> bool {+ if skill.validate().is_err() || !dir.is_dir() {+ return false;+ }+ let expected: std::collections::HashSet<&str> = skill.files.iter().map(|f| f.path).collect();+ for file in skill.files {+ let path = dir.join(file.path);+ let Ok(meta) = std::fs::symlink_metadata(&path) else {+ return false;+ };+ if !meta.is_file() || meta.file_type().is_symlink() {+ return false;+ }+ let Ok(contents) = std::fs::read(&path) else {+ return false;+ };+ if contents != file.contents.as_bytes() {+ return false;+ }+ }+ let mut stack = vec![dir.to_path_buf()];+ while let Some(current) = stack.pop() {+ let Ok(entries) = std::fs::read_dir(¤t) else {+ return false;+ };+ for entry in entries.flatten() {+ let Ok(meta) = entry symlink_metadata() else {+ return false;+ };+ let Ok(relative) = entry.path().strip_prefix(dir) else {+ return false;+ };+ let relative = relative.to_string_lossy().replace('\\', "/");+ if meta.file_type().is_symlink() || (!meta.is_dir() && !meta.is_file()) {+ return false;+ }+ if meta.is_dir() {+ stack.push(entry.path());+ } else if !expected.contains(relative.as_str()) {+ return false;+ }+ }+ }+ true+}+/// Returns `Ok(true)` when the bundle was (re)written, `Ok(false)` when the/// on-disk copy was already current.fn install_one(root: &Path, skill: &BundledSkill) -> Result<bool, String> {diff --git a/src/openhuman/skills/ops_discover.rs b/src/openhuman/skills/ops_discover.rsindex 17b3ed3374..e0f1b4f186 100644--- a/src/openhuman/skills/ops_discover.rs+++ b/src/openhuman/skills/ops_discover.rs@@ -239,7 +239,10 @@ fn discover_filtered(scope = ?WorkflowScope::Builtin,"[workflows] discover:branch:builtin");- absorb(&mut by_name, scan_root(&root, WorkflowScope::Builtin));+ absorb(+ &mut by_name,+ scan_bundled_root(&root, WorkflowScope::Builtin),+ );}}@@ -319,6 +322,19 @@ fn discover_filtered(out}+fn scan_bundled_root(root: &Path, scope: WorkflowScope) -> Vec<Workflow> {+ let mut out = Vec::new();+ for bundled in crate::openhuman::skills::bundled::BUNDLED {+ let dir = root.join(bundled.dir_name);+ if crate::openhuman::skills::bundled::is_current_materialization(&dir, bundled) {+ if let Some(workflow) = load_skill_dir(&dir, bundled.dir_name, scope) {+ out.push(workflow);+ }+ }+ }+ out+}+fn user_roots(home: &Path) -> Vec<(PathBuf, RootKind)> {// `workflows/` is the current layout (create writes here); the `skills/`// roots are still scanned for back-compat with installs created before thediff --git a/src/openhuman/skills/tools.rs b/src/openhuman/skills/tools.rsindex 313dee62d1..e71bc6bf2f 100644--- a/src/openhuman/skills/tools.rs+++ b/src/openhuman/skills/tools.rs@@ -90,9 +90,13 @@ pub(super) fn is_builtin_skill(skill_id: &str) -> bool {fn skill_allowed_including_profile(allowlist: &SkillAllowlist,profile_local_ids: &std::collections::HashSet<String>,+ workspace_dir: &Path,+ profile_skills_root: Option<&Path>,skill_id: &str,) -> bool {- is_builtin_skill(skill_id)+ let resolved_scope = get_workflow_with_profile(workspace_dir, skill_id, profile_skills_root)+ .map(|workflow| workflow.scope);+ matches!(resolved_scope, Some(WorkflowScope::Builtin))|| profile_local_ids.contains(skill_id)|| skill_allowed(allowlist, skill_id)}