Skip to content

Commit

Permalink
In-proxy broker GeoIP fixes
Browse files Browse the repository at this point in the history
- Always log client GeoIP, even when request validation fails
- Log unexpected ICE candidate GeoIP information
  • Loading branch information
rod-hynes committed Jun 28, 2024
1 parent ffbed1c commit 6b60b62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
8 changes: 4 additions & 4 deletions psiphon/common/inproxy/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (b *Broker) handleProxyAnnounce(
// Always log the outcome.
defer func() {
if logFields == nil {
logFields = make(common.LogFields)
logFields = b.config.APIParameterLogFieldFormatter(geoIPData, nil)
}
logFields["broker_event"] = "proxy-announce"
logFields["proxy_id"] = proxyID
Expand Down Expand Up @@ -717,7 +717,7 @@ func (b *Broker) handleClientOffer(
// Always log the outcome.
defer func() {
if logFields == nil {
logFields = make(common.LogFields)
logFields = b.config.APIParameterLogFieldFormatter(geoIPData, nil)
}
logFields["broker_event"] = "client-offer"
if serverParams != nil {
Expand Down Expand Up @@ -976,7 +976,7 @@ func (b *Broker) handleProxyAnswer(
// Always log the outcome.
defer func() {
if logFields == nil {
logFields = make(common.LogFields)
logFields = b.config.APIParameterLogFieldFormatter(geoIPData, nil)
}
logFields["broker_event"] = "proxy-answer"
logFields["proxy_id"] = proxyID
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func (b *Broker) handleClientRelayedPacket(
// Always log the outcome.
defer func() {
if logFields == nil {
logFields = make(common.LogFields)
logFields = b.config.APIParameterLogFieldFormatter(geoIPData, nil)
}
logFields["broker_event"] = "client-relayed-packet"
logFields["elapsed_time"] = time.Since(startTime) / time.Millisecond
Expand Down
23 changes: 17 additions & 6 deletions psiphon/common/inproxy/webrtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,10 +1689,12 @@ func processSDPAddresses(
return nil, nil, errors.TraceNew("unexpected non-IP")
}

candidateIsIPv6 := false
if candidateIP.To4() == nil {
if disableIPv6Candidates {
continue
}
candidateIsIPv6 = true
hasIPv6 = true
}

Expand All @@ -1715,18 +1717,27 @@ func processSDPAddresses(
// The broker will check that clients and proxies specify only
// candidates that map to the same GeoIP country and ASN as
// the client/proxy connection to the broker. This limits
// misuse of candidate to connect to other locations.
// misuse of candidates to connect to other locations.
// Legitimate candidates will not all have the exact same IP
// address, as there could be a mix of IPv4 and IPv6, as well
// as potentially different NAT paths.

if lookupGeoIP != nil {
candidateGeoIPData := lookupGeoIP(candidate.Address())
if candidateGeoIPData.Country != expectedGeoIPData.Country {
return nil, nil, errors.TraceNew("unexpected GeoIP country")
}
if candidateGeoIPData.ASN != expectedGeoIPData.ASN {
return nil, nil, errors.TraceNew("unexpected GeoIP ASN")

if candidateGeoIPData.Country != expectedGeoIPData.Country ||
candidateGeoIPData.ASN != expectedGeoIPData.ASN {

version := "IPv4"
if candidateIsIPv6 {
version = "IPv6"
}
errStr := fmt.Sprintf(
"unexpected GeoIP for %s candidate: %s, %s",
version,
candidateGeoIPData.Country,
candidateGeoIPData.ASN)
return nil, nil, errors.TraceNew(errStr)
}
}

Expand Down

0 comments on commit 6b60b62

Please sign in to comment.