Skip to content

Resolve the DNS alias owner server-side - #836

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/820-dns-alias-tenancy
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/820-dns-alias-tenancy

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #820. Advisory: GHSA-q9qq-223w-mqx6 (draft; publishes on merge). Also fixes the
decision-free half of #835 (ip_address validation); the allowlist decision there stays
open.

The defect

lambda/dns-updater builds the canonical record from the SigV4-verified caller:

// ... anchored to the authorized account — a caller can only write records under its
// own account's subdomain.
fqdn := getFullDNSName(req.RecordName, accountID, reqDomain)
...
alias := aliasDNSName(req.RecordName, req.AccountName, reqDomain)

The comment is true of the line it describes and false of the one eight lines later.
req.AccountName comes from the request body and was validated only as a DNS label,
so any caller could UPSERT {record}.{any-tenant-slug}.{domain} as a CNAME onto its own
instance, or DELETE it.

aliasDNSName is not at fault — it validates the slug correctly. The caller never checked
ownership.

Why resolving it server-side was awkward

There was nowhere obvious to resolve ownership from:

  • The friendly name comes from account:GetAccountInformation, which for a member
    account requires org-management or delegated-admin credentials. The management account
    of this org is one spore.host must never obtain access to, so that route is closed by a
    project constraint rather than by effort.
  • The natural registry, the spore-portal-accounts DynamoDB table, is written by the
    portal rather than by spawn and currently holds 0 items. A lookup against it would
    authorize nothing and would break the one tenant actually using aliases.

So ownership is derived from the zone's own state, which already encodes it: an existing
alias CNAME points at {record}.{base36}.{domain}, and that base36 label decodes back to
the owning account ID.

  • First use of an unclaimed slug takes it, and records a _spore-owner.{slug} TXT
    marker
    . That matters: without it, deleting the last alias CNAME makes the slug look
    unclaimed again, which is exactly when a squatter would take it.
  • The explicit marker outranks an inferred owner, so one planted CNAME cannot contest
    a recorded claim.
  • decodeAccountBase36 requires a canonical 12-digit round-trip, so an ordinary label
    cannot be read as an ownership claim — without that check, web decodes to 41987 and
    prod to 1202269.

No IAM change needed: the execution role already holds
route53:ListResourceRecordSets on this zone.

It lists the whole zone rather than seeking with StartRecordName. Route53 sorts by label
from the right, so a slug's records are contiguous and seeking would be cheaper — but
getting that ordering subtly wrong would skip a record and report a claimed slug as
unclaimed, which is the one error this function must not make. DNS updates happen on
launch and teardown, so the extra calls are affordable in a way a false "unclaimed" is not.

A second fail-open, found by a gate written to assert the refusal

Owner resolution returned "unclaimed" when the record listing came back empty, which
authorizes the write. The error path already failed closed; this was the same hole one
branch over, on the success path.

A real hosted zone always carries apex SOA and NS records that cannot be deleted, so an
empty listing never means "no records under this slug" — it means the listing did not do
what was asked: wrong zone ID, pagination bug, stubbed client. It now refuses.

It was only visible because the emulator returns an empty list where real Route53 returns
NoSuchHostedZone. The fixture now seeds an apex record for the same reason — Substrate's
CreateHostedZone does not create SOA/NS, so without it every test here exercised a zone
shape that cannot exist in production.

Gates

Against the Substrate Route53 emulator, not a hand mock: what is most likely to be
wrong here is how real record names and values come back — trailing dots, TXT quoting,
octal \052 escaping for * — and a fake that returns what the code expects cannot catch
any of that.

Two are handler-level on purpose. Every unit test calls authorizeAlias directly, so
deleting the call from handler leaves all of them green — the exact shape of the original
bug. Against that revert the handler-level gate reports the attack concretely:

the handler reported writing an alias under another account's slug:
  "DNS record updated: evil.cbxv6l3i.spore.host -> 198.51.100.7
   (alias evil.mycelium-development.spore.host)"
the handler WROTE an alias under another account's slug — #820 is reopened

Eight compiling reverts, each failing the intended gate:

