mirror of
https://github.com/openai/codex.git
synced 2026-11-07 20:30:33 +00:00
Preserve trusted MITM hook constraints
This commit is contained in:
@@ -122,6 +122,7 @@ fn network_constraints_from_trusted_layers(
|
||||
layers: &ConfigLayerStack,
|
||||
) -> Result<NetworkProxyConstraints> {
|
||||
let mut constraints = NetworkProxyConstraints::default();
|
||||
let mut trusted_network = NetworkConfigAccumulator::default();
|
||||
for layer in layers.get_layers(
|
||||
ConfigLayerStackOrdering::LowestPrecedenceFirst,
|
||||
/*include_disabled*/ false,
|
||||
@@ -132,9 +133,13 @@ fn network_constraints_from_trusted_layers(
|
||||
|
||||
let parsed = network_tables_from_toml(&layer.config)?;
|
||||
if let Some(network) = selected_network_from_tables(parsed)? {
|
||||
apply_network_constraints(network, &mut constraints);
|
||||
apply_network_constraints(network.clone(), &mut constraints);
|
||||
trusted_network.apply_network(network);
|
||||
}
|
||||
}
|
||||
let trusted_mitm_hooks = trusted_network.finish()?.network.mitm_hooks;
|
||||
constraints.required_mitm_hook_prefix =
|
||||
(!trusted_mitm_hooks.is_empty()).then_some(trusted_mitm_hooks);
|
||||
Ok(constraints)
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +174,72 @@ strip_request_headers = ["x-api-key"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trusted_named_mitm_actions_become_required_hook_constraints() {
|
||||
let lower_network: toml::Value = toml::from_str(
|
||||
r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.network]
|
||||
mode = "full"
|
||||
|
||||
[permissions.workspace.network.mitm.hooks.github_write]
|
||||
host = "api.github.com"
|
||||
methods = ["POST"]
|
||||
path_prefixes = ["/repos/openai/"]
|
||||
action = ["strip_auth"]
|
||||
|
||||
[permissions.workspace.network.mitm.actions.strip_auth]
|
||||
strip_request_headers = ["authorization"]
|
||||
"#,
|
||||
)
|
||||
.expect("lower layer should parse");
|
||||
let higher_network: toml::Value = toml::from_str(
|
||||
r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.network]
|
||||
mode = "full"
|
||||
|
||||
[permissions.workspace.network.mitm.actions.strip_auth]
|
||||
strip_request_headers = ["x-api-key"]
|
||||
"#,
|
||||
)
|
||||
.expect("higher layer should parse");
|
||||
|
||||
let mut trusted_network = NetworkConfigAccumulator::default();
|
||||
trusted_network
|
||||
.apply_network_tables(
|
||||
network_tables_from_toml(&lower_network).expect("lower layer should deserialize"),
|
||||
)
|
||||
.expect("lower layer should apply");
|
||||
trusted_network
|
||||
.apply_network_tables(
|
||||
network_tables_from_toml(&higher_network).expect("higher layer should deserialize"),
|
||||
)
|
||||
.expect("higher layer should apply");
|
||||
|
||||
let constraints = NetworkProxyConstraints {
|
||||
required_mitm_hook_prefix: Some(
|
||||
trusted_network
|
||||
.finish()
|
||||
.expect("trusted network should build")
|
||||
.network
|
||||
.mitm_hooks,
|
||||
),
|
||||
..NetworkProxyConstraints::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
constraints
|
||||
.required_mitm_hook_prefix
|
||||
.expect("trusted hooks should be constrained")[0]
|
||||
.actions
|
||||
.strip_request_headers,
|
||||
vec!["x-api-key"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execpolicy_network_rules_overlay_network_lists() {
|
||||
let mut config = NetworkProxyConfig::default();
|
||||
|
||||
Reference in New Issue
Block a user