ipn/ipnlocal: move URL validation to LocalBackend

Updates tailscale/corp#7948

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-11-16 21:18:28 +05:00
committed by Maisem Ali
parent 4caca8619e
commit 513780f4f8
3 changed files with 30 additions and 29 deletions

View File

@ -999,9 +999,6 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
metricMapResponsePings.Add(1)
go c.answerPing(pr)
}
if !c.validPopBrowserURL(resp.PopBrowserURL) {
resp.PopBrowserURL = ""
}
if u := resp.PopBrowserURL; u != "" && u != sess.lastPopBrowserURL {
sess.lastPopBrowserURL = u
if c.popBrowser != nil {
@ -1705,28 +1702,6 @@ func (c *Direct) ReportHealthChange(sys health.Subsystem, sysErr error) {
res.Body.Close()
}
// validPopBrowserURL reports whether urlStr is a valid value for a
// control server to send in a MapResponse.PopUpBrowserURL field.
func (c *Direct) validPopBrowserURL(urlStr string) bool {
if urlStr == "" {
// Common case.
return true
}
u, err := url.Parse(urlStr)
if err != nil {
return false
}
switch u.Scheme {
case "https":
return true
case "http":
// If the control server is using plain HTTP (likely a dev server),
// then permit http://.
return strings.HasPrefix(c.serverURL, "http://")
}
return false
}
var (
metricMapRequestsActive = clientmetric.NewGauge("controlclient_map_requests_active")