mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Keep configuration values out of Windows sandbox policy events (#49067)
## Why Configuration parser errors can include entire configuration lines containing credentials. Persistent policy-rejection events must avoid recording those values. ## What changed Replace free-form error text in Windows sandbox provisioning policy-rejection events with known stage labels and typed cloud, HTTP, I/O, and Win32 error codes. Use fixed fallback labels when the stage or cause is unrecognized. ## Testing Add regression coverage using malformed requirements and cloud configuration fragments containing a synthetic secret. Verify that diagnostics exclude parser values while retaining safe error codes, and that unknown errors produce fixed fallback text. GitOrigin-RevId: 4f2fa5f6f602c34451776ec31381a102213660b8
This commit is contained in:
@@ -339,7 +339,7 @@ fn handle_request(
|
||||
}
|
||||
crate::service::log_error(
|
||||
crate::service::EVENT_REQUEST_REJECTED,
|
||||
&format!("Codex sandbox provisioning was rejected by administrator policy: {error}"),
|
||||
&policy_rejection_diagnostic(&error),
|
||||
);
|
||||
return Err(error)
|
||||
.context("requested sandbox settings violate administrator-controlled machine policy");
|
||||
@@ -353,6 +353,39 @@ fn handle_request(
|
||||
)
|
||||
}
|
||||
|
||||
fn policy_rejection_diagnostic(error: &anyhow::Error) -> String {
|
||||
// Only service-owned labels and typed codes belong in persistent events.
|
||||
// Parser wrappers can stringify entire config lines, including credentials.
|
||||
let stage = match error.to_string().as_str() {
|
||||
"start managed configuration runtime" => "runtime",
|
||||
"load bootstrap configuration" => "bootstrap",
|
||||
"resolve cloud configuration authentication" => "resolve_auth",
|
||||
"initialize cloud configuration authentication" => "initialize_auth",
|
||||
"load managed configuration" => "managed",
|
||||
"enforce managed provisioning requirements" => "enforce",
|
||||
_ => "unknown",
|
||||
};
|
||||
let detail = error.chain().find_map(|cause| {
|
||||
let io = cause.downcast_ref::<std::io::Error>();
|
||||
let inner = io
|
||||
.and_then(std::io::Error::get_ref)
|
||||
.map(|inner| inner as &(dyn std::error::Error + 'static))
|
||||
.unwrap_or(cause);
|
||||
if let Some(cloud) = inner.downcast_ref::<codex_config::CloudConfigBundleLoadError>() {
|
||||
return Some(format!(
|
||||
"cloud={:?} http={:?}",
|
||||
cloud.code(),
|
||||
cloud.status_code()
|
||||
));
|
||||
}
|
||||
io.map(|io| format!("io={:?} win32={:?}", io.kind(), io.raw_os_error()))
|
||||
});
|
||||
let detail = detail.unwrap_or_else(|| "cause=unavailable".to_string());
|
||||
format!(
|
||||
"Codex sandbox provisioning was rejected by administrator policy: stage={stage} {detail}"
|
||||
)
|
||||
}
|
||||
|
||||
fn is_config_parse_error(error: &anyhow::Error) -> bool {
|
||||
error.chain().any(|cause| {
|
||||
cause.is::<toml::de::Error>()
|
||||
|
||||
@@ -7,6 +7,7 @@ use super::home::prepare_codex_home;
|
||||
use super::is_config_parse_error;
|
||||
use super::pin_existing_ancestors;
|
||||
use super::pipe_security_descriptor;
|
||||
use super::policy_rejection_diagnostic;
|
||||
use super::refresh_session;
|
||||
use super::request::ProvisioningRequest;
|
||||
use super::response_error_message;
|
||||
@@ -264,6 +265,64 @@ fn config_parse_errors_are_distinguished_from_policy_and_io_failures() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn policy_event_excludes_real_parser_values_but_retains_safe_codes() {
|
||||
let contents = "Authorization = \"Bearer synthetic-secret";
|
||||
let requirements =
|
||||
codex_config::compose_requirements([codex_config::RequirementsLayerEntry::from_toml(
|
||||
codex_config::RequirementSource::Unknown,
|
||||
contents,
|
||||
)])
|
||||
.unwrap_err();
|
||||
let fragment = codex_config::cloud_config_layers_from_fragments(
|
||||
[codex_config::CloudConfigFragment {
|
||||
id: "synthetic-id".into(),
|
||||
name: "private-name".into(),
|
||||
contents: contents.into(),
|
||||
}],
|
||||
&Path::new(r"C:\CodexTest").try_into().unwrap(),
|
||||
)
|
||||
.unwrap_err();
|
||||
for error in [
|
||||
std::io::Error::from(requirements),
|
||||
std::io::Error::from(fragment),
|
||||
] {
|
||||
let error = anyhow::Error::new(error).context("load managed configuration");
|
||||
assert!(format!("{error:#}").contains("synthetic-secret"));
|
||||
assert!(!is_config_parse_error(&error));
|
||||
assert_eq!(
|
||||
policy_rejection_diagnostic(&error),
|
||||
"Codex sandbox provisioning was rejected by administrator policy: stage=managed io=InvalidData win32=None"
|
||||
);
|
||||
}
|
||||
|
||||
for (error, expected) in [
|
||||
(
|
||||
anyhow::Error::new(std::io::Error::from_raw_os_error(5))
|
||||
.context("load bootstrap configuration"),
|
||||
"stage=bootstrap io=PermissionDenied win32=Some(5)",
|
||||
),
|
||||
(
|
||||
anyhow::Error::new(codex_config::CloudConfigBundleLoadError::new(
|
||||
codex_config::CloudConfigBundleLoadErrorCode::RequestFailed,
|
||||
Some(503),
|
||||
contents,
|
||||
))
|
||||
.context("load managed configuration"),
|
||||
"stage=managed cloud=RequestFailed http=Some(503)",
|
||||
),
|
||||
(
|
||||
anyhow::anyhow!("{contents}"),
|
||||
"stage=unknown cause=unavailable",
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
policy_rejection_diagnostic(&error),
|
||||
format!("Codex sandbox provisioning was rejected by administrator policy: {expected}")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provisioning_request_preserves_home_spaces_and_unicode() {
|
||||
let request = framed_request(SandboxProvisioningRequest {
|
||||
|
||||
Reference in New Issue
Block a user