* claim: #11362 * Settings profiles: export and import go through vfs, inside an agent's folders (#11362) settings.profile.export and settings.profile.import read and wrote their path with std::fs, so the folder scope an MCP request's allow_paths sets up never saw it: an agent could write a profile anywhere, or probe any path. Both now go through vfs (len, read_to_string, write), as file.export and ui.screenshot do. requests_with_allow_paths_stay_inside_them covers export and import inside and outside the agent's folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: thocsmith <193096300+thocsmith@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+17
-4
No files matched your search
@@ -2635,12 +2635,23 @@ mod tests {
|
||||
assert_eq!(call("ui.render", json!({"path": at(&root, "a.png"), "width": 32, "height": 32}), true)["ok"], true);
|
||||
}
|
||||
assert_eq!(call("ui.screenshot", json!({"path": at(&root, "b.png")}), true)["ok"], true);
|
||||
// Settings profiles are read and written by the app, not the engine, and stay inside too (#11362).
|
||||
let profile = |id: &str, params: Value| json!({"command": id, "params": params});
|
||||
let poc = json!({"format": "solidcraft-profile/1", "name": "scope-poc"});
|
||||
assert_eq!(call("engine.execute", profile("settings.profile.import", json!({"profile": poc})), true)["ok"], true);
|
||||
let inside = json!({"name": "scope-poc", "path": at(&root, "p.json")});
|
||||
assert_eq!(call("engine.execute", profile("settings.profile.export", inside), true)["ok"], true);
|
||||
assert_eq!(call("engine.execute", profile("settings.profile.import", json!({"path": at(&root, "p.json")})), true)["ok"], true);
|
||||
std::fs::write(at(&base, "p.json"), poc.to_string()).unwrap();
|
||||
for (method, params) in [
|
||||
("engine.execute", export(at(&out, "a.step"))),
|
||||
("engine.execute", export(at(&root, "../out/a.step"))),
|
||||
("engine.script", json!({"commands": [{"command": "file.export", "params": {"path": at(&out, "a.step")}}]})),
|
||||
("ui.render", json!({"path": at(&out, "a.png"), "width": 32, "height": 32})),
|
||||
("ui.screenshot", json!({"path": at(&out, "b.png")})),
|
||||
("engine.execute", profile("settings.profile.export", json!({"name": "scope-poc", "path": at(&out, "p.json")}))),
|
||||
("engine.execute", profile("settings.profile.import", json!({"path": at(&base, "p.json")}))),
|
||||
("engine.execute", profile("settings.profile.import", json!({"path": at(&out, "missing.json")}))),
|
||||
] {
|
||||
let v = call(method, params, true);
|
||||
assert!(v["ok"] == false && v.to_string().contains("outside the folders this agent may use"), "{method}: {v}");
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//! parameters, and [`command`] does the rest after `SolveApp::run`.
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use solidcraft_engine::io::vfs;
|
||||
use solidcraft_engine::{MAX_PROFILE_NAME, profile_name};
|
||||
|
||||
use crate::ui_kit::BackingTooltipExt as _;
|
||||
@@ -418,13 +419,14 @@ fn apply(app: &mut SolveApp, doc: &Value) -> Vec<String> {
|
||||
skipped
|
||||
}
|
||||
|
||||
/// A profile file read and checked, refusing one too large to be a profile.
|
||||
/// A profile file read and checked, refusing one too large to be a profile. Read through `vfs`, so
|
||||
/// an MCP agent's folders apply as they do to the engine's files (#11362).
|
||||
fn read_file(path: &str) -> Result<Value, String> {
|
||||
let size = std::fs::metadata(path).map_err(|e| format!("{path}: {e}"))?.len();
|
||||
let size = vfs::len(path).map_err(|e| format!("{path}: {e}"))?;
|
||||
if size > MAX_FILE_BYTES {
|
||||
return Err(format!("{path}: a settings profile file is at most {} MiB", MAX_FILE_BYTES / 1024 / 1024));
|
||||
}
|
||||
let text = std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?;
|
||||
let text = vfs::read_to_string(path, MAX_FILE_BYTES as usize).map_err(|e| format!("{path}: {e}"))?;
|
||||
serde_json::from_str(&text).map_err(|e| format!("{path}: not a settings profile: {e}"))
|
||||
}
|
||||
|
||||
@@ -494,7 +496,7 @@ pub fn command(app: &mut SolveApp, id: &str, v: &Value) -> Result<Value, String>
|
||||
let doc = app.settings_profiles.get(name)?.clone();
|
||||
if let Some(path) = v.get("path").and_then(Value::as_str) {
|
||||
let text = serde_json::to_string_pretty(&doc).map_err(|e| e.to_string())?;
|
||||
std::fs::write(path, text).map_err(|e| format!("{path}: {e}"))?;
|
||||
vfs::write(path, text.as_bytes()).map_err(|e| format!("{path}: {e}"))?;
|
||||
return Ok(json!({ "profile": doc, "path": path }));
|
||||
}
|
||||
Ok(json!({ "profile": doc }))
|
||||
|
||||
Reference in new issue
Block a user