mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Protect inline visualization viewers from sandbox writes (#38306)
## Why Inline visualization viewer documents must remain outside locations that a sandboxed session can modify before they are opened in a browser. ## What changed - Materialize viewer documents in a dedicated cache under `CODEX_HOME`, keyed by the source and artifact thread IDs, instead of alongside visualization artifacts. - Create visualization links only when the active filesystem policy cannot write to the viewer cache. This also disables links for full-disk-write sessions and applies the policy consistently when loading transcript history. - Reject viewer cache paths containing symbolic links and track materialized documents in memory so unchanged viewers are reused without trusting existing file contents. ## Testing - Verify that rendering an unchanged visualization reuses the existing viewer file, while an updated fragment refreshes it. GitOrigin-RevId: 12b7fbe522a68076e5d683a987b7801940d131c2
This commit is contained in:
@@ -244,12 +244,37 @@ fn viewer_reuses_path_and_refreshes_static_document() {
|
||||
let (_codex_home, context) = context_with_fragment("<div>first</div>");
|
||||
let first_url = context.link_for("chart.html").expect("first viewer link");
|
||||
let viewer_path = first_url.to_file_path().expect("viewer file path");
|
||||
let original_viewer_metadata = fs::metadata(&viewer_path).expect("read viewer metadata");
|
||||
assert!(
|
||||
fs::read_to_string(&viewer_path)
|
||||
.expect("read first viewer")
|
||||
.contains("first")
|
||||
);
|
||||
|
||||
let reused_url = context.link_for("chart.html").expect("reused viewer link");
|
||||
|
||||
assert_eq!(reused_url, first_url);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
assert_eq!(
|
||||
fs::metadata(&viewer_path)
|
||||
.expect("read reused viewer metadata")
|
||||
.ino(),
|
||||
original_viewer_metadata.ino()
|
||||
);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
assert_eq!(
|
||||
fs::metadata(&viewer_path)
|
||||
.expect("read reused viewer metadata")
|
||||
.creation_time(),
|
||||
original_viewer_metadata.creation_time()
|
||||
);
|
||||
}
|
||||
|
||||
fs::write(context.thread_dir.join("chart.html"), "<div>second</div>").expect("update fragment");
|
||||
let second_url = context.link_for("chart.html").expect("second viewer link");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user