mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 00:17:45 +08:00
feat(security): harden gateway boundaries and usage policies
Consolidate subscription usage policy enforcement, privacy-safe persistence, and gateway security hardening into one reviewable change. Includes bounded HTTP and execution envelopes, header and protocol guards, DNS and relay validation, authentication and secret projection hardening, secure backup/install paths, and regression coverage.
This commit is contained in:
@@ -7,6 +7,7 @@ repository.workspace = true
|
||||
description = "Provider-specific pool behavior adapters for Aether"
|
||||
|
||||
[dependencies]
|
||||
aether-contracts.workspace = true
|
||||
aether-data-contracts.workspace = true
|
||||
aether-pool-core.workspace = true
|
||||
aether-provider-transport.workspace = true
|
||||
|
||||
@@ -366,6 +366,34 @@ mod tests {
|
||||
.contains("profileArn=arn%3Aaws%3Asso%3A%3A%3Aprofile%2Fp-1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kiro_quota_request_rejects_region_url_injection() {
|
||||
let spec = build_kiro_pool_quota_request(
|
||||
"key-1",
|
||||
&KiroPoolQuotaAuthInput {
|
||||
authorization_value: "Bearer sensitive-access-token".to_string(),
|
||||
api_region: "attacker.example/evil".to_string(),
|
||||
kiro_version: "0.3.210".to_string(),
|
||||
machine_id: "machine".to_string(),
|
||||
profile_arn: None,
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
spec.url,
|
||||
"https://q.us-east-1.amazonaws.com/getUsageLimits?origin=AI_EDITOR&resourceType=AGENTIC_REQUEST&isEmailRequired=true"
|
||||
);
|
||||
assert_eq!(
|
||||
spec.headers.get("host").map(String::as_str),
|
||||
Some("q.us-east-1.amazonaws.com")
|
||||
);
|
||||
assert!(!spec.url.contains("attacker.example"));
|
||||
assert!(!spec
|
||||
.headers
|
||||
.get("host")
|
||||
.is_some_and(|value| value.contains("attacker.example")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chatgpt_web_quota_request_uses_default_base_url_when_empty() {
|
||||
let spec = build_chatgpt_web_pool_quota_request(
|
||||
@@ -382,7 +410,6 @@ mod tests {
|
||||
spec.headers.get("origin").map(String::as_str),
|
||||
Some("https://chatgpt.com")
|
||||
);
|
||||
assert!(spec.accept_invalid_certs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -91,7 +91,6 @@ pub fn build_antigravity_pool_quota_request(
|
||||
client_api_format: "gemini:generate_content".to_string(),
|
||||
provider_api_format: "antigravity:fetch_available_models".to_string(),
|
||||
model_name: Some("fetchAvailableModels".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +130,6 @@ pub fn build_antigravity_pool_quota_summary_request(
|
||||
client_api_format: "gemini:generate_content".to_string(),
|
||||
provider_api_format: "antigravity:retrieve_user_quota_summary".to_string(),
|
||||
model_name: Some("retrieveUserQuotaSummary".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,6 @@ pub fn build_chatgpt_web_pool_quota_request(
|
||||
client_api_format: "openai:image".to_string(),
|
||||
provider_api_format: "chatgpt_web:conversation_init".to_string(),
|
||||
model_name: Some("chatgpt-web-conversation-init".to_string()),
|
||||
accept_invalid_certs: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,6 @@ pub fn build_codex_pool_quota_request(
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("codex-wham-usage".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -239,7 +238,6 @@ pub fn build_codex_pool_reset_credits_request(
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("codex-wham-reset-credits".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -273,7 +271,6 @@ pub fn build_codex_pool_reset_credit_consume_request(
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("codex-wham-reset-credit-consume".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,5 @@ pub fn build_gemini_cli_pool_quota_request(
|
||||
client_api_format: "gemini:generate_content".to_string(),
|
||||
provider_api_format: "gemini_cli:retrieve_user_quota".to_string(),
|
||||
model_name: Some("retrieveUserQuota".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@ use crate::quota::{
|
||||
provider_pool_reset_deadline_elapsed, provider_pool_timestamp_unix_secs,
|
||||
};
|
||||
use crate::quota_refresh::ProviderPoolQuotaRequestSpec;
|
||||
use aether_provider_transport::kiro::normalize_kiro_region;
|
||||
|
||||
pub const KIRO_USAGE_LIMITS_PATH: &str = "/getUsageLimits";
|
||||
pub const KIRO_USAGE_SDK_VERSION: &str = "1.0.0";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct KiroPoolQuotaAuthInput {
|
||||
pub authorization_value: String,
|
||||
pub api_region: String,
|
||||
@@ -29,6 +30,19 @@ pub struct KiroPoolQuotaAuthInput {
|
||||
pub profile_arn: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for KiroPoolQuotaAuthInput {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter
|
||||
.debug_struct("KiroPoolQuotaAuthInput")
|
||||
.field("authorization_value", &"[REDACTED]")
|
||||
.field("api_region", &self.api_region)
|
||||
.field("kiro_version", &self.kiro_version)
|
||||
.field("machine_id", &self.machine_id)
|
||||
.field("profile_arn", &self.profile_arn)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct KiroProviderPoolAdapter;
|
||||
|
||||
@@ -134,17 +148,11 @@ pub fn build_kiro_pool_quota_request(
|
||||
client_api_format: "claude:messages".to_string(),
|
||||
provider_api_format: "kiro:usage".to_string(),
|
||||
model_name: Some("kiro-usage-limits".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_region(value: &str) -> &str {
|
||||
let value = value.trim();
|
||||
if value.is_empty() {
|
||||
"us-east-1"
|
||||
} else {
|
||||
value
|
||||
}
|
||||
normalize_kiro_region(value)
|
||||
}
|
||||
|
||||
fn normalize_kiro_version(value: &str) -> &str {
|
||||
@@ -180,3 +188,23 @@ pub(crate) fn quota_exhausted_from_bucket(bucket: &Map<String, Value>) -> bool {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::KiroPoolQuotaAuthInput;
|
||||
|
||||
#[test]
|
||||
fn quota_auth_debug_output_redacts_authorization() {
|
||||
let input = KiroPoolQuotaAuthInput {
|
||||
authorization_value: "Bearer kiro-secret-canary".to_string(),
|
||||
api_region: "us-east-1".to_string(),
|
||||
kiro_version: "1.0.0".to_string(),
|
||||
machine_id: "machine-1".to_string(),
|
||||
profile_arn: None,
|
||||
};
|
||||
|
||||
let debug = format!("{input:?}");
|
||||
assert!(!debug.contains("kiro-secret-canary"));
|
||||
assert!(debug.contains("[REDACTED]"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,6 @@ fn build_windsurf_connect_rpc_request(
|
||||
client_api_format: "openai:chat".to_string(),
|
||||
provider_api_format: provider_api_format.to_string(),
|
||||
model_name: Some(model_name.to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
|
||||
use aether_contracts::redact_url_for_debug;
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct ProviderPoolQuotaRequestSpec {
|
||||
pub request_id: String,
|
||||
pub provider_name: String,
|
||||
@@ -15,5 +17,30 @@ pub struct ProviderPoolQuotaRequestSpec {
|
||||
pub client_api_format: String,
|
||||
pub provider_api_format: String,
|
||||
pub model_name: Option<String>,
|
||||
pub accept_invalid_certs: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for ProviderPoolQuotaRequestSpec {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter
|
||||
.debug_struct("ProviderPoolQuotaRequestSpec")
|
||||
.field("request_id", &self.request_id)
|
||||
.field("provider_name", &self.provider_name)
|
||||
.field("quota_kind", &self.quota_kind)
|
||||
.field("method", &self.method)
|
||||
.field("url", &redact_url_for_debug(&self.url))
|
||||
.field("header_names", &self.headers.keys().collect::<Vec<_>>())
|
||||
.field("content_type", &self.content_type)
|
||||
.field("has_json_body", &self.json_body.is_some())
|
||||
.field(
|
||||
"json_body_bytes",
|
||||
&self
|
||||
.json_body
|
||||
.as_ref()
|
||||
.and_then(|body| serde_json::to_vec(body).ok().map(|bytes| bytes.len())),
|
||||
)
|
||||
.field("client_api_format", &self.client_api_format)
|
||||
.field("provider_api_format", &self.provider_api_format)
|
||||
.field("model_name", &self.model_name)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user