Repository navigation
Resolve the DNS alias owner server-side - #836
Merged
Merged
Conversation
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
force-pushed
the
fix/820-dns-alias-tenancy
branch
from
October 11, 2026 18:50
ef56b15 to
e160827
Compare
This was referenced Oct 12, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #820. Advisory: GHSA-q9qq-223w-mqx6 (draft; publishes on merge). Also fixes the
decision-free half of #835 (
ip_addressvalidation); the allowlist decision there staysopen.
The defect
lambda/dns-updaterbuilds the canonical record from the SigV4-verified caller:The comment is true of the line it describes and false of the one eight lines later.
req.AccountNamecomes 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 owninstance, or DELETE it.
aliasDNSNameis not at fault — it validates the slug correctly. The caller never checkedownership.
Why resolving it server-side was awkward
There was nowhere obvious to resolve ownership from:
account:GetAccountInformation, which for a memberaccount 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.
spore-portal-accountsDynamoDB table, is written by theportal 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 tothe owning account ID.
_spore-owner.{slug}TXTmarker. That matters: without it, deleting the last alias CNAME makes the slug look
unclaimed again, which is exactly when a squatter would take it.
a recorded claim.
decodeAccountBase36requires a canonical 12-digit round-trip, so an ordinary labelcannot be read as an ownership claim — without that check,
webdecodes to41987andprodto1202269.No IAM change needed: the execution role already holds
route53:ListResourceRecordSetson this zone.It lists the whole zone rather than seeking with
StartRecordName. Route53 sorts by labelfrom 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'sCreateHostedZonedoes not create SOA/NS, so without it every test here exercised a zoneshape 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
\052escaping for*— and a fake that returns what the code expects cannot catchany of that.
Two are handler-level on purpose. Every unit test calls
authorizeAliasdirectly, sodeleting the call from
handlerleaves all of them green — the exact shape of the originalbug. Against that revert the handler-level gate reports the attack concretely:
Eight compiling reverts, each failing the intended gate:
authorizeAliasauthorizeAliasallows a non-ownerTestOnlyTheOwningAccountMayWriteAnAliasSubdomainTestAListErrorRefusesRatherThanAllowingTestAnUnresolvableOwnerRefusesRatherThanAllowingdecodeAccountBase36drops the 12-digit checkTestDecodeAccountBase36...TestTheExplicitClaimOutranksAnInferredOwnerTestHandlerRejectsANonIPv4AddressTestFirstUserClaimsAnUnownedSlugAndTheClaimPersistsThe 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 "", nilpassed everythinguntil then.
Live state
The zone serves two real aliases —
gatetest.mycelium-development.spore.hostandtstest.mycelium-development.spore.host, both CNAMEs to*.5k0zfnmq.spore.host(account 435415984226). So
mycelium-developmenthas an inferable owner from day one andno 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 tidyclean inlambda/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.