Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gw): frugal DNSLink lookups on subdomains #493

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions gateway/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,32 @@
// can be loaded from a subdomain gateway with a wildcard
// TLS cert if represented as a single DNS label:
// https://my-v--long-example-com.ipns.dweb.link
if ns == "ipns" && !strings.Contains(rootID, ".") {
// if there is no TXT recordfor rootID
if !hasDNSLinkRecord(r.Context(), backend, rootID) {
// my-v--long-example-com → my.v-long.example.com
dnslinkFQDN := toDNSLinkFQDN(rootID)
if hasDNSLinkRecord(r.Context(), backend, dnslinkFQDN) {
// update path prefix to use real FQDN with DNSLink
pathPrefix = "/ipns/" + dnslinkFQDN
}
if ns == "ipns" && !strings.Contains(rootID, ".") && strings.Contains(rootID, "-") {
// If there are no '.' but '-' is present in rootID, we most
// likely have an inlined DNSLink (like my-v--long-example-com)

// We un-inline and check for DNSLink presence on domain with '.'
// first to minimize the amount of DNS lookups:
// my-v--long-example-com → my.v-long.example.com
dnslinkFQDN := toDNSLinkFQDN(rootID)

// Does _dnslink.my.v-long.example.com exist?
if hasDNSLinkRecord(r.Context(), backend, dnslinkFQDN) {
// Un-inlined DNS name has a valid DNSLink record.
// Update path prefix to use un-inlined FQDN in gateway processing.
pathPrefix = "/ipns/" + dnslinkFQDN // → /ipns/my.v-long.example.com

} else if !hasDNSLinkRecord(r.Context(), backend, rootID) {
// Inspected _dnslink.my-v--long-example-com as a
// fallback, but it had no DNSLink record either.

// At this point it is more likely the un-inlined
// dnslinkFQDN is what the end user wanted to load, so
// we switch to that. This ensures the error message
// about missing DNSLink will use the un-inlined FQDN,
// and not the inlined one.
pathPrefix = "/ipns/" + dnslinkFQDN

Check warning on line 193 in gateway/hostname.go

View check run for this annotation

Codecov / codecov/patch

gateway/hostname.go#L168-L193

Added lines #L168 - L193 were not covered by tests
}
}
}
Expand Down
Loading