[io] Fix a bug where the proxy configuration parser did not correctly validate proxy passwords.

Closes https://github.com/dart-lang/sdk/pull/60476

GitOrigin-RevId: c2f3b31db38755c7d439daa862e86c528744739c
Change-Id: I498dcfae0b0c9614fc388f102f8d88630e0761ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420381
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Brian Quinlan
2025-06-05 13:52:34 -07:00
committed by Commit Queue
parent ff583f2e2e
commit 0ac78fb92f
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -3744,7 +3744,7 @@ class _ProxyConfiguration {
String userinfo = proxy.substring(0, at).trim();
proxy = proxy.substring(at + 1).trim();
int colon = userinfo.indexOf(":");
if (colon == -1 || colon == 0 || colon == proxy.length - 1) {
if (colon == -1 || colon == 0 || colon == userinfo.length - 1) {
throw HttpException("Invalid proxy configuration $configuration");
}
username = userinfo.substring(0, colon).trim();
+22
View File
@@ -296,21 +296,43 @@ Future<ProxyServer> setupProxyServer({ipV6 = false}) {
testInvalidProxy() {
HttpClient client = new HttpClient(context: clientContext);
// User without password.
client.findProxy = (Uri uri) => "PROXY user@localhost:80";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// User with empty password.
client.findProxy = (Uri uri) => "PROXY user:@localhost:80";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// User but no username.
client.findProxy = (Uri uri) => "PROXY :password@localhost:80";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// Empty proxy configuration.
client.findProxy = (Uri uri) => "";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// No 'PROXY' prefix.
client.findProxy = (Uri uri) => "XXX";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// No port.
client.findProxy = (Uri uri) => "PROXY www.google.com";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),
).catchError((error) {}, test: (e) => e is HttpException);
// Port string is non an integer.
client.findProxy = (Uri uri) => "PROXY www.google.com:http";
Future<HttpClientRequest?>.value(
client.getUrl(Uri.parse("http://www.google.com/test")),