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

Method hasUsableBaseURL

internal/server/server.go:1175–1215  ·  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

1173// than minting a write-locked user). Self-host and admin/invitation signup are
1174// unaffected either way.
1175func (s *Server) hasUsableBaseURL() bool {
1176 if s.baseURL == "" {
1177 return false
1178 }
1179 u, err := url.Parse(s.baseURL)
1180 if err != nil {
1181 return false
1182 }
1183 if u.Scheme != "http" && u.Scheme != "https" {
1184 return false
1185 }
1186 // The verification link is built by concatenation (baseURL +
1187 // "/verify-email/" + token), so a base URL carrying a query or fragment
1188 // would push the route into the query/fragment and break the link.
1189 if u.RawQuery != "" || u.Fragment != "" {
1190 return false
1191 }
1192 host := u.Hostname()
1193 if host == "" {
1194 return false
1195 }
1196 // A present port must be a valid TCP port (1–65535); url.Parse accepts
1197 // out-of-range numeric ports that no client can actually connect to.
1198 if p := u.Port(); p != "" {
1199 n, perr := strconv.Atoi(p)
1200 if perr != nil || n < 1 || n > 65535 {
1201 return false
1202 }
1203 }
1204
1205 // Reject literal IPs outright — a usable public verification endpoint is a
1206 // DNS hostname, and "is this IP publicly reachable" is not decidable from a
1207 // finite denylist. Fail closed on any IP.
1208 if _, aerr := netip.ParseAddr(host); aerr == nil {
1209 return false
1210 }
1211
1212 // The host must be a syntactically-valid, multi-label public FQDN (rejects
1213 // malformed hosts like ".com", "foo..com", "-a.com" and special-use TLDs).
1214 return isPublicDNSName(host)
1215}
1216
1217// isPublicDNSName reports whether host is a syntactically-valid public FQDN
1218// (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