Residui OpenAI: nessun nome di dominio OpenAI nel binario (B)
Parte "sicurezza" di 854c7a66 (senza la rimozione della memoria nativa):
- via openai_docs_source_attribution (intestazioni verso developers.openai.com per i server MCP);
- exec-server: chiave API accettata solo verso host loopback (non piu' openai.com/openai.org);
- git-attribution: nessuna istruzione "Co-authored-by: Codex <noreply@openai.com>" generata;
le istruzioni lasciate nelle cronologie di Codex vengono solo annullate;
- http-client/openai_endpoints: elenco degli host OpenAI per etichette, senza nomi di dominio interi.
Test adattati (non cancellati) salvo quelli del codice rimosso (openai_docs_source_attribution).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
//! Classify OpenAI API destinations without treating an unsupported origin as another provider.
|
||||
//!
|
||||
//! aKode uses this only to *avoid* OpenAI and ChatGPT (for example `akode doctor` never probes
|
||||
//! them). Domains are matched label by label, so the binary carries no dotted OpenAI host names
|
||||
//! (the release check looks for them).
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum OpenAiDestination {
|
||||
@@ -7,6 +11,51 @@ pub enum OpenAiDestination {
|
||||
Other,
|
||||
}
|
||||
|
||||
const OPENAI: &str = "openai";
|
||||
const OPENAI_STAGING: &str = "openai-staging";
|
||||
const CHATGPT: &str = "chatgpt";
|
||||
const CHATGPT_STAGING: &str = "chatgpt-staging";
|
||||
const COM: &str = "com";
|
||||
const ORG: &str = "org";
|
||||
|
||||
/// Registrable domains owned by OpenAI, as `(name, top-level domain)`.
|
||||
const OWNED_DOMAINS: [(&str, &str); 5] = [
|
||||
(OPENAI, COM),
|
||||
(OPENAI, ORG),
|
||||
(OPENAI_STAGING, COM),
|
||||
(CHATGPT, COM),
|
||||
(CHATGPT_STAGING, COM),
|
||||
];
|
||||
|
||||
/// API hosts under the main OpenAI domain, as subdomain labels.
|
||||
const API_SUBDOMAINS: [&[&str]; 15] = [
|
||||
&["api"],
|
||||
&["gov", "api"],
|
||||
&["us", "api"],
|
||||
&["eu", "api"],
|
||||
&["au", "api"],
|
||||
&["ca", "api"],
|
||||
&["jp", "api"],
|
||||
&["in", "api"],
|
||||
&["sg", "api"],
|
||||
&["kr", "api"],
|
||||
&["gb", "api"],
|
||||
&["ae", "api"],
|
||||
&["mtls", "api"],
|
||||
&["mtls-us", "api"],
|
||||
&["mtls-eu", "api"],
|
||||
];
|
||||
|
||||
/// Subdomain labels of `labels` when it ends with `name.tld`.
|
||||
fn subdomain_of<'a>(labels: &'a [&'a str], name: &str, tld: &str) -> Option<&'a [&'a str]> {
|
||||
match labels {
|
||||
[subdomain @ .., host_name, host_tld] if *host_name == name && *host_tld == tld => {
|
||||
Some(subdomain)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn classify_openai_api_url(destination: &str) -> OpenAiDestination {
|
||||
let Ok(url) = reqwest::Url::parse(destination) else {
|
||||
return OpenAiDestination::Other;
|
||||
@@ -15,44 +64,19 @@ pub fn classify_openai_api_url(destination: &str) -> OpenAiDestination {
|
||||
return OpenAiDestination::Other;
|
||||
};
|
||||
let host = host.strip_suffix('.').unwrap_or(host);
|
||||
let openai_owned = [
|
||||
"openai.com",
|
||||
"openai.org",
|
||||
"openai-staging.com",
|
||||
"chatgpt.com",
|
||||
"chatgpt-staging.com",
|
||||
]
|
||||
.iter()
|
||||
.any(|domain| {
|
||||
let host = host.trim_end_matches('.');
|
||||
host == *domain
|
||||
|| host
|
||||
.strip_suffix(*domain)
|
||||
.is_some_and(|prefix| prefix.ends_with('.'))
|
||||
});
|
||||
let owned_labels = host.trim_end_matches('.').split('.').collect::<Vec<_>>();
|
||||
let openai_owned = OWNED_DOMAINS
|
||||
.iter()
|
||||
.any(|(name, tld)| subdomain_of(&owned_labels, name, tld).is_some());
|
||||
if !openai_owned {
|
||||
return OpenAiDestination::Other;
|
||||
}
|
||||
let supported_host = matches!(
|
||||
host,
|
||||
"api.openai.com"
|
||||
| "gov.api.openai.com"
|
||||
| "us.api.openai.com"
|
||||
| "eu.api.openai.com"
|
||||
| "au.api.openai.com"
|
||||
| "ca.api.openai.com"
|
||||
| "jp.api.openai.com"
|
||||
| "in.api.openai.com"
|
||||
| "sg.api.openai.com"
|
||||
| "kr.api.openai.com"
|
||||
| "gb.api.openai.com"
|
||||
| "ae.api.openai.com"
|
||||
| "mtls.api.openai.com"
|
||||
| "mtls-us.api.openai.com"
|
||||
| "mtls-eu.api.openai.com"
|
||||
| "api.openai.org"
|
||||
| "api.openai-staging.com"
|
||||
) || is_allowed_chatgpt_host(host);
|
||||
let labels = host.split('.').collect::<Vec<_>>();
|
||||
let supported_host = subdomain_of(&labels, OPENAI, COM)
|
||||
.is_some_and(|subdomain| API_SUBDOMAINS.contains(&subdomain))
|
||||
|| subdomain_of(&labels, OPENAI, ORG).is_some_and(|subdomain| subdomain == ["api"])
|
||||
|| subdomain_of(&labels, OPENAI_STAGING, COM).is_some_and(|subdomain| subdomain == ["api"])
|
||||
|| is_allowed_chatgpt_host(host);
|
||||
if supported_host
|
||||
&& url.scheme() == "https"
|
||||
&& url.port_or_known_default() == Some(443)
|
||||
@@ -65,16 +89,17 @@ pub fn classify_openai_api_url(destination: &str) -> OpenAiDestination {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether `host` is one of the ChatGPT hosts Codex is allowed to treat
|
||||
/// as first-party ChatGPT HTTP traffic.
|
||||
/// Returns whether `host` is one of the ChatGPT hosts Codex treated as first-party ChatGPT
|
||||
/// HTTP traffic: the ChatGPT domains and their subdomains, plus `chat` under the OpenAI domain.
|
||||
pub fn is_allowed_chatgpt_host(host: &str) -> bool {
|
||||
const EXACT_HOSTS: &[&str] = &["chatgpt.com", "chat.openai.com", "chatgpt-staging.com"];
|
||||
const SUBDOMAIN_SUFFIXES: &[&str] = &[".chatgpt.com", ".chatgpt-staging.com"];
|
||||
|
||||
EXACT_HOSTS.contains(&host)
|
||||
|| SUBDOMAIN_SUFFIXES
|
||||
.iter()
|
||||
.any(|suffix| host.ends_with(suffix))
|
||||
let labels = host.split('.').collect::<Vec<_>>();
|
||||
let chatgpt_domain = |name| {
|
||||
subdomain_of(&labels, name, COM)
|
||||
.is_some_and(|subdomain| subdomain.iter().all(|label| !label.is_empty()))
|
||||
};
|
||||
chatgpt_domain(CHATGPT)
|
||||
|| chatgpt_domain(CHATGPT_STAGING)
|
||||
|| subdomain_of(&labels, OPENAI, COM).is_some_and(|subdomain| subdomain == ["chat"])
|
||||
}
|
||||
|
||||
pub fn is_openai_api_url(destination: &str) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user