Reject paths in project documentation fallback filenames (#45865)

## Why

Probing Windows network paths can send ambient credentials, even during metadata checks. Entries in `project_doc_fallback_filenames` must be validated before filesystem probes.

## What changed

Ignore entries containing path syntax according to the executor's OS, rather than the host's. Reject `.` and `..`, slashes, and NUL characters on all executors; also reject backslashes and colons on Windows. Log a warning for rejected entries and continue considering valid filenames.

## Testing

Add tests that verify invalid entries never reach metadata probes under POSIX and Windows path conventions, preserve backslashes and colons in POSIX filenames, and confirm valid fallback instructions still load alongside invalid entries.

GitOrigin-RevId: 4369e9b97ae6a3560d09e79efd8c85adac3d1d90
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-16 04:59:23 +00:00
1 parent 83dc7d11e8
commit 50d77959bf
3 files changed
+140 -4

No files matched your search

+52
View File
@@ -374,6 +374,58 @@ async fn configured_fallback_is_used_when_agents_candidate_is_directory() -> Res
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn invalid_fallback_paths_do_not_prevent_loading_valid_filenames() -> Result<()> {
let server = start_mock_server().await;
let response_mock = mount_sse_once(
&server,
sse(vec![ev_response_created("resp1"), ev_completed("resp1")]),
)
.await;
let test = test_codex()
.with_config(|config| {
config.project_doc_fallback_filenames =
[".", "..", "nested/WORKFLOW.md", "WORKFLOW.md"]
.map(str::to_owned)
.to_vec();
})
.with_workspace_setup(|cwd, fs| async move {
let nested = executor_path_uri(cwd.join("nested"))?;
fs.create_directory(
&nested,
CreateDirectoryOptions {
recursive: false,
follow_symlinks: true,
},
/*sandbox*/ None,
)
.await?;
for (path, contents) in [
(nested.join("WORKFLOW.md")?, b"nested instructions".to_vec()),
(
executor_path_uri(cwd.join("WORKFLOW.md"))?,
b"local instructions".to_vec(),
),
] {
fs.write_file(&path, contents, Default::default(), /*sandbox*/ None)
.await?;
}
Ok::<(), anyhow::Error>(())
})
.build_with_auto_env(&server)
.await?;
test.submit_turn("hello").await?;
assert_single_instruction_fragment(
&response_mock.single_request(),
&expected_instruction_fragment(
&test.executor_environment().selection().cwd,
"local instructions",
),
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn agents_docs_are_concatenated_from_project_root_to_cwd() -> Result<()> {
let instructions = agents_instructions(