Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(security): extend IMDS absolute-block to Apprise plugin schemes (#4063)

LearningCircuitb0008045df41
diff --git a/changelog.d/+imds-block-plugin-schemes.security.md b/changelog.d/+imds-block-plugin-schemes.security.md
new file mode 100644
index 0000000000..783f825385
--- /dev/null
+++ b/changelog.d/+imds-block-plugin-schemes.security.md
@@ -0,0 +1 @@
+Extended the cloud-metadata IP absolute-block in `NotificationURLValidator` to Apprise plugin schemes (signal, gotify, ntfy/ntfys, mattermost, rocketchat, matrix, json, xml, form, mailto). Previously only the http/https branch ran the IMDS guard, so a notification URL like `signal://169.254.169.254/...` would round-trip to Apprise even though Apprise translates it into a plain HTTP request against that host. LAN/loopback reach for self-hosted plugin endpoints (the #4006 use case) is unchanged.
diff --git a/src/local_deep_research/security/notification_validator.py b/src/local_deep_research/security/notification_validator.py
index 73409b745e..9918d5b4b8 100644
--- a/src/local_deep_research/security/notification_validator.py
+++ b/src/local_deep_research/security/notification_validator.py
@@ -254,42 +254,47 @@ class NotificationURLValidator:
f"Allowed: {', '.join(NotificationURLValidator.ALLOWED_SCHEMES[:5])}...",
)
- # For HTTP/HTTPS, check for private IPs (SSRF prevention).
- # Use urllib3 (the parser ``requests`` uses internally) instead of
- # urlparse for hostname extraction — urlparse is vulnerable to
- # parser-differential bypasses like ``http://127.0.0.1\@1.1.1.1``
- # (GHSA-g23j-2vwm-5c25). For non-HTTP schemes (Apprise transports
- # like discord://, slack://, mailto://) Apprise handles the URL
- # itself and the parser-differential doesn't apply.
+ # Extract the host for any allowed scheme. We use urllib3 (the
+ # parser ``requests`` uses internally) instead of urlparse —
+ # urlparse is vulnerable to parser-differential bypasses like
+ # ``http://127.0.0.1\@1.1.1.1`` (GHSA-g23j-2vwm-5c25).
#
- # The host check runs even when ``allow_private_ips=True`` —
- # ``_is_private_ip`` propagates that flag, so RFC1918 / loopback
- # are allowed through, but cloud-metadata IPs and NAT64-wrapped
- # metadata still block. ``allow_private_ips=True`` is an
- # operator opt-in for self-hosted webhooks on internal networks,
- # not for IMDS exfiltration.
+ # Per-scheme policy applied below:
+ # - http/https: full ``_is_private_ip`` check, honoring the
+ # operator ``allow_private_ips`` opt-in. RFC1918 / loopback
+ # are allowed through with the flag, but cloud-metadata and
+ # NAT64-wrapped metadata always block.
+ # - Apprise plugin schemes (discord, slack, signal, gotify,
+ # ntfy/ntfys, mattermost, rocketchat, matrix, teams, mailto,
+ # json, xml, form): private-IP reachability is intentionally
+ # allowed (these are typically self-hosted on a LAN), but the
+ # absolute cloud-metadata block still applies. Apprise
+ # translates these to HTTP requests against the URL host
+ # (e.g. ``signal://169.254.169.254/...`` → ``POST
+ # http://169.254.169.254/v2/send``), so without this guard
+ # the plugin schemes would bypass the IMDS protection that
+ # http/https has.
+ try:
+ u3 = parse_url(url)
+ except LocationParseError:
+ logger.warning(
+ "Blocked notification URL: urllib3 parser rejected it"
+ )
+ return False, "Invalid URL format (parser rejected)"
+ hostname = u3.host
+ # Authority must be ASCII printable (forward-defence vs urllib3
+ # ever loosening its IDN handling).
+ if hostname and any(ord(c) < 0x20 or ord(c) > 0x7E for c in hostname):
+ logger.warning(
+ "Blocked notification URL with non-ASCII / control bytes in host"
+ )
+ return False, "URL host contains disallowed characters"
+ if hostname and hostname.startswith("[") and hostname.endswith("]"):
+ hostname = hostname[1:-1]
+ if hostname:
+ hostname = hostname.rstrip(".")
+
if scheme in ("http", "https"):
- try:
- u3 = parse_url(url)
- except LocationParseError:
- logger.warning(
- "Blocked notification URL: urllib3 parser rejected it"
- )
- return False, "Invalid URL format (parser rejected)"
- hostname = u3.host
- # Authority must be ASCII printable (forward-defence vs urllib3
- # ever loosening its IDN handling).
- if hostname and any(
- ord(c) < 0x20 or ord(c) > 0x7E for c in hostname
- ):
- logger.warning(
- "Blocked notification URL with non-ASCII / control bytes in host"
- )
- return False, "URL host contains disallowed characters"
- if hostname and hostname.startswith("[") and hostname.endswith("]"):
- hostname = hostname[1:-1]
- if hostname:
- hostname = hostname.rstrip(".")
if hostname and NotificationURLValidator._is_private_ip(
hostname, allow_private_ips=allow_private_ips
):
@@ -301,6 +306,21 @@ class NotificationURLValidator:
False,
f"Blocked private/internal IP address: {hostname}",
)
+ else:
+ # Plugin-scheme IMDS guard. ``allow_private_ips=True`` leaves
+ # ALWAYS_BLOCKED_METADATA_IPS and NAT64-wrapped metadata as
+ # the only active blocks in ``_is_private_ip`` — exactly the
+ # set we want to enforce regardless of operator flags.
+ if hostname and NotificationURLValidator._is_private_ip(
+ hostname, allow_private_ips=True
+ ):
+ logger.warning(
+ f"Blocked cloud-metadata IP in notification URL: {hostname}"
+ )
+ return (
+ False,
+ f"Blocked cloud-metadata IP address: {hostname}",
+ )
# Passed all security checks
return True, None
diff --git a/tests/security/test_notification_validator.py b/tests/security/test_notification_validator.py
index 9b106fb78f..3940a9f3b6 100644
--- a/tests/security/test_notification_validator.py
+++ b/tests/security/test_notification_validator.py
@@ -397,6 +397,131 @@ class TestParserDifferentialBypass:
assert is_valid is False
+class TestCloudMetadataBlockedForPluginSchemes:
+ """Plugin-scheme IMDS guard.
+
+ Apprise translates schemes like signal://host/... into HTTP requests
+ against the URL host (e.g. POST http://host/v2/send), so cloud-
+ metadata IPs reached through a plugin scheme would otherwise bypass
+ the IMDS protection enforced for http/https. ``validate_service_url``
+ must reject them under every flag combination.
+ """
+
+ METADATA_IPS = (
+ "169.254.169.254", # AWS IMDSv1/v2, Azure, OCI, DigitalOcean
+ "169.254.170.2", # AWS ECS task metadata v3
+ "169.254.170.23", # AWS ECS task metadata v4
+ "169.254.0.23", # Tencent Cloud
+ "100.100.100.200", # AlibabaCloud
+ )
+
+ # Plugin schemes that resolve a user-supplied host into an outbound
+ # HTTP request under Apprise. (Schemes whose "host" slot holds an
+ # opaque token — discord, slack, telegram, pushover, teams — are
+ # covered by the existing positive tests; an IP-shaped token would
+ # still trip this guard, which is fine.)
+ HOST_BEARING_SCHEMES = (
+ "signal",
+ "gotify",
+ "ntfy",
+ "ntfys",
+ "mattermost",
+ "rocketchat",
+ "matrix",
+ "json",
+ "xml",
+ "form",
+ )
+
+ @pytest.mark.parametrize("ip", METADATA_IPS)
+ @pytest.mark.parametrize("scheme", HOST_BEARING_SCHEMES)
+ def test_metadata_ip_blocked_by_default(self, scheme, ip):
+ url = f"{scheme}://{ip}/path"
+ is_valid, error = NotificationURLValidator.validate_service_url(url)
+ assert is_valid is False
+ assert "cloud-metadata" in error.lower()
+
+ @pytest.mark.parametrize("ip", METADATA_IPS)
+ @pytest.mark.parametrize("scheme", HOST_BEARING_SCHEMES)
+ def test_metadata_ip_blocked_even_with_allow_private_ips(self, scheme, ip):
+ """allow_private_ips=True unlocks LAN reach, NOT IMDS."""
+ url = f"{scheme}://{ip}/path"
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ url, allow_private_ips=True
+ )
+ assert is_valid is False
+ assert "cloud-metadata" in error.lower()
+
+ def test_mailto_metadata_host_blocked(self):
+ """mailto://[email protected]/... must not reach IMDS."""
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ "mailto://user:[email protected]/recipient"
+ )
+ assert is_valid is False
+ assert "cloud-metadata" in error.lower()
+
+ def test_signal_lan_host_still_allowed(self):
+ """LAN signal-api-rest container (#4006 use case) keeps working."""
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ "signal://192.168.50.20:8739/+15551234567/+15557654321"
+ )
+ assert is_valid is True
+ assert error is None
+
+ def test_gotify_lan_host_still_allowed(self):
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ "gotify://10.0.0.5:8080/AbCdEf123"
+ )
+ assert is_valid is True
+ assert error is None
+
+ def test_signal_loopback_still_allowed(self):
+ """Plugin schemes pointing at localhost (same-host self-hosted
+ container) round-trip without the operator opt-in — only the
+ absolute IMDS block fires for plugin schemes."""
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ "signal://127.0.0.1:8739/+15551234567/+15557654321"
+ )
+ assert is_valid is True
+ assert error is None
+
+ def test_plugin_scheme_token_host_unaffected(self):
+ """Schemes whose 'host' slot is an opaque token (discord, slack,
+ telegram, pushover, teams) keep working — the IMDS check is a
+ no-op against non-IP strings."""
+ for url in (
+ "discord://webhook_id/token",
+ "slack://TestApp@TokenA/TokenB/TokenC",
+ "telegram://bottoken/ChatID",
+ "pushover://user@token",
+ "teams://group@token1/token2/token3",
+ ):
+ is_valid, error = NotificationURLValidator.validate_service_url(url)
+ assert is_valid is True, f"{url} should be valid, got: {error}"
+
+ def test_signal_metadata_hostname_via_dns_blocked(self):
+ """DNS-resolved hostname pointing at IMDS is rejected — closes
+ the easy ``signal://imds.attacker.example/...`` variant of the
+ bypass. (The full DNS-rebinding TOCTOU window is a separately
+ documented residual risk; this test only covers single-resolve
+ attackers.)"""
+ with patch("socket.getaddrinfo") as mock_dns:
+ mock_dns.return_value = [
+ (
+ socket.AF_INET,
+ socket.SOCK_STREAM,
+ 0,
+ "",
+ ("169.254.169.254", 0),
+ )
+ ]
+ is_valid, error = NotificationURLValidator.validate_service_url(
+ "signal://imds.attacker.example/+15551234567/+15557654321"
+ )
+ assert is_valid is False
+ assert "cloud-metadata" in error.lower()
+
+
class TestValidateServiceUrlStrict:
"""Tests for validate_service_url_strict static method."""