Dough Git

commit

AAAAAAAAAAAA

commit
78d244424c7d6afa9f42f653bcfd92e34f080c82
author
Clove Twilight <[email protected]>
date
2026-10-27 09:11

diff --git a/commands/cogs/lookups/whois.py b/commands/cogs/lookups/whois.py
index e96360b..d3c08e1 100644
--- a/commands/cogs/lookups/whois.py
+++ b/commands/cogs/lookups/whois.py
@@ -59,7 +59,16 @@ domainFields = (
         ("registrar", "sponsoring registrar", "registrar name"),
         False,
     ),
-    ("Registrant", ("registrant organization", "holder", "org"), False),
+    (
+        "Owner",
+        (
+            "registrant name",
+            "registrant organization",
+            "holder",
+            "org",
+        ),
+        False,
+    ),
     ("Country", ("registrant country", "country"), False),
     (
         "Registered",
@@ -100,7 +109,7 @@ domainFields = (
 )
 
 domainContactFields = (
-    ("Registrar URL", ("registrar url", "referral url"), False),
+    ("URL", ("registrar url", "referral url"), False),
     (
         "Abuse Email",
         ("registrar abuse contact email", "abuse contact"),
@@ -131,9 +140,9 @@ networkFields = (
 )
 
 networkContactFields = (
-    ("Abuse Email", ("orgabuseemail", "abuse-mailbox"), False),
-    ("Abuse Phone", ("orgabusephone",), False),
-    ("Abuse Handle", ("abuse-c",), False),
+    ("Email", ("orgabuseemail", "abuse-mailbox"), False),
+    ("Phone", ("orgabusephone",), False),
+    ("Handle", ("abuse-c",), False),
 )
 
 dateFormats = (
@@ -153,16 +162,13 @@ redactionMarkers = (
     "data protected",
 )
 
-# person-level contact lines in raw port 43 text. the organisation,
-# country and state of a contact are kept since those identify the
-# registrant without pointing at anyone's front door
-personalLine = re.compile(
-    r"^\s*(?:"
-    r"(?:registrant|admin|administrative|tech|technical|billing)"
-    r"(?![^:]*\b(?:organi[sz]ation|org|country|state|province)\b)"
-    r"|person|address|phone|fax-no|e-mail"
-    r")[^:]*:",
-    re.IGNORECASE,
+# the contact roles a domain record carries, as (heading, rdap key
+# prefix, port 43 key prefix). the registrant is the owner and gets its
+# own page, the rest share the contacts page
+contactRoles = (
+    ("Admin", "admin", "admin"),
+    ("Technical", "technical", "tech"),
+    ("Billing", "billing", "billing"),
 )
 
 eppPrefixes = ("client", "server", "pending")
@@ -397,12 +403,65 @@ def nameServersFrom(fields: dict[str, list[str]]) -> list[str]:
     return servers
 
 
-def scrubRecord(text: str) -> str:
-    return "\n".join(
-        line.split(":", 1)[0] + ": [hidden]"
-        if personalLine.match(line)
-        else line
-        for line in text.strip().splitlines()
+def present(
+    pairs: tuple[tuple[str, str | None], ...],
+) -> list[components.Field]:
+    return [(name, value[:1024]) for name, value in pairs if value]
+
+
+def portContact(
+    fields: dict[str, list[str]], prefix: str
+) -> list[components.Field]:
+    def get(*suffixes: str) -> str | None:
+        return firstValue(
+            fields, tuple(f"{prefix} {suffix}" for suffix in suffixes)
+        )
+
+    streets = [
+        street
+        for street in fields.get(f"{prefix} street", [])
+        if not isPlaceholder(street)
+    ]
+    address = [
+        part
+        for part in (
+            *streets,
+            get("city"),
+            get("state/province", "state", "province"),
+            get("postal code"),
+            get("country"),
+        )
+        if part
+    ]
+    phone = get("phone")
+    fax = get("fax")
+    return present(
+        (
+            ("Name", get("name")),
+            ("Organisation", get("organization", "organisation")),
+            ("Email", get("email")),
+            ("Phone", formatPhone(phone) if phone else None),
+            ("Fax", formatPhone(fax) if fax else None),
+            ("Address", ", ".join(address) or None),
+        )
+    )
+
+
+def contactsBody(
+    groups: list[tuple[str, list[components.Field]]],
+    owner: list[components.Field],
+) -> str:
+    # admin and tech are usually the owner again, so say so rather than
+    # printing the same block three times
+    return "\n\n".join(
+        f"**{heading}**\n"
+        + (
+            "> Same as the owner"
+            if owner and fields == owner
+            else quoteLines(fields)
+        )
+        for heading, fields in groups
+        if fields
     )
 
 
@@ -410,7 +469,8 @@ def buildPages(
     overview: list[components.Field],
     statuses: list[str],
     nameServers: list[str],
-    contacts: list[components.Field],
+    owner: list[components.Field],
+    contacts: list[tuple[str, list[components.Field]]],
     raw: str | None = None,
 ) -> tuple[Page, ...]:
     pages: list[Page] = []
@@ -423,6 +483,15 @@ def buildPages(
                 quoteLines(overview),
             )
         )
+    if owner:
+        pages.append(
+            Page(
+                "owner",
+                "Owner",
+                "Who the domain is registered to",
+                quoteLines(owner),
+            )
+        )
     if statuses:
         pages.append(
             Page(
@@ -441,13 +510,13 @@ def buildPages(
                 quoteList([f"`{server}`" for server in nameServers]),
             )
         )
-    if contacts:
+    if any(fields for _, fields in contacts):
         pages.append(
             Page(
                 "contacts",
                 "Contacts",
-                "Registrar and abuse contacts",
-                quoteLines(contacts),
+                "Registrar, abuse and other contacts",
+                contactsBody(contacts, owner),
             )
         )
     if raw:
@@ -479,10 +548,6 @@ def rdapCandidates(domain: str) -> list[tuple[str, str]]:
 
 
 def rdapPages(record: dict[str, Any]) -> tuple[Page, ...]:
-    # contact names, emails, phones and addresses for the registrant,
-    # admin and tech are left out on purpose: rdap hands them over for
-    # unredacted registrations, and the bot shouldn't post someone's
-    # home address into a channel
     def text(key: str) -> str | None:
         value = record.get(key)
         if not isinstance(value, str) or isPlaceholder(value):
@@ -495,35 +560,52 @@ def rdapPages(record: dict[str, Any]) -> tuple[Page, ...]:
             return None
         return formatStamp(value)
 
-    def present(
-        pairs: tuple[tuple[str, str | None], ...],
-    ) -> list[components.Field]:
-        return [(name, value) for name, value in pairs if value]
+    def phone(key: str) -> str | None:
+        value = text(key)
+        return formatPhone(value) if value else None
+
+    def contact(prefix: str) -> list[components.Field]:
+        return present(
+            (
+                ("Name", text(f"{prefix}_name")),
+                ("Organisation", text(f"{prefix}_organization")),
+                ("Email", text(f"{prefix}_email")),
+                ("Phone", phone(f"{prefix}_phone")),
+                ("Fax", phone(f"{prefix}_fax")),
+                ("Address", text(f"{prefix}_address")),
+            )
+        )
 
-    phone = text("registrar_phone")
-    abusePhone = text("abuse_phone")
     overview = present(
         (
             ("Registrar", text("registrar_name")),
-            ("Registrant", text("registrant_organization")),
+            (
+                "Owner",
+                text("registrant_name") or text("registrant_organization"),
+            ),
             ("Registered", date("created_date")),
             ("Updated", date("updated_date")),
             ("Expires", date("expires_date")),
             ("DNSSEC", text("dnssec")),
         )
     )
-    contacts = present(
+    owner = contact("registrant")
+    contacts = [
+        ("Registrar", contact("registrar")),
         (
-            ("Registrar Email", text("registrar_email")),
-            ("Registrar Phone", formatPhone(phone) if phone else None),
-            ("Registrar Address", text("registrar_address")),
-            ("Abuse Email", text("abuse_email")),
-            (
-                "Abuse Phone",
-                formatPhone(abusePhone) if abusePhone else None,
+            "Abuse",
+            present(
+                (
+                    ("Email", text("abuse_email")),
+                    ("Phone", phone("abuse_phone")),
+                )
             ),
-        )
-    )
+        ),
+        *(
+            (heading, contact(prefix))
+            for heading, prefix, _ in contactRoles
+        ),
+    ]
     statuses: list[str] = []
     for status in record.get("status") or []:
         code = eppCode(status) if isinstance(status, str) else ""
@@ -534,7 +616,7 @@ def rdapPages(record: dict[str, Any]) -> tuple[Page, ...]:
         for server in record.get("nameservers") or []
         if isinstance(server, str)
     ]
-    return buildPages(overview, statuses, servers, contacts)
+    return buildPages(overview, statuses, servers, owner, contacts)
 
 
 async def askServer(server: str, query: str) -> str:
@@ -648,10 +730,19 @@ async def buildReport(target: str) -> Report:
     server, text = records[-1]
     fields = mergeRecords(records)
     overview = pickFields(fields, networkFields if isIp else domainFields)
-    contacts = pickFields(
-        fields, networkContactFields if isIp else domainContactFields
-    )
-    raw = scrubRecord(text)
+    if isIp:
+        owner: list[components.Field] = []
+        contacts = [("Abuse", pickFields(fields, networkContactFields))]
+    else:
+        owner = portContact(fields, "registrant")
+        contacts = [
+            ("Registrar", pickFields(fields, domainContactFields)),
+            *(
+                (heading, portContact(fields, prefix))
+                for heading, _, prefix in contactRoles
+            ),
+        ]
+    raw = text.strip()
 
     if not overview and any(
         marker in text.lower() for marker in notFoundMarkers
@@ -667,6 +758,7 @@ async def buildReport(target: str) -> Report:
             overview,
             statusesFrom(fields),
             [] if isIp else nameServersFrom(fields),
+            owner,
             contacts,
             raw,
         ),
diff --git a/tests/test_whois.py b/tests/test_whois.py
index 21d84a1..4c394d6 100644
--- a/tests/test_whois.py
+++ b/tests/test_whois.py
@@ -57,16 +57,20 @@ def test_epp_codes_from_rdap_and_port_43_agree() -> None:
     assert whois.formatStatus("connect") == "`connect`"
 
 
-def test_rdap_pages_never_leak_personal_contacts() -> None:
+def test_rdap_pages_show_the_owner_and_contacts() -> None:
+    owner = {
+        "name": "Some Person",
+        "email": "[email protected]",
+        "address": "1 Home Street, Sheffield",
+        "phone": "tel:+44.0000000000",
+    }
     record = {
         "domain_name": "example.gay",
         "registrar_name": "NAMECHEAP INC",
         "registrar_phone": "tel:+1.6613102107",
-        "registrant_name": "Some Person",
-        "registrant_email": "[email protected]",
-        "registrant_address": "1 Home Street",
-        "registrant_phone": "tel:+44.0000000000",
-        "technical_email": "[email protected]",
+        **{f"registrant_{key}": value for key, value in owner.items()},
+        **{f"technical_{key}": value for key, value in owner.items()},
+        "admin_name": "Someone Else",
         "abuse_email": "[email protected]",
         "created_date": dt.datetime(2026, 3, 15, tzinfo=dt.UTC),
         "status": ["client transfer prohibited"],
@@ -74,46 +78,56 @@ def test_rdap_pages_never_leak_personal_contacts() -> None:
     }
 
     pages = {page.key: page for page in whois.rdapPages(record)}
-    rendered = "\n".join(page.body for page in pages.values())
 
-    assert list(pages) == ["overview", "status", "nameservers", "contacts"]
-    assert "> **Registrar**: NAMECHEAP INC" in pages["overview"].body
+    assert list(pages) == [
+        "overview",
+        "owner",
+        "status",
+        "nameservers",
+        "contacts",
+    ]
+    assert "> **Owner**: Some Person" in pages["overview"].body
     assert ":R>" in pages["overview"].body
+    assert "> **Email**: [email protected]" in pages["owner"].body
+    assert "> **Phone**: +44.0000000000" in pages["owner"].body
+    assert "1 Home Street, Sheffield" in pages["owner"].body
     assert "`ns1.example.com`" in pages["nameservers"].body
-    assert "+1.6613102107" in pages["contacts"].body
-    for leaked in ("Some Person", "[email protected]", "Home Street"):
-        assert leaked not in rendered
+    contacts = pages["contacts"].body
+    assert "> **Phone**: +1.6613102107" in contacts
+    assert "**Abuse**\n> **Email**: [email protected]" in contacts
+    assert "**Technical**\n> Same as the owner" in contacts
+    assert "**Admin**\n> **Name**: Someone Else" in contacts
+    assert "Billing" not in contacts
 
 
 def test_rdap_pages_drop_redacted_registrant() -> None:
-    record = {"registrant_organization": "REDACTED FOR PRIVACY"}
+    record = {
+        "registrant_name": "REDACTED FOR PRIVACY",
+        "registrant_organization": "REDACTED FOR PRIVACY",
+    }
     assert whois.rdapPages(record) == ()
 
 
-def test_scrub_record_hides_people_but_keeps_registry_facts() -> None:
+def test_port_contact_builds_an_address_from_its_parts() -> None:
     lines = [
-        "Domain Name: example.gay",
-        "Registrar: NAMECHEAP INC",
         "Registrant Name: Some Person",
-        "Registrant Organization: Example Ltd",
+        "Registrant Organization: REDACTED FOR PRIVACY",
         "Registrant Street: 1 Home Street",
+        "Registrant Street: Flat 2",
+        "Registrant City: Sheffield",
+        "Registrant Postal Code: S1 1AA",
         "Registrant Country: GB",
-        "Admin Email: [email protected]",
-        "Tech Phone: +44.0000000000",
-        "Registrar Abuse Contact Email: [email protected]",
-        "address:        1 Home Street",
-        "e-mail:         [email protected]",
+        "Registrant Phone: +44.0000000000",
+        "Registrant Email: [email protected]",
     ]
-    raw = "\n".join(lines)
-
-    scrubbed = whois.scrubRecord(raw)
+    fields = whois.parseRecord("\n".join(lines))
 
-    for leaked in ("Some Person", "Home Street", "[email protected]"):
-        assert leaked not in scrubbed
-    assert "Registrant Name: [hidden]" in scrubbed
-    assert "Registrant Organization: Example Ltd" in scrubbed
-    assert "Registrant Country: GB" in scrubbed
-    assert "[email protected]" in scrubbed
+    assert whois.portContact(fields, "registrant") == [
+        ("Name", "Some Person"),
+        ("Email", "[email protected]"),
+        ("Phone", "+44.0000000000"),
+        ("Address", "1 Home Street, Flat 2, Sheffield, S1 1AA, GB"),
+    ]
 
 
 def test_report_menu_round_trips_through_its_custom_id() -> None:
diff --git a/web/privacy.html b/web/privacy.html
index 63e57be..0d2e68f 100644
--- a/web/privacy.html
+++ b/web/privacy.html
@@ -201,7 +201,7 @@
         <li><strong>Pluralpedia</strong> and <strong>morethanone.info</strong>, which are linked by <code>/snippet</code>'s plurality explainer.</li>
         <li><strong>girlcockx.com</strong>, which receives the post URL you give <code>/tweet</code>, to build the embed.</li>
         <li><strong>Bluesky's public API</strong>, which receives the handle and post ID you give <code>/bluesky</code>. The resulting embed links to <strong>xsky.app</strong>.</li>
-        <li><strong>RDAP and WHOIS servers</strong>, which receive the domain or IP you give <code>/whois</code>. Domains are looked up over RDAP first, starting from IANA's list of registry servers, and fall back to WHOIS, which starts at IANA and follows referrals to the registry and registrar for that name &mdash; so more than one operator sees the query. It never carries anything about you, since neither protocol has a facility for it. Sandrone also leaves personal contact details out of what it posts, even when a registry hands them over.</li>
+        <li><strong>RDAP and WHOIS servers</strong>, which receive the domain or IP you give <code>/whois</code>. Domains are looked up over RDAP first, starting from IANA's list of registry servers, and fall back to WHOIS, which starts at IANA and follows referrals to the registry and registrar for that name &mdash; so more than one operator sees the query. It never carries anything about you, since neither protocol has a facility for it. Whatever contact details the registry publishes for that domain, including the owner's, are shown in the reply.</li>
         <li><strong>Cloudflare (1.1.1.1)</strong> and <strong>Quad9 (9.9.9.9)</strong>, the public DNS resolvers that receive the domain or IP you give <code>/dig</code>. The query carries the bot server's address, not yours.</li>
         <li><strong>The Doughmination API</strong> (<code>doughmination.uk</code>), which <code>/profile</code> queries with the Discord ID of whoever the command is run on, and which <code>/genshin</code> queries with the Genshin UID you type. That UID is a game account number you supply, not something Sandrone knows about you, and it is not recorded anywhere.</li>
         <li><strong>Enka.Network</strong>, which is where the Doughmination API gets Genshin account data from. Your UID reaches it through that API when you run <code>/genshin</code>; nothing about your Discord account does.</li>