Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 61 additions & 27 deletions crates/registry-breg-mcp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use registry_platform_config::{
LoadedRuntimeConfig, Posture, PostureSource, PrivateListenerConfig, RemovedKey,
RuntimeConfigLoader, RuntimeEnvelope, SecretProvidersConfig, SettingOrigin, TlsTermination,
};
use registry_platform_httputil::loopback::loopback_host;
use registry_platform_httputil::client::transport_protects_the_credential;
use registry_platform_yaml::{
escape_pointer_segment, BoundedU64, Diagnostic, Invalid, LocalId, Report, RetiredApiVersion,
UniqueList, Url,
Expand Down Expand Up @@ -643,8 +643,7 @@ fn endpoint_findings(config: &RuntimeConfig, findings: &mut Vec<Finding>) {
];
for (pointer, endpoint) in endpoints {
let url = endpoint.to_url();
let secure = url.scheme() == "https" || (url.scheme() == "http" && is_loopback(&url));
if !secure {
if !transport_protects_the_credential(&url) {
findings.push(Finding::new(
"breg.mcp-runtime.plain-http-endpoint",
pointer,
Expand Down Expand Up @@ -723,13 +722,6 @@ fn cross_member_findings(
}
}

fn is_loopback(url: &url::Url) -> bool {
url.scheme() == "http"
&& url
.host_str()
.is_some_and(|host| loopback_host(host).is_some())
}

/// A value that satisfies the member at `pointer`, so a deferred expression
/// never decides whether its neighbours decode.
fn stand_in_for(pointer: &str) -> &'static str {
Expand Down Expand Up @@ -1845,10 +1837,27 @@ rateLimits:
}
}

const CREDENTIAL_ENDPOINTS: [(&str, &str); 2] = [
("https://registry.example.test/", "/registry/baseUrl"),
(
"https://login.example.test/token",
"/exchange/tokenEndpoint",
),
];

#[test]
fn default_posture_accepts_plain_http_loopback_registry() {
let local = document().replace("https://registry.example.test/", "http://127.0.0.1:8080/");
load(&local).expect("production accepts loopback registry transport");
fn default_posture_accepts_loopback_http_and_private_https_credential_endpoints() {
let source = document();
for (original, pointer) in CREDENTIAL_ENDPOINTS {
for url in [
"http://127.0.0.1:8080/",
"https://10.0.0.4:8443/nested/endpoint",
] {
let config = source.replacen(original, url, 1);
assert_ne!(config, source, "{pointer} fixture must be replaced");
load(&config).unwrap_or_else(|_| panic!("{pointer} should accept {url}"));
}
}
}

#[test]
Expand Down Expand Up @@ -1904,22 +1913,47 @@ rateLimits:
#[test]
fn plain_http_follows_the_shared_loopback_definition() {
let development = document().replace("operator-controlled-upstream", "loopback-plaintext");
for host in ["LOCALHOST", "127.0.0.2", "[::1]", "[::ffff:127.0.0.1]"] {
let config = development.replace(
"https://registry.example.test/",
&format!("http://{host}:8080/"),
);
load(&config).unwrap_or_else(|_| panic!("{host} is loopback"));
for (original, pointer) in CREDENTIAL_ENDPOINTS {
for host in ["LOCALHOST", "127.0.0.2", "[::1]", "[::ffff:127.0.0.1]"] {
let config = development.replacen(original, &format!("http://{host}:8080/"), 1);
load(&config).unwrap_or_else(|_| panic!("{pointer} should accept {host}"));
}
for host in [
"localhost.",
"app.localhost",
"10.0.0.4",
"[::ffff:10.0.0.1]",
"remote.example.test",
] {
refused(
&development.replacen(original, &format!("http://{host}:8080/"), 1),
"breg.mcp-runtime.plain-http-endpoint",
pointer,
);
}
}
for host in ["localhost.", "app.localhost", "[::ffff:10.0.0.1]"] {
refused(
&development.replace(
"https://registry.example.test/",
&format!("http://{host}:8080/"),
}

#[test]
fn credential_endpoint_transport_refusal_precedes_query_or_fragment() {
let source = document();
for (original, pointer) in CREDENTIAL_ENDPOINTS {
for (endpoint, code) in [
(original, "breg.mcp-runtime.endpoint-query-or-fragment"),
(
"http://127.0.0.1:8080/nested/endpoint",
"breg.mcp-runtime.endpoint-query-or-fragment",
),
"breg.mcp-runtime.plain-http-endpoint",
"/registry/baseUrl",
);
(
"http://10.0.0.4:8080/nested/endpoint",
"breg.mcp-runtime.plain-http-endpoint",
),
] {
for suffix in ["?", "#", "?tenant=a", "#anchor", "?tenant=a#anchor"] {
let config = source.replacen(original, &format!("{endpoint}{suffix}"), 1);
refused(&config, code, pointer);
}
}
}
}

Expand Down
Loading