Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

feat(url_safety): add the CLAUDE_SEO_LOCAL_TARGETS local-target allowlist

Agrici Daniel3896dc190c24
diff --git a/SECURITY.md b/SECURITY.md
index 464bb0e..cedb972 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -60,7 +60,12 @@ claude-seo is a research and audit toolkit that runs on a user's workstation. It
- **IPv6-only audit targets.** The strict validator queries `family=AF_INET` for the initial resolution. Hosts with AAAA records only will surface as "DNS resolution failed". This is **fail-closed** by design — we'd rather refuse than connect to an unvalidated IPv6 endpoint. Tracked for a future patch (full dual-stack pinning, similar to the Playwright handler which already uses `AF_UNSPEC`).
- **Windows file permissions.** `os.fchmod(fd, 0o600)` is a no-op on Windows for non-ACL filesystems. Users on Windows should rely on per-user directory ACLs instead of POSIX mode bits.
-- **RFC 6598 (100.64.0.0/10) is refused.** Cloud providers serve instance metadata in this range, so `url_safety` treats it like RFC 1918. Tailscale also allocates from it: a staging site reached over Tailscale cannot be audited with the default policy. There is no escape hatch yet; an explicit local-target allowlist is planned.
+- **RFC 6598 (100.64.0.0/10) is refused by default.** Cloud providers serve instance metadata in this range, so `url_safety` treats it like RFC 1918. Tailscale also allocates from it, so a staging site reached over Tailscale is refused under the default policy. The escape hatch is `CLAUDE_SEO_LOCAL_TARGETS`, a comma-separated allowlist of `host` or `host:port` entries (for example `localhost:3000,127.0.0.1:8080,100.101.102.103`, the last being a Tailscale address). Its scope is deliberately narrow:
+ - It is consulted **only** for the first, top-level URL passed to `validate_url` / `validate_url_strict`. Redirect targets, embedded subresources, and every request the Playwright route handler sees stay fail-closed, so a page served from an allowlisted dev server still cannot pull anything else off the local network. Rendering an allowlisted host through Playwright is therefore not supported; the raw-HTTP path is.
+ - A host must be named exactly. There is no range, wildcard, or "allow private" mode, `host:port` matches that port only, and a bare `host` matches any port on that host.
+ - Cloud metadata endpoints are refused even when listed, by name (`metadata.google.internal` and its siblings) and by address (169.254.169.254, `fd00:ec2::254`, and Alibaba's 100.100.100.200, which sits inside the Tailscale range). Link-local, multicast, unspecified, and reserved addresses are never allowlistable.
+ - `is_safe_ip` is unchanged and reads no environment, so every fail-closed path downstream of the first connection is unaffected.
+ - Unset, claude-seo behaves exactly as it did before the flag existed.
## Security-relevant code paths
diff --git a/scripts/url_safety.py b/scripts/url_safety.py
index fb2a5f4..0c6c8da 100644
--- a/scripts/url_safety.py
+++ b/scripts/url_safety.py
@@ -46,6 +46,18 @@ is_safe_ip(ip_str) -> bool
URLSafetyError
ValueError subclass raised by the strict validator and pinning helpers.
+Local targets
+=============
+``CLAUDE_SEO_LOCAL_TARGETS`` is an opt-in, comma-separated allowlist of
+``host`` or ``host:port`` entries (for example
+``localhost:3000,127.0.0.1:8080,100.101.102.103``) that lets an operator
+audit a dev server, a staging host, or a machine reached over Tailscale.
+It is consulted **only** for the first, top-level URL handed to
+``validate_url`` / ``validate_url_strict``. Redirect targets, embedded
+subresources, and browser-issued requests never consult it, and cloud
+metadata endpoints are refused even when listed. Unset, the policy is
+exactly what it is without the feature.
+
Threading
=========
The DNS pinning helper is a critical section guarded by a non-blocking
@@ -73,6 +85,7 @@ in SECURITY.md.
from __future__ import annotations
import ipaddress
+import os
import re
import socket
import threading
@@ -214,6 +227,155 @@ def is_safe_ip(ip_str: str) -> bool:
)
+# ---------------------------------------------------------------------------
+# CLAUDE_SEO_LOCAL_TARGETS: an explicit, top-level-only allowlist
+# ---------------------------------------------------------------------------
+#
+# Auditing a site before it is deployed, or a staging host reached over
+# Tailscale, means pointing claude-seo at a non-public address. The default
+# policy refuses that, correctly: this toolkit follows URLs found on pages it
+# crawls, so a blanket "allow private" switch is an SSRF hole with a friendly
+# name.
+#
+# The allowlist is therefore narrow by construction:
+#
+# * It is consulted for the FIRST, top-level URL only, in ``validate_url``
+# and ``validate_url_strict``. Redirect targets, embedded subresources,
+# and browser-issued requests never reach it: those go through
+# ``is_safe_ip`` and ``_BLOCKED_HOSTNAMES``, which this module keeps
+# free of any environment dependency.
+# * A host must be named. There is no range, wildcard, or "all private".
+# * ``host:port`` matches that port only. A bare ``host`` matches any port.
+# * Cloud metadata endpoints are refused even when listed. This is the
+# trapdoor every "allow local" flag falls through: 169.254.169.254 is
+# link-local, 100.100.100.200 sits inside the Tailscale range this
+# allowlist exists to permit, and fd00:ec2::254 is unique-local rather
+# than link-local, so no single address predicate catches all three.
+_LOCAL_TARGETS_ENV = "CLAUDE_SEO_LOCAL_TARGETS"
+
+
+# Hostnames and literals no allowlist entry can ever unblock.
+_NEVER_ALLOWLISTABLE_HOSTNAMES: frozenset[str] = frozenset(
+ {
+ "metadata",
+ "metadata.goog",
+ "metadata.google.internal",
+ "metadata.azure.com",
+ "metadata.ec2.internal",
+ "metadata.oraclecloud.com",
+ "169.254.169.254", # AWS, Azure, GCP, Oracle, Alibaba metadata IPv4
+ "100.100.100.200", # Alibaba metadata, inside RFC 6598
+ "fd00:ec2::254", # AWS IMDS IPv6
+ "0.0.0.0",
+ }
+)
+
+
+def _is_allowlistable_ip(ip_str: str) -> bool:
+ """True when an explicit allowlist entry may reach ``ip_str``.
+
+ Loopback, RFC 1918, and RFC 6598 (Tailscale) are the ranges an operator
+ can opt into. Link-local stays refused in both families: that is where
+ the IMDS endpoints live, and Python's ``is_private`` reports
+ 169.254.0.0/16 as private, so a plain "loopback or private" carve-out
+ would hand back 169.254.169.254. Multicast, unspecified, and reserved
+ are refused for the same reason: nothing an SEO audit legitimately
+ targets lives there.
+ """
+ try:
+ ip = ipaddress.ip_address(ip_str)
+ except ValueError:
+ return False
+ if ip.version == 6 and ip.ipv4_mapped is not None:
+ ip = ip.ipv4_mapped
+ if str(ip) in _NEVER_ALLOWLISTABLE_HOSTNAMES:
+ return False
+ if ip.is_link_local or ip.is_multicast or ip.is_unspecified:
+ return False
+ if ip.is_loopback:
+ # Checked before is_reserved: IPv6 ::/8 is reserved and contains ::1.
+ return True
+ return not ip.is_reserved
+
+
+def _parse_local_target(entry: str) -> Optional[tuple[str, Optional[int]]]:
+ """Parse one ``host`` or ``host:port`` entry into ``(host, port|None)``.
+
+ Returns ``None`` for anything unparseable, so a typo in the environment
+ variable widens nothing.
+ """
+ entry = entry.strip()
+ if not entry:
+ return None
+ # A bare IPv6 literal has more than one colon and no brackets; urlparse
+ # would read its last group as a port.
+ if entry.count(":") > 1 and "[" not in entry:
+ candidate, port = entry, None
+ else:
+ try:
+ parsed = urlparse(f"//{entry}")
+ candidate, port = parsed.hostname, parsed.port
+ except ValueError:
+ return None
+ if not candidate:
+ return None
+ try:
+ return normalize_hostname(candidate), port
+ except URLSafetyError:
+ return None
+
+
+def _local_targets() -> tuple[tuple[str, Optional[int]], ...]:
+ """The parsed contents of ``CLAUDE_SEO_LOCAL_TARGETS``.
+
+ Read on every call rather than cached: the variable is operator
+ configuration, and a cached empty tuple from import time would make the
+ setting silently inert in a long-lived process.
+ """
+ raw = os.environ.get(_LOCAL_TARGETS_ENV, "")
+ if not raw.strip():
+ return ()
+ parsed = (_parse_local_target(part) for part in raw.split(","))
+ return tuple(entry for entry in parsed if entry is not None)
+
+
+def _is_allowlisted_local_target(hostname: str, port: Optional[int]) -> bool:
+ """True when ``hostname``/``port`` is named in ``CLAUDE_SEO_LOCAL_TARGETS``.
+
+ ``hostname`` must already be normalized. Metadata endpoints are refused
+ before the list is even read.
+ """
+ if hostname in _NEVER_ALLOWLISTABLE_HOSTNAMES:
+ return False
+ if not _is_allowlistable_ip(hostname) and _looks_like_ip(hostname):
+ return False
+ for entry_host, entry_port in _local_targets():
+ if entry_host != hostname:
+ continue
+ if entry_port is None or entry_port == port:
+ return True
+ return False
+
+
+def _looks_like_ip(hostname: str) -> bool:
+ try:
+ ipaddress.ip_address(hostname)
+ except ValueError:
+ return False
+ return True
+
+
+def _url_port(parsed) -> Optional[int]:
+ """The URL's effective port, or ``None`` if the authority names a bad one."""
+ try:
+ explicit = parsed.port
+ except ValueError:
+ return None
+ if explicit is not None:
+ return explicit
+ return 443 if parsed.scheme == "https" else 80
+
+
def normalize_hostname(hostname: str) -> str:
"""
Canonicalize a hostname so that obfuscated forms cannot bypass the
@@ -286,13 +448,20 @@ def validate_url(url: str) -> bool:
hostname = normalize_hostname(parsed.hostname)
except URLSafetyError:
return False
- if hostname in _BLOCKED_HOSTNAMES:
+ # An unparseable port matches no allowlist entry, but is otherwise left
+ # to the caller and to validate_url_strict: this function is a parse-time
+ # check and its answer for such URLs is unchanged.
+ port = _url_port(parsed)
+ allowlisted = port is not None and _is_allowlisted_local_target(hostname, port)
+ if hostname in _BLOCKED_HOSTNAMES and not allowlisted:
return False
try:
ipaddress.ip_address(hostname)
except ValueError:
return True # Hostname is a name, not a literal — OK at parse time.
- return is_safe_ip(hostname)
+ if is_safe_ip(hostname):
+ return True
+ return allowlisted and _is_allowlistable_ip(hostname)
def validate_url_strict(url: str) -> tuple[str, str]:
@@ -317,7 +486,14 @@ def validate_url_strict(url: str) -> tuple[str, str]:
raise URLSafetyError("URL has no hostname")
hostname = normalize_hostname(parsed.hostname)
- if hostname in _BLOCKED_HOSTNAMES:
+ port = _url_port(parsed)
+ if port is None:
+ raise URLSafetyError(f"Invalid port in URL authority: {url!r}")
+
+ # The CLAUDE_SEO_LOCAL_TARGETS allowlist is read here and nowhere the
+ # request chain can reach later, which is what keeps it top-level only.
+ allowlisted = _is_allowlisted_local_target(hostname, port)
+ if hostname in _BLOCKED_HOSTNAMES and not allowlisted:
raise URLSafetyError(f"Blocked hostname: {hostname}")
# If the hostname is an IP literal, validate it directly without DNS.
@@ -327,11 +503,12 @@ def validate_url_strict(url: str) -> tuple[str, str]:
literal = None
if literal is not None:
- if not is_safe_ip(hostname):
+ if not is_safe_ip(hostname) and not (
+ allowlisted and _is_allowlistable_ip(hostname)
+ ):
raise URLSafetyError(f"Blocked IP literal: {hostname}")
return url, str(literal)
- port = parsed.port or (443 if parsed.scheme == "https" else 80)
try:
addrinfo = socket.getaddrinfo(
hostname,
@@ -347,11 +524,14 @@ def validate_url_strict(url: str) -> tuple[str, str]:
raise URLSafetyError(f"No A records for {hostname}")
for ip_str in resolved_ips:
- if not is_safe_ip(ip_str):
- raise URLSafetyError(
- f"DNS rebinding refused: {hostname} resolves to "
- f"non-public IP {ip_str}"
- )
+ if is_safe_ip(ip_str):
+ continue
+ if allowlisted and _is_allowlistable_ip(ip_str):
+ continue # Named in CLAUDE_SEO_LOCAL_TARGETS; see that block.
+ raise URLSafetyError(
+ f"DNS rebinding refused: {hostname} resolves to "
+ f"non-public IP {ip_str}"
+ )
pinned = resolved_ips[0]
return url, pinned
diff --git a/skills/seo-technical/SKILL.md b/skills/seo-technical/SKILL.md
index 1a8e175..d7b983e 100644
--- a/skills/seo-technical/SKILL.md
+++ b/skills/seo-technical/SKILL.md
@@ -237,6 +237,30 @@ If DataForSEO MCP tools are available, use `on_page_instant_pages` for real page
If Google API credentials are configured, use `"${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run pagespeed_check.py <url> --json` for real PSI + CrUX field data (replaces lab-only CWV estimates), `"${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run crux_history.py <url> --json` for 25-week CWV trends, and `"${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run gsc_inspect.py <url> --json` for real indexation status per URL.
+## Auditing a Local or Private Host
+
+`url_safety` refuses loopback and private addresses by default, so `http://localhost:3000` and a staging host on Tailscale fail with "Blocked hostname" or "Blocked IP literal". That default is deliberate: these scripts follow URLs found on the pages they crawl.
+
+To audit a pre-deployment host, the operator names it in `CLAUDE_SEO_LOCAL_TARGETS`, a comma-separated list of `host` or `host:port` entries:
+
+```bash
+CLAUDE_SEO_LOCAL_TARGETS="localhost:3000,127.0.0.1:8080,100.101.102.103" \
+ "${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run fetch_page.py http://localhost:3000/
+```
+
+What it does and does not cover:
+
+| Behaviour | Allowlisted host |
+|-----------|------------------|
+| First, top-level URL over raw HTTP | Allowed |
+| Redirect target reached from that URL | Refused |
+| Subresource fetched by a rendered page | Refused |
+| Playwright renders (`--render`, screenshots) | Refused; use the raw-HTTP path |
+| A host not named in the variable | Refused |
+| Cloud metadata endpoints, even when listed | Refused |
+
+`host:port` matches that port only; a bare `host` matches any port. With the variable unset the policy is unchanged. Never suggest setting it for a host the user does not control. See SECURITY.md.
+
## Error Handling
| Scenario | Action |
diff --git a/tests/test_url_safety.py b/tests/test_url_safety.py
index e26d45c..ce21e5b 100644
--- a/tests/test_url_safety.py
+++ b/tests/test_url_safety.py
@@ -912,3 +912,191 @@ def test_safe_requests_session_refuses_a_non_public_proxy(monkeypatch) -> None:
):
with url_safety.safe_requests_session("https://example.com/"):
pass
+
+
+# ---------------------------------------------------------------------------
+# CLAUDE_SEO_LOCAL_TARGETS: explicit, top-level-only local allowlist
+# ---------------------------------------------------------------------------
+
+
[email protected](autouse=True)
+def _clear_local_targets(monkeypatch):
+ """No test in this module inherits the developer's own allowlist."""
+ monkeypatch.delenv("CLAUDE_SEO_LOCAL_TARGETS", raising=False)
+
+
+def _loopback_resolver(host_ips: dict):
+ def fake_getaddrinfo(host, port, *args, **kwargs):
+ if host in host_ips:
+ return _addrinfo(host_ips[host], port or 0)
+ raise socket.gaierror(socket.EAI_NONAME, f"unmocked host {host!r}")
+
+ return fake_getaddrinfo
+
+
+def test_local_targets_unset_leaves_behaviour_unchanged(monkeypatch) -> None:
+ """The default policy must be byte-for-byte what it was before the flag."""
+ monkeypatch.delenv("CLAUDE_SEO_LOCAL_TARGETS", raising=False)
+ assert url_safety.validate_url("http://localhost:3000/") is False
+ assert url_safety.validate_url("http://127.0.0.1:8080/") is False
+ assert url_safety.validate_url("http://192.168.1.10/") is False
+ assert url_safety.validate_url("http://100.101.102.103/") is False
+ with pytest.raises(url_safety.URLSafetyError, match="Blocked hostname"):
+ url_safety.validate_url_strict("http://localhost:3000/")
+ with pytest.raises(url_safety.URLSafetyError, match="Blocked hostname"):
+ url_safety.validate_url_strict("http://127.0.0.1:8080/")
+ with pytest.raises(url_safety.URLSafetyError, match="Blocked IP literal"):
+ url_safety.validate_url_strict("http://192.168.1.10/")
+
+
+def test_empty_local_targets_is_the_same_as_unset(monkeypatch) -> None:
+ for value in ("", " ", ",", " , "):
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", value)
+ assert url_safety.validate_url("http://localhost:3000/") is False
+
+
+def test_allowlisted_hostname_passes_at_top_level(monkeypatch) -> None:
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000,127.0.0.1:8080")
+ assert url_safety.validate_url("http://localhost:3000/nl") is True
+
+ resolver = _loopback_resolver({"localhost": "127.0.0.1"})
+ with patch.object(url_safety.socket, "getaddrinfo", side_effect=resolver):
+ norm, pinned = url_safety.validate_url_strict("http://localhost:3000/nl")
+ assert norm == "http://localhost:3000/nl"
+ assert pinned == "127.0.0.1"
+
+
+def test_allowlisted_ip_literal_passes_at_top_level(monkeypatch) -> None:
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "127.0.0.1:8080")
+ assert url_safety.validate_url("http://127.0.0.1:8080/") is True
+ assert url_safety.validate_url_strict("http://127.0.0.1:8080/") == (
+ "http://127.0.0.1:8080/",
+ "127.0.0.1",
+ )
+
+
+def test_bare_host_entry_matches_any_port_and_covers_tailscale(monkeypatch) -> None:
+ """RFC 6598 is the Tailscale range; a bare entry names the host only."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "100.101.102.103")
+ assert url_safety.validate_url("http://100.101.102.103/") is True
+ assert url_safety.validate_url("https://100.101.102.103:8443/staging") is True
+ assert url_safety.validate_url_strict("http://100.101.102.103/")[1] == (
+ "100.101.102.103"
+ )
+
+
+def test_port_mismatch_is_refused(monkeypatch) -> None:
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000")
+ assert url_safety.validate_url("http://localhost:3001/") is False
+ assert url_safety.validate_url("http://localhost/") is False # implicit :80
+ with pytest.raises(url_safety.URLSafetyError, match="Blocked hostname"):
+ url_safety.validate_url_strict("http://localhost:3001/")
+
+
+def test_unlisted_host_is_refused(monkeypatch) -> None:
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000")
+ assert url_safety.validate_url("http://127.0.0.1:3000/") is False
+ assert url_safety.validate_url("http://192.168.1.10:3000/") is False
+ with pytest.raises(url_safety.URLSafetyError, match="Blocked IP literal"):
+ url_safety.validate_url_strict("http://192.168.1.10:3000/")
+
+
+ "target",
+ [
+ "169.254.169.254",
+ "metadata.google.internal",
+ "[fd00:ec2::254]",
+ "100.100.100.200",
+ "metadata.goog",
+ "metadata.azure.com",
+ ],
+)
+def test_metadata_endpoints_are_never_allowlistable(monkeypatch, target) -> None:
+ """Listing a metadata endpoint must not unblock it. This is the trapdoor
+ a naive 'allow loopback and private' carve-out falls through."""
+ host = target.strip("[]")
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", f"{host},{host}:80,{host}:3128")
+ assert url_safety.validate_url(f"http://{target}/latest/meta-data/") is False
+ with pytest.raises(url_safety.URLSafetyError):
+ url_safety.validate_url_strict(f"http://{target}/latest/meta-data/")
+
+
+def test_allowlist_does_not_unblock_link_local_resolution(monkeypatch) -> None:
+ """A listed name that resolves into 169.254/16 is still refused: the
+ allowlist forgives loopback, RFC 1918 and RFC 6598, never link-local."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "sneaky.local:80")
+ resolver = _loopback_resolver({"sneaky.local": "169.254.169.254"})
+ with patch.object(url_safety.socket, "getaddrinfo", side_effect=resolver):
+ with pytest.raises(url_safety.URLSafetyError, match="DNS rebinding refused"):
+ url_safety.validate_url_strict("http://sneaky.local/")
+
+
+def test_allowlist_does_not_change_is_safe_ip(monkeypatch) -> None:
+ """is_safe_ip stays a pure predicate. Every fail-closed path downstream
+ (redirects, subresources) depends on it not reading the environment."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000,127.0.0.1:8080")
+ assert url_safety.is_safe_ip("127.0.0.1") is False
+ assert url_safety.is_safe_ip("192.168.1.10") is False
+ assert url_safety.is_safe_ip("100.101.102.103") is False
+
+
+def test_allowlisted_host_is_refused_as_a_redirect_target(monkeypatch) -> None:
+ """The allowlist is consulted once, for the top-level URL. Inside the
+ pinned scope a 30x to the same host resolves through the fall-through
+ check, which does not read it."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000")
+ resolver = _loopback_resolver({"localhost": "127.0.0.1"})
+ with patch.object(url_safety.socket, "getaddrinfo", side_effect=resolver):
+ with url_safety._pin_dns("audited.example", "93.184.216.34", 443):
+ with pytest.raises(socket.gaierror, match="non-public IP"):
+ socket.getaddrinfo("localhost", 3000)
+
+
+def test_allowlisted_host_is_refused_as_a_browser_subresource(monkeypatch) -> None:
+ """The Playwright route handler never reads the allowlist, so a rendered
+ page cannot pull a subresource off the allowlisted dev server."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000,127.0.0.1:8080")
+ handler = url_safety.make_safe_playwright_route_handler()
+ resolver = _loopback_resolver({"localhost": "127.0.0.1"})
+ with patch.object(url_safety.socket, "getaddrinfo", side_effect=resolver):
+ route = _FakeRoute()
+ handler(route, _FakeRequest("http://localhost:3000/app.js", "script"))
+ assert route.action == "abort"
+ route = _FakeRoute()
+ handler(route, _FakeRequest("http://127.0.0.1:8080/app.js", "script"))
+ assert route.action == "abort"
+
+
+def test_local_target_entries_are_normalized(monkeypatch) -> None:
+ """Entries go through normalize_hostname, so case, a trailing dot, and
+ obfuscated IPv4 cannot be used to smuggle a second spelling past a
+ reviewer reading the environment variable."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", " LocalHost.:3000 , 2130706433:8080 ")
+ assert url_safety._local_targets() == (("localhost", 3000), ("127.0.0.1", 8080))
+ assert url_safety.validate_url("http://localhost:3000/") is True
+ assert url_safety.validate_url("http://127.0.0.1:8080/") is True
+
+
+def test_malformed_entries_are_dropped_not_widened(monkeypatch) -> None:
+ monkeypatch.setenv(
+ "CLAUDE_SEO_LOCAL_TARGETS", "localhost:notaport,,:8080,localhost:3000"
+ )
+ assert url_safety._local_targets() == (("localhost", 3000),)
+ assert url_safety.validate_url("http://localhost:3000/") is True
+ assert url_safety.validate_url("http://localhost:8080/") is False
+
+
+def test_ipv6_entries_parse_in_both_spellings(monkeypatch) -> None:
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "[::1]:3000,fd00::1")
+ assert url_safety._local_targets() == (("::1", 3000), ("fd00::1", None))
+ assert url_safety.validate_url("http://[::1]:3000/") is True
+ assert url_safety.validate_url("http://[::1]:3001/") is False
+
+
+def test_allowlist_does_not_bypass_authority_confusion_checks(monkeypatch) -> None:
+ """The allowlist relaxes the address policy, nothing else."""
+ monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "localhost:3000")
+ assert url_safety.validate_url("http://user@localhost:3000/") is False
+ assert url_safety.validate_url("http://localhost:3000\\@evil.example/") is False
+ assert url_safety.validate_url("ftp://localhost:3000/") is False