MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / generate_security_notes

Function generate_security_notes

crates/openshell-server/src/grpc/policy.rs:3221–3258  ·  view source on GitHub ↗

Re-validate security notes server-side for a proposed policy chunk.

(host: &str, port: u16)

Source from the content-addressed store, hash-verified

3219
3220/// Re-validate security notes server-side for a proposed policy chunk.
3221fn generate_security_notes(host: &str, port: u16) -> String {
3222 let mut notes = Vec::new();
3223
3224 // Flag destinations that are an internal/private address. Parse the host as
3225 // an IP literal and defer to the canonical RFC-accurate classifier
3226 // (openshell-core net::is_internal_ip) rather than naive string prefixes:
3227 // `starts_with("172.")` wrongly matched 172.0-15 / 172.32-255 (RFC 1918 is
3228 // only 172.16.0.0/12) and missed CGNAT (100.64.0.0/10), IPv6 ULA, etc. The
3229 // "localhost" hostname is not an IP literal, so it is checked separately.
3230 // See #1777.
3231 let resolves_internal = host.parse::<IpAddr>().is_ok_and(is_internal_ip);
3232 if resolves_internal || host == "localhost" {
3233 notes.push(format!(
3234 "Destination '{host}' appears to be an internal/private address."
3235 ));
3236 }
3237
3238 if host.contains('*') {
3239 notes.push(format!(
3240 "Host '{host}' contains a wildcard — this may match unintended destinations."
3241 ));
3242 }
3243
3244 if port > 49152 {
3245 notes.push(format!(
3246 "Port {port} is in the ephemeral range — this may be a temporary service."
3247 ));
3248 }
3249
3250 const DB_PORTS: [u16; 7] = [5432, 3306, 6379, 27017, 9200, 11211, 5672];
3251 if DB_PORTS.contains(&port) {
3252 notes.push(format!(
3253 "Port {port} is a well-known database/service port."
3254 ));
3255 }
3256
3257 notes.join(" ")
3258}
3259
3260/// Reject proposed rules whose endpoints or `allowed_ips` target
3261/// always-blocked addresses (loopback, link-local, unspecified).

Callers 1

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected