MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / hasUsableBaseURL

Method hasUsableBaseURL

internal/server/server.go:1125–1165  ·  view source on GitHub ↗

hasUsableBaseURL reports whether s.baseURL is a URL a verification-email recipient on the public internet can actually reach. It supersets the unreachable-host warning in SetBaseURL (BUG-899): the bind-all hosts 0.0.0.0 / :: are the right thing to bind() to but the wrong thing to email, and so is ev

()

Source from the content-addressed store, hash-verified

1123// than minting a write-locked user). Self-host and admin/invitation signup are
1124// unaffected either way.
1125func (s *Server) hasUsableBaseURL() bool {
1126 if s.baseURL == "" {
1127 return false
1128 }
1129 u, err := url.Parse(s.baseURL)
1130 if err != nil {
1131 return false
1132 }
1133 if u.Scheme != "http" && u.Scheme != "https" {
1134 return false
1135 }
1136 // The verification link is built by concatenation (baseURL +
1137 // "/verify-email/" + token), so a base URL carrying a query or fragment
1138 // would push the route into the query/fragment and break the link.
1139 if u.RawQuery != "" || u.Fragment != "" {
1140 return false
1141 }
1142 host := u.Hostname()
1143 if host == "" {
1144 return false
1145 }
1146 // A present port must be a valid TCP port (1–65535); url.Parse accepts
1147 // out-of-range numeric ports that no client can actually connect to.
1148 if p := u.Port(); p != "" {
1149 n, perr := strconv.Atoi(p)
1150 if perr != nil || n < 1 || n > 65535 {
1151 return false
1152 }
1153 }
1154
1155 // Reject literal IPs outright — a usable public verification endpoint is a
1156 // DNS hostname, and "is this IP publicly reachable" is not decidable from a
1157 // finite denylist. Fail closed on any IP.
1158 if _, aerr := netip.ParseAddr(host); aerr == nil {
1159 return false
1160 }
1161
1162 // The host must be a syntactically-valid, multi-label public FQDN (rejects
1163 // malformed hosts like ".com", "foo..com", "-a.com" and special-use TLDs).
1164 return isPublicDNSName(host)
1165}
1166
1167// isPublicDNSName reports whether host is a syntactically-valid public FQDN
1168// (RFC 1123 labels) whose TLD is neither a special-use reserved name nor

Callers 3

emailConfiguredMethod · 0.95
readCalendarFeedMethod · 0.95

Calls 1

isPublicDNSNameFunction · 0.85

Tested by

no test coverage detected