Просмотр исходного кода

Fix: speed_test_samples sent as "" when using web API

- Further document limitations of web API protocol.

- Add workaround in psiphond to drop string-type
  speed_test_samples sent by deployed clients.
Rod Hynes 7 лет назад
Родитель
Сommit
270db830ba
4 измененных файлов с 21 добавлено и 8 удалено
  1. 5 2
      psiphon/config.go
  2. 9 0
      psiphon/server/api.go
  3. 5 1
      psiphon/server/webServer.go
  4. 2 5
      psiphon/serverApi.go

+ 5 - 2
psiphon/config.go

@@ -254,8 +254,11 @@ type Config struct {
 	// TargetApiProtocol specifies whether to force use of "ssh" or "web" API
 	// protocol. When blank, the default, the optimal API protocol is used.
 	// Note that this capability check is not applied before the
-	// "CandidateServers" count is emitted. This parameter is intended for
-	// testing and debugging only.
+	// "CandidateServers" count is emitted.
+	//
+	// This parameter is intended for testing and debugging only. Not all
+	// parameters are supported in the legacy "web" API protocol, including
+	// speed test samples.
 	TargetApiProtocol string
 
 	// RemoteServerListUrl is a URL which specifies a location to fetch out-

+ 9 - 0
psiphon/server/api.go

@@ -630,6 +630,11 @@ func validateRequestParams(
 			// No validation: the JSON already unmarshalled; the parameter
 			// user will validate that the JSON contains the expected
 			// objects/data.
+
+			// TODO: without validation, any valid JSON will be logged
+			// by getRequestLogFields, even if the parameter user validates
+			// and rejects the parameter.
+
 		default:
 			err = validateStringRequestParam(config, expectedParam, value)
 		}
@@ -772,6 +777,10 @@ func getRequestLogFields(
 			case "upstream_proxy_type":
 				// Submitted value could be e.g., "SOCKS5" or "socks5"; log lowercase
 				logFields[expectedParam.name] = strings.ToLower(strValue)
+			case tactics.SPEED_TEST_SAMPLES_PARAMETER_NAME:
+				// Due to a client bug, clients may deliever an incorrect ""
+				// value for speed_test_samples via the web API protocol. Omit
+				// the field in this case.
 			default:
 				logFields[expectedParam.name] = strValue
 			}

+ 5 - 1
psiphon/server/webServer.go

@@ -169,7 +169,11 @@ func convertHTTPRequestToAPIRequest(
 
 	for name, values := range r.URL.Query() {
 		for _, value := range values {
-			// Note: multiple values per name are ignored
+
+			// Limitations:
+			// - This is intended only to support params sent by legacy
+			//   clients; non-base array-type params are not converted.
+			// - Multiple values per name are ignored.
 
 			// TODO: faster lookup?
 			isArray := false

+ 2 - 5
psiphon/serverApi.go

@@ -879,20 +879,17 @@ func makeRequestUrl(tunnel *Tunnel, port, path string, params common.APIParamete
 			// parameter, which has a different type. This parameter is not recognized
 			// by legacy servers.
 
-			strValue := ""
 			switch v := value.(type) {
 			case string:
-				strValue = v
+				queryParams.Set(name, v)
 			case []string:
 				// String array param encoded as JSON
 				jsonValue, err := json.Marshal(v)
 				if err != nil {
 					break
 				}
-				strValue = string(jsonValue)
+				queryParams.Set(name, string(jsonValue))
 			}
-
-			queryParams.Set(name, strValue)
 		}
 
 		requestUrl.WriteString("?")