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

Merge pull request #291 from adam-p/master

Fix URL proxy double-escaping
Adam Pritchard 9 лет назад
Родитель
Сommit
b08041f83a
2 измененных файлов с 10 добавлено и 5 удалено
  1. 3 0
      MobileLibrary/iOS/BUILD.md
  2. 7 5
      psiphon/httpProxy.go

+ 3 - 0
MobileLibrary/iOS/BUILD.md

@@ -22,6 +22,9 @@
 
 
 * The result will be in `MobileLibrary/iOS/build`.
 * The result will be in `MobileLibrary/iOS/build`.
 
 
+#### Testing
+
+Run `test-psiphon-framework.sh`.
 
 
 ## Automatic Build -- Jenkins
 ## Automatic Build -- Jenkins
 
 

+ 7 - 5
psiphon/httpProxy.go

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2015, Psiphon Inc.
+ * Copyright (c) 2016, Psiphon Inc.
  * All rights reserved.
  * All rights reserved.
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -45,12 +45,14 @@ import (
 // Android Media Player (http://developer.android.com/reference/android/media/MediaPlayer.html).
 // Android Media Player (http://developer.android.com/reference/android/media/MediaPlayer.html).
 // To make the Media Player use the Psiphon tunnel, construct a URL such as:
 // To make the Media Player use the Psiphon tunnel, construct a URL such as:
 // "http://127.0.0.1:<proxy-port>/tunneled/<origin media URL>"; and pass this to the player.
 // "http://127.0.0.1:<proxy-port>/tunneled/<origin media URL>"; and pass this to the player.
+// The <origin media URL> must be escaped in such a way that it can be used inside a URL query.
 // TODO: add ICY protocol to support certain streaming media (e.g., https://gist.github.com/tulskiy/1008126)
 // TODO: add ICY protocol to support certain streaming media (e.g., https://gist.github.com/tulskiy/1008126)
 //
 //
 // An example use case for direct, untunneled, relaying is to make use of Go's TLS
 // An example use case for direct, untunneled, relaying is to make use of Go's TLS
 // stack for HTTPS requests in cases where the native TLS stack is lacking (e.g.,
 // stack for HTTPS requests in cases where the native TLS stack is lacking (e.g.,
 // WinHTTP on Windows XP). The URL for direct relaying is:
 // WinHTTP on Windows XP). The URL for direct relaying is:
 // "http://127.0.0.1:<proxy-port>/direct/<origin URL>".
 // "http://127.0.0.1:<proxy-port>/direct/<origin URL>".
+// Again, the <origin URL> must be escaped in such a way that it can be used inside a URL query.
 //
 //
 // Origin URLs must include the scheme prefix ("http://" or "https://") and must be
 // Origin URLs must include the scheme prefix ("http://" or "https://") and must be
 // URL encoded.
 // URL encoded.
@@ -255,11 +257,11 @@ func (proxy *HttpProxy) urlProxyHandler(responseWriter http.ResponseWriter, requ
 	// Request URL should be "/tunneled/<origin URL>" or  "/direct/<origin URL>" and the
 	// Request URL should be "/tunneled/<origin URL>" or  "/direct/<origin URL>" and the
 	// origin URL must be URL encoded.
 	// origin URL must be URL encoded.
 	switch {
 	switch {
-	case strings.HasPrefix(request.URL.Path, URL_PROXY_TUNNELED_REQUEST_PATH):
-		originUrl, err = url.QueryUnescape(request.URL.Path[len(URL_PROXY_TUNNELED_REQUEST_PATH):])
+	case strings.HasPrefix(request.URL.RawPath, URL_PROXY_TUNNELED_REQUEST_PATH):
+		originUrl, err = url.QueryUnescape(request.URL.RawPath[len(URL_PROXY_TUNNELED_REQUEST_PATH):])
 		client = proxy.urlProxyTunneledClient
 		client = proxy.urlProxyTunneledClient
-	case strings.HasPrefix(request.URL.Path, URL_PROXY_DIRECT_REQUEST_PATH):
-		originUrl, err = url.QueryUnescape(request.URL.Path[len(URL_PROXY_DIRECT_REQUEST_PATH):])
+	case strings.HasPrefix(request.URL.RawPath, URL_PROXY_DIRECT_REQUEST_PATH):
+		originUrl, err = url.QueryUnescape(request.URL.RawPath[len(URL_PROXY_DIRECT_REQUEST_PATH):])
 		client = proxy.urlProxyDirectClient
 		client = proxy.urlProxyDirectClient
 	default:
 	default:
 		err = errors.New("missing origin URL")
 		err = errors.New("missing origin URL")