mirror of
https://github.com/openai/codex.git
synced 2026-10-23 18:08:45 +00:00
Sanitize credentials from Git remote metadata (#40713)
## Why Git remote URLs can embed usernames, passwords, or tokens. Codex carries these URLs through turn metadata and persisted thread metadata, so credentials must be removed before a remote enters those paths. ## What changed - Add `SanitizedGitUrl`, which parses Git URL and SCP-style remotes, strips authentication data, and preserves the conventional `git` SSH user. - Use sanitized remotes when collecting Git metadata, enriching model requests, discovering cloud environments, updating thread metadata, and reading legacy rollouts. Reject or omit malformed remotes instead of retaining their raw contents. - Keep API, schema, and TypeScript representations as strings while enforcing sanitization in Rust. ## Testing - Cover URL schemes, SCP and IPv6 forms, remote helpers, encoded paths, malformed values, and legacy deserialization. - Verify credentials do not appear in model requests, API responses, SQLite, or rollout files. GitOrigin-RevId: 6435efc4c45bfbfad4723ce7a0457cb00175f25c
This commit is contained in:
committed by
copyberry
parent
399be2d6b5
commit
1bc02aea50
@@ -17,6 +17,7 @@ use codex_app_server_protocol::ThreadSectionMoveParams;
|
||||
use codex_app_server_protocol::ThreadSectionMoveResponse;
|
||||
use codex_extension_api::ExtensionDataInit;
|
||||
use codex_extension_api::ThreadIdleCause;
|
||||
use codex_protocol::SanitizedGitUrl;
|
||||
use codex_protocol::config_types::MultiAgentMode;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
@@ -1901,16 +1902,25 @@ impl ThreadRequestProcessor {
|
||||
return Err(invalid_request("gitInfo must include at least one field"));
|
||||
}
|
||||
|
||||
let origin_url =
|
||||
Self::normalize_thread_metadata_git_field(origin_url, "gitInfo.originUrl")?;
|
||||
let origin_url = match origin_url {
|
||||
Some(Some(origin_url)) => {
|
||||
Some(Some(SanitizedGitUrl::try_from(origin_url).map_err(
|
||||
|_| invalid_request("gitInfo.originUrl must be a valid Git remote"),
|
||||
)?))
|
||||
}
|
||||
Some(None) => Some(None),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok(StoreGitInfoPatch {
|
||||
sha: Self::normalize_thread_metadata_git_field(sha, "gitInfo.sha")?,
|
||||
branch: Self::normalize_thread_metadata_git_field(
|
||||
branch,
|
||||
"gitInfo.branch",
|
||||
)?,
|
||||
origin_url: Self::normalize_thread_metadata_git_field(
|
||||
origin_url,
|
||||
"gitInfo.originUrl",
|
||||
)?,
|
||||
origin_url,
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -5840,7 +5850,7 @@ pub(crate) fn thread_from_stored_thread(
|
||||
let git_info = thread.git_info.map(|info| ApiGitInfo {
|
||||
sha: info.commit_hash.map(|sha| sha.0),
|
||||
branch: info.branch,
|
||||
origin_url: info.repository_url,
|
||||
origin_url: info.repository_url.map(String::from),
|
||||
});
|
||||
let cwd = AbsolutePathBuf::relative_to_current_dir(path_utils::normalize_for_native_workdir(
|
||||
thread.cwd,
|
||||
@@ -5916,7 +5926,7 @@ fn summary_from_stored_thread(
|
||||
let git_info = thread.git_info.map(|git| ConversationGitInfo {
|
||||
sha: git.commit_hash.map(|sha| sha.0),
|
||||
branch: git.branch,
|
||||
origin_url: git.repository_url,
|
||||
origin_url: git.repository_url.map(String::from),
|
||||
});
|
||||
ConversationSummary {
|
||||
conversation_id: thread.thread_id,
|
||||
@@ -6016,7 +6026,7 @@ fn summary_from_thread_metadata(metadata: &ThreadMetadata) -> ConversationSummar
|
||||
metadata.agent_role.clone(),
|
||||
metadata.git_sha.clone(),
|
||||
metadata.git_branch.clone(),
|
||||
metadata.git_origin_url.clone(),
|
||||
metadata.git_origin_url.clone().map(String::from),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user