发布小壹 1.1.1 并限定制作凭据传输范围
This commit is contained in:
parent
619f3fe4b8
commit
ed03285779
@ -23,6 +23,17 @@ const INVALID: &str = "企业知识库请求边界无效";
|
||||
const CREDENTIAL: &str = "企业知识库用户凭据未配置或不可读取";
|
||||
const NETWORK: &str = "企业知识库网络不可达";
|
||||
const RESPONSE: &str = "企业知识库响应无效";
|
||||
const XIAOYI_ORIGIN_REQUIRED: &str = "请通过公司内网或 HTTPS 连接小壹制作知识库";
|
||||
|
||||
fn allows_xiaoyi_origin(origin: &str) -> bool {
|
||||
let Ok(url) = reqwest::Url::parse(origin) else { return false; };
|
||||
match (url.scheme(), url.host_str()) {
|
||||
("https", Some(_)) => true,
|
||||
("http", Some("localhost" | "[::1]")) => true,
|
||||
("http", Some(host)) => host.parse::<Ipv4Addr>().is_ok_and(|ip| ip.is_private() || ip.is_loopback()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn config_path() -> Option<std::path::PathBuf> {
|
||||
crate::services::config_dir().map(|root| root.join("enterprise-knowledge-origin.json"))
|
||||
@ -126,7 +137,7 @@ fn verify_xiaoyi_key(key: &str, origins: &[String], save: impl FnOnce() -> R<boo
|
||||
let Ok(client) = MCP_CLIENT.as_ref() else {
|
||||
return json!({"status":null,"saved":false,"error":NETWORK});
|
||||
};
|
||||
let response = origins.iter().find_map(|origin| {
|
||||
let response = origins.iter().filter(|origin| allows_xiaoyi_origin(origin)).find_map(|origin| {
|
||||
client.get(format!("{origin}{XIAOYI_CURRENT}")).bearer_auth(key).send().ok()
|
||||
});
|
||||
let Some(response) = response else {
|
||||
@ -230,7 +241,7 @@ impl Route {
|
||||
r"\A/api/xiaoyi/v1/(?:templates/[A-Za-z0-9][A-Za-z0-9_.-]*/(?:current|releases/[A-Za-z0-9][A-Za-z0-9_.-]*/(?:manifest|bundle))|blobs/[a-f0-9]{64})\z"
|
||||
).map_err(|_| INVALID)?.is_match(path) =>
|
||||
{
|
||||
Ok(Self::Xiaoyi)
|
||||
if allows_xiaoyi_origin(origin) { Ok(Self::Xiaoyi) } else { Err(XIAOYI_ORIGIN_REQUIRED.into()) }
|
||||
}
|
||||
_ => Err(INVALID.into()),
|
||||
}
|
||||
@ -514,6 +525,14 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jiansun_xiaoyi_origin_allows_lan_and_https() {
|
||||
assert!(allows_xiaoyi_origin("http://192.168.101.188:18880"));
|
||||
assert!(allows_xiaoyi_origin("http://127.0.0.1:18980"));
|
||||
assert!(allows_xiaoyi_origin("https://knowledge.example.com"));
|
||||
assert!(!allows_xiaoyi_origin("http://218.93.9.38:20009"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jiansun_xiaoyi_recheck_reports_success_without_saving() {
|
||||
const KEY: &str = "synthetic-existing-key";
|
||||
@ -549,7 +568,11 @@ mod tests {
|
||||
),
|
||||
] {
|
||||
let input = json!({"origin":origin,"path":path,"httpMethod":method,"body":body});
|
||||
assert_eq!(Route::parse(&input).unwrap(), route);
|
||||
if route == Route::Xiaoyi && !allows_xiaoyi_origin(origin) {
|
||||
assert_eq!(Route::parse(&input).unwrap_err(), XIAOYI_ORIGIN_REQUIRED);
|
||||
} else {
|
||||
assert_eq!(Route::parse(&input).unwrap(), route);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (origin, method, path) in [
|
||||
|
||||
@ -1 +1 @@
|
||||
1.1.0
|
||||
1.1.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user