mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:59:25 +00:00
Add revocable network policy primitives to the HTTP client (#45503)
## What changed - Add `NetworkPolicyController` and `NetworkPolicy` APIs for publishing destination policies, checking access, and observing policy changes. Restricted policies permit only `https` and `wss` URLs with exact allowed hosts. - Add revocable `NetworkPermit` values with cancellation support. Reject stale policy publications, revoke permits when access is removed, and prevent account-bound policy handles from regaining access after invalidation. - Provide a permit API for SDK transports without destination enforcement that denies access under restricted policies. - Let `HttpClientFactory` carry a network policy, defaulting to unmanaged access, and include policy identity in factory equality. ## Testing Add tests for secure host matching, invalidation, stale publication, recovery after policy load failure, account isolation, and SDK permit revocation. Make accepted sockets blocking in redirect test servers to handle macOS socket inheritance, and add a missing read timeout. GitOrigin-RevId: c79231527bc5e6954cda6581c0b9f43c90335755
This commit is contained in:
1 parent
08d3748cf0
commit
973ec2942c
7 files changed
+502
-1
No files matched your search
@@ -18,6 +18,7 @@ use tokio::sync::Semaphore;
|
||||
|
||||
use http::HeaderValue;
|
||||
|
||||
use crate::NetworkPolicy;
|
||||
use crate::chatgpt_cloudflare_cookies::ChatGptCookieStore;
|
||||
use crate::custom_ca::BuildCustomCaTransportError;
|
||||
use crate::custom_ca::build_reqwest_client_with_custom_ca;
|
||||
@@ -166,11 +167,13 @@ impl fmt::Debug for OutboundProxyRoute {
|
||||
pub struct HttpClientFactory {
|
||||
outbound_proxy_policy: OutboundProxyPolicy,
|
||||
chatgpt_cookie_store: Option<Arc<ChatGptCookieStore>>,
|
||||
network_policy: NetworkPolicy,
|
||||
}
|
||||
|
||||
impl PartialEq for HttpClientFactory {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.outbound_proxy_policy == other.outbound_proxy_policy
|
||||
&& self.network_policy == other.network_policy
|
||||
&& self
|
||||
.chatgpt_cookie_store
|
||||
.as_ref()
|
||||
@@ -188,6 +191,7 @@ impl fmt::Debug for HttpClientFactory {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("HttpClientFactory")
|
||||
.field("outbound_proxy_policy", &self.outbound_proxy_policy)
|
||||
.field("network_policy", &self.network_policy)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -198,9 +202,20 @@ impl HttpClientFactory {
|
||||
Self {
|
||||
outbound_proxy_policy,
|
||||
chatgpt_cookie_store: None,
|
||||
network_policy: NetworkPolicy::unmanaged(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Carries the account/configuration owner's application policy into every transport.
|
||||
pub fn with_network_policy(mut self, policy: NetworkPolicy) -> Self {
|
||||
self.network_policy = policy;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn network_policy(&self) -> &NetworkPolicy {
|
||||
&self.network_policy
|
||||
}
|
||||
|
||||
/// Adds process-scoped cookies to requests made by ChatGPT cookie-store clients.
|
||||
pub fn with_chatgpt_cookies(mut self, cookies: impl IntoIterator<Item = HeaderValue>) -> Self {
|
||||
let cookies = cookies.into_iter().collect::<Vec<_>>();
|
||||
|
||||
Reference in new issue
Block a user