Ver Fonte

Redact server IPs from "net" package I/O error messages

Rod Hynes há 7 anos atrás
pai
commit
7e72301aba
1 ficheiros alterados com 7 adições e 1 exclusões
  1. 7 1
      psiphon/serverApi.go

+ 7 - 1
psiphon/serverApi.go

@@ -32,6 +32,7 @@ import (
 	"net"
 	"net/http"
 	"net/url"
+	"regexp"
 	"strconv"
 	"strings"
 
@@ -590,6 +591,11 @@ func RecordRemoteServerListStat(
 		config, datastorePersistentStatTypeRemoteServerList, remoteServerListStatJson)
 }
 
+// failedTunnelErrStripIPAddressRegex strips IPv4 address strings from
+// "net" package I/O error messages. This is to avoid inadvertently recording direct server IPs via error message logs.
+var failedTunnelErrStripIPAddressRegex = regexp.MustCompile(
+	"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
+
 // RecordFailedTunnelStat records metrics for a failed tunnel dial, including
 // dial parameters and error condition (tunnelErr).
 //
@@ -612,7 +618,7 @@ func RecordFailedTunnelStat(
 	params["server_entry_ip_address"] = dialParams.ServerEntry.IpAddress
 	params["last_connected"] = lastConnected
 	params["client_failed_timestamp"] = common.TruncateTimestampToHour(common.GetCurrentTimestamp())
-	params["tunnel_error"] = tunnelErr.Error()
+	params["tunnel_error"] = failedTunnelErrStripIPAddressRegex.ReplaceAllString(tunnelErr.Error(), "<ip-address>")
 
 	failedTunnelStatJson, err := json.Marshal(params)
 	if err != nil {