revert caught by
handler stops calling authorizeAlias handler-level gate (above)
authorizeAlias allows a non-owner TestOnlyTheOwningAccountMayWriteAnAliasSubdomain
owner resolution fails open on a list error TestAListErrorRefusesRatherThanAllowing
drop the empty-listing guard TestAnUnresolvableOwnerRefusesRatherThanAllowing
decodeAccountBase36 drops the 12-digit check TestDecodeAccountBase36...
TXT claim no longer outranks an inferred owner TestTheExplicitClaimOutranksAnInferredOwner
drop the IPv4 validation TestHandlerRejectsANonIPv4Address
(first pass) claim not recorded TestFirstUserClaimsAnUnownedSlugAndTheClaimPersists

The third one is worth calling out: it was not caught on the first attempt. The
emulator never produces a list error, so the error branch was uncovered until a test
re-pointed the client at a closed port. A revert to return "", nil passed everything
until then.

Live state

The zone serves two real aliases — gatetest.mycelium-development.spore.host and
tstest.mycelium-development.spore.host, both CNAMEs to *.5k0zfnmq.spore.host
(account 435415984226). So mycelium-development has an inferable owner from day one and
no migration gap: it does not need the TXT marker to be protected.

Verification

make check (all nested modules), make check-docs, changelog gate,
semgrep scan --config=auto --error . (0 findings), go mod tidy clean in
lambda/dns-updater.

Not deployed. This is a Lambda code change and needs a redeploy to take effect, like
#797. The vulnerable version is live until then.

@scttfrdmn scttfrdmn added this to the Security audit 2026-10 milestone Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

lambda/dns-updater builds the canonical record from the SigV4-verified
caller account, so a caller can only write under its own base36
subdomain — and the comment saying exactly that sits two lines above the
friendly alias (#121), which was built from req.AccountName out of the
request BODY, validated only as a DNS label. Any caller could therefore
UPSERT {record}.{any-tenant-slug}.{domain} onto its own instance, or
DELETE it.

Resolving the owner server-side was the hard part, because there was
nowhere obvious to resolve it from. The friendly name comes from
account:GetAccountInformation, which for a member account needs
org-management credentials this project must never hold. The natural
registry, the spore-portal-accounts table, is written by the portal
rather than by spawn and holds zero items, so a lookup against it would
authorize nothing and break the one tenant actually using aliases.

So ownership comes from the zone's own state, which already encodes it:
an existing alias CNAME points at {record}.{base36}.{domain}, and that
base36 label decodes back to the owning account. First use of an
unclaimed slug takes it and records a _spore-owner.{slug} TXT marker, so
ownership survives the last alias CNAME being deleted — otherwise that
deletion is exactly when a slug would quietly become available to a
squatter. The marker outranks an inferred owner, so one planted CNAME
cannot contest a recorded claim.

ip_address is now validated as an IPv4 literal (#835). It was checked
only for non-emptiness, leaving the handler to rely on Route53 rejecting
a malformed A value — validation in another service, reached only after
the request had been authorized.

The gates run against the Substrate Route53 emulator rather than a hand
mock, because what is most likely to be wrong is how real names and
values come back (trailing dots, TXT quoting, octal escaping) and a fake
that returns what the code expects cannot catch any of it. Two are
handler-level deliberately: every unit test calls authorizeAlias
directly, so deleting the call from handler leaves them all green, which
is the exact shape of the original bug.

One of them found a second fail-open while being written. Owner
resolution returned "unclaimed" when the listing came back empty, which
authorizes the write. A real hosted zone always carries apex SOA and NS
records that cannot be deleted, so an empty listing never means "no
records under this slug" — it means the listing did not do what was
asked. It now refuses. The error path already failed closed; this was
the same hole one branch over, visible only because the emulator returns
an empty list where Route53 returns NoSuchHostedZone.

Refs GHSA-q9qq-223w-mqx6
Refs #835
Closes #820
@scttfrdmn
scttfrdmn force-pushed the fix/820-dns-alias-tenancy branch from ef56b15 to e160827 Compare October 11, 2026 18:50
@scttfrdmn
scttfrdmn merged commit f894cbf into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/820-dns-alias-tenancy branch October 11, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve the DNS alias owner server-side instead of from the request body

1 participant