obs(07): native-plugin fail-closed, value/trace privacy test and final gate evidence

This commit is contained in:
cflmy committed 2026-11-22 16:12:47 +08:00
1 parent 2d51f08340
commit 1d3dca7c18
9 files changed
+189 -5

No files matched your search

+20
View File
@@ -333,6 +333,26 @@ pub fn execute(
return fail_prepare(stream, json, command_name, "authorization", &error);
}
}
// A native plugin shares this process and can write fd 1 directly, so it
// can pollute the JSONL channel. Fail closed rather than presenting
// untrusted raw bytes as program stdout (RFC-OBS-0001 §4.4/§9.2, T26).
if stream.is_some()
&& static_plugins
.plugins
.iter()
.any(|plugin| plugin.kind == marqdo_plugin_abi::PluginKind::Native)
{
return fail(
stream,
json,
command_name,
"authorization",
"ext.event_stream_unsupported_native_plugin",
"--event-stream jsonl cannot guarantee a clean channel with an in-process native \
plugin; use a worker plugin or disable event mode",
2,
);
}
// T7: start only selected, granted and verified extensions.
for plugin in &static_plugins.plugins {
if let Err(message) = load_plugin_into_host(
+81
View File
@@ -266,6 +266,87 @@ fn structure_fixture_attributes_repeated_recursive_frames() {
);
}
#[test]
fn native_plugin_is_fail_closed_in_event_mode() {
use sha2::Digest;
let dir = TempDir::new("native-plugin");
dir.write("index.mq.md", "## @exec main\n\n`return 1`\n");
let plugin_dir = dir.path().join("plugin");
fs::create_dir_all(&plugin_dir).unwrap();
let artifact = plugin_dir.join("solver.so");
fs::write(&artifact, b"not-a-real-library").unwrap();
let digest = hex::encode(sha2::Sha256::digest(fs::read(&artifact).unwrap()));
let manifest = format!(
"plugin:\n name: demo.solver\n version: 0.1.0\n abi: \"^1.0\"\n kind: native\n exports:\n - name: solver.add\n signature: \"($a: Int, $b: Int) -> Int\"\n requires:\n - math.compute\n artifacts:\n - target: {}\n file: solver.so\n sha256: \"{}\"\n",
marqdo_plugin_abi::HostTarget::current().triple(),
digest
);
fs::write(plugin_dir.join("plugin.yaml"), manifest).unwrap();
let output = cli(
dir.path(),
&[
"run",
"index.mq.md",
"--event-stream",
"jsonl",
"--plugin",
plugin_dir.join("plugin.yaml").to_str().unwrap(),
"--allow-plugin",
"demo.solver",
],
);
assert_eq!(output.status.code(), Some(2));
let events = parse_events(&output.stdout);
assert_envelope(&events);
let terminal = events.last().unwrap();
assert_eq!(terminal["kind"], "run.rejected");
assert_eq!(
terminal["payload"]["error"]["code"],
"ext.event_stream_unsupported_native_plugin"
);
assert!(
events_of(&events, "run.started").is_empty(),
"the native plugin is rejected before execution"
);
}
#[test]
fn observed_values_never_enter_trace_v2() {
let dir = TempDir::new("trace-redaction");
dir.write(
"index.mq.md",
"## @exec main\n\n`secret_token = \"DO_NOT_LEAK_SENTINEL_1\"`\n\n`visible_count = 42`\n\n`return visible_count`\n",
);
let trace_path = dir.path().join("trace.json");
let output = cli(
dir.path(),
&[
"run",
"index.mq.md",
"--event-stream",
"jsonl",
"--observe-variable",
"secret_token",
"--observe-text-values",
"--trace-file",
trace_path.to_str().unwrap(),
],
);
assert_eq!(output.status.code(), Some(0));
assert!(
String::from_utf8_lossy(&output.stdout).contains("DO_NOT_LEAK_SENTINEL_1"),
"the explicit event consent publishes the selected value in the stream"
);
let trace = fs::read(&trace_path).unwrap();
assert!(
!String::from_utf8_lossy(&trace).contains("DO_NOT_LEAK_SENTINEL_1"),
"Trace v2 must not gain observed values"
);
let trace: Value = serde_json::from_slice(&trace).unwrap();
assert_eq!(trace["schema"], "marqdo.trace");
assert_eq!(trace["schema_version"], 2);
}
#[test]
fn basic_stream_is_pure_jsonl_and_reconstructs_program_output() {
let dir = TempDir::new("basic");