Preserve executor paths in Guardian approval reviews (#42838)

## Why

Guardian approval actions can contain paths from a remote executor whose path convention differs from the host, such as Windows paths reviewed on a POSIX host. Converting those paths to host-native absolute paths prevents the action from being reviewed.

## What changed

- Render command working directories using the executor's reported path convention, and preserve URI-backed paths for attribution.
- Carry foreign command and patch paths through Guardian events and app-server schemas as legacy path strings.
- Bound remote plugin attribution within the overall review deadline and reject Guardian action payloads that exceed the review byte limit.

## Testing

- Cover Windows and POSIX executor path rendering, foreign patch paths, protocol round trips, oversized payload rejection, and remote Guardian review context.

GitOrigin-RevId: 38be0fcdac897139519e74e077eb5cb4f8f8017e
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-09-04 19:56:31 +00:00
1 parent 83b62a02fa
commit 773f0b081d
27 files changed
+442 -203

No files matched your search

@@ -202,7 +202,7 @@ pub fn build_item_from_guardian_event(
plugin_id: assessment.plugin_id.clone(),
script_path: assessment.script_path.clone(),
command,
cwd: cwd.clone().into(),
cwd: cwd.clone(),
process_id: None,
source: CommandExecutionSource::Agent,
status,
@@ -579,7 +579,7 @@ impl From<GuardianCommandSource> for CoreGuardianCommandSource {
pub struct GuardianCommandReviewAction {
pub source: GuardianCommandSource,
pub command: String,
pub cwd: AbsolutePathBuf,
pub cwd: LegacyAppPathString,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
@@ -596,8 +596,8 @@ pub struct GuardianExecveReviewAction {
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct GuardianApplyPatchReviewAction {
pub cwd: AbsolutePathBuf,
pub files: Vec<AbsolutePathBuf>,
pub cwd: LegacyAppPathString,
pub files: Vec<LegacyAppPathString>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
@@ -639,7 +639,7 @@ pub enum GuardianApprovalReviewAction {
Command {
source: GuardianCommandSource,
command: String,
cwd: AbsolutePathBuf,
cwd: LegacyAppPathString,
},
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase")]
@@ -661,8 +661,8 @@ pub enum GuardianApprovalReviewAction {
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase")]
ApplyPatch {
cwd: AbsolutePathBuf,
files: Vec<AbsolutePathBuf>,
cwd: LegacyAppPathString,
files: Vec<LegacyAppPathString>,
},
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase")]
@@ -2863,12 +2863,12 @@ fn automatic_approval_review_deserializes_aborted_status() {
}
#[test]
fn guardian_approval_review_action_round_trips_command_shape() {
fn guardian_approval_review_action_round_trips_foreign_command_path() {
let value = json!({
"type": "command",
"source": "shell",
"command": "rm -rf /tmp/example.sqlite",
"cwd": absolute_path_string("tmp"),
"command": r"Remove-Item C:\workspace\example.sqlite",
"cwd": r"C:\workspace",
});
let action: GuardianApprovalReviewAction =
serde_json::from_value(value.clone()).expect("guardian review action");
@@ -2877,8 +2877,8 @@ fn guardian_approval_review_action_round_trips_command_shape() {
action,
GuardianApprovalReviewAction::Command {
source: GuardianCommandSource::Shell,
command: "rm -rf /tmp/example.sqlite".to_string(),
cwd: absolute_path("tmp"),
command: r"Remove-Item C:\workspace\example.sqlite".to_string(),
cwd: LegacyAppPathString::from_string(r"C:\workspace"),
}
);
assert_eq!(