Skip to content

Commit 0ac78fb

Browse files
brianquinlanCommit Queue
authored andcommitted
[io] Fix a bug where the proxy configuration parser did not correctly validate proxy passwords.
Closes #60476 GitOrigin-RevId: c2f3b31 Change-Id: I498dcfae0b0c9614fc388f102f8d88630e0761ef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420381 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Brian Quinlan <[email protected]>
1 parent ff583f2 commit 0ac78fb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sdk/lib/_http/http_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3744,7 +3744,7 @@ class _ProxyConfiguration {
37443744
String userinfo = proxy.substring(0, at).trim();
37453745
proxy = proxy.substring(at + 1).trim();
37463746
int colon = userinfo.indexOf(":");
3747-
if (colon == -1 || colon == 0 || colon == proxy.length - 1) {
3747+
if (colon == -1 || colon == 0 || colon == userinfo.length - 1) {
37483748
throw HttpException("Invalid proxy configuration $configuration");
37493749
}
37503750
username = userinfo.substring(0, colon).trim();

tests/standalone/io/http_proxy_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,21 +296,43 @@ Future<ProxyServer> setupProxyServer({ipV6 = false}) {
296296
testInvalidProxy() {
297297
HttpClient client = new HttpClient(context: clientContext);
298298

299+
// User without password.
300+
client.findProxy = (Uri uri) => "PROXY user@localhost:80";
301+
Future<HttpClientRequest?>.value(
302+
client.getUrl(Uri.parse("http://www.google.com/test")),
303+
).catchError((error) {}, test: (e) => e is HttpException);
304+
305+
// User with empty password.
306+
client.findProxy = (Uri uri) => "PROXY user:@localhost:80";
307+
Future<HttpClientRequest?>.value(
308+
client.getUrl(Uri.parse("http://www.google.com/test")),
309+
).catchError((error) {}, test: (e) => e is HttpException);
310+
311+
// User but no username.
312+
client.findProxy = (Uri uri) => "PROXY :password@localhost:80";
313+
Future<HttpClientRequest?>.value(
314+
client.getUrl(Uri.parse("http://www.google.com/test")),
315+
).catchError((error) {}, test: (e) => e is HttpException);
316+
317+
// Empty proxy configuration.
299318
client.findProxy = (Uri uri) => "";
300319
Future<HttpClientRequest?>.value(
301320
client.getUrl(Uri.parse("http://www.google.com/test")),
302321
).catchError((error) {}, test: (e) => e is HttpException);
303322

323+
// No 'PROXY' prefix.
304324
client.findProxy = (Uri uri) => "XXX";
305325
Future<HttpClientRequest?>.value(
306326
client.getUrl(Uri.parse("http://www.google.com/test")),
307327
).catchError((error) {}, test: (e) => e is HttpException);
308328

329+
// No port.
309330
client.findProxy = (Uri uri) => "PROXY www.google.com";
310331
Future<HttpClientRequest?>.value(
311332
client.getUrl(Uri.parse("http://www.google.com/test")),
312333
).catchError((error) {}, test: (e) => e is HttpException);
313334

335+
// Port string is non an integer.
314336
client.findProxy = (Uri uri) => "PROXY www.google.com:http";
315337
Future<HttpClientRequest?>.value(
316338
client.getUrl(Uri.parse("http://www.google.com/test")),

0 commit comments

Comments
 (0)