Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes serialization of ProxyServer for mojo. #11028

Merged
merged 4 commits into from
Nov 13, 2021

Conversation

mkarolin
Copy link
Collaborator

Previuosly, serialization of ProxyServer's HostPortPair used
its ToString method which we overrode, but now
ProxyServerToPacResultElement explicitly constructs the string
by getting host() and port() members and calling
ConstructHostPortString. We need to override this behavior to insert
auth info.

Fixes brave/brave-browser#19371

Chromium change:

https://source.chromium.org/chromium/chromium/src/+/5dbd4599a981da1fac5dc5211772fe843a06a9b0

commit 5dbd4599a981da1fac5dc5211772fe843a06a9b0
Author: Eric Orth [email protected]
Date: Fri Sep 24 21:21:24 2021 +0000

Stop dealing with HostPortPair in proxy_string_util.(cc/h)

String->ProxyServer now done using ProxyServer::FromSchemeHostAndPort,
and ProxyServer->String now done using ProxyServer::GetHost() and
ProxyServer::GetPort(). With less ProxyServer-external dealing with
HostPortPair, will aide the future-CL transition to not storing
HostPortPair for all proxies.

Also has the effect that construction-from-string now results in
canonicalization of the ProxyServer hostname. Slight impact on tests
that were parsing stuff with now-recognized-as-invalid hostnames
(especially the v8 tracing tests that were hacking information into
wildly invalid hostnames), but don't expect any real-world impact
because these are clearly invalid names that shouldn't ever be able to
resolve to real servers.

Also moved the hostname:port parsing directly into proxy_string_util.cc
(from url_util::ParseHostAndPort()) to avoid silliness like stripping
IPv6 brackets just for them to be added back for canonicalization.

Bug: 1243398

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@mkarolin mkarolin requested review from mariospr and darkdh November 11, 2021 23:11
@mkarolin mkarolin requested a review from a team as a code owner November 11, 2021 23:11
@mkarolin mkarolin self-assigned this Nov 11, 2021
Copy link
Member

@darkdh darkdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should extend unit test ProxySpecificationUtilTest.ProxyUriToProxyServer with username and password cases and run it. So that we can detect brokerage easily in the future.
It can be done as follow-up so we don't block the release

@mkarolin
Copy link
Collaborator Author

@darkdh, added a few unit tests. PTAL. Thanks

}

std::string result =
scheme_prefix + GetProxyServerAuthString(proxy_server) + proxy_uri;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base::StrCat

}

std::string result =
scheme_prefix + GetProxyServerAuthString(proxy_server) + proxy_pac;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base::StrCat

#include "testing/gtest/include/gtest/gtest.h"

namespace net {
namespace {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests shouldn't be in anonymous namespace. They will work, but we shouldn't encourage this. One of the reasons - you cannot friend such test fixture.

@@ -72,14 +61,15 @@ std::string ProxyServerToProxyUri(const ProxyServer& proxy_server) {
}
auth_string += '@';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this can be improved with base::StrAppend.

Copy link
Contributor

@mariospr mariospr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ fixes suggested by @goodov (which mostly apply to code I originally wrote, sorry)

Previuosly, serialization of ProxyServer's HostPortPair used
its ToString method which we overrode, but now
ProxyServerToPacResultElement explicitly constructs the string
by getting host() and port() members and calling
ConstructHostPortString. We need to override this behavior to insert
auth info.

Fixes brave/brave-browser#19371

Chromium change:

https://source.chromium.org/chromium/chromium/src/+/5dbd4599a981da1fac5dc5211772fe843a06a9b0

commit 5dbd4599a981da1fac5dc5211772fe843a06a9b0
Author: Eric Orth <[email protected]>
Date:   Fri Sep 24 21:21:24 2021 +0000

    Stop dealing with HostPortPair in proxy_string_util.(cc/h)

    String->ProxyServer now done using ProxyServer::FromSchemeHostAndPort,
    and ProxyServer->String now done using ProxyServer::GetHost() and
    ProxyServer::GetPort(). With less ProxyServer-external dealing with
    HostPortPair, will aide the future-CL transition to not storing
    HostPortPair for all proxies.

    Also has the effect that construction-from-string now results in
    canonicalization of the ProxyServer hostname. Slight impact on tests
    that were parsing stuff with now-recognized-as-invalid hostnames
    (especially the v8 tracing tests that were hacking information into
    wildly invalid hostnames), but don't expect any real-world impact
    because these are clearly invalid names that shouldn't ever be able to
    resolve to real servers.

    Also moved the hostname:port parsing directly into proxy_string_util.cc
    (from url_util::ParseHostAndPort()) to avoid silliness like stripping
    IPv6 brackets just for them to be added back for canonicalization.

    Bug: 1243398
@mkarolin mkarolin force-pushed the maxk-fix-tor-reset-connection branch from c198485 to 4339800 Compare November 13, 2021 00:59
@mkarolin
Copy link
Collaborator Author

Merging as this is blocking the upcoming release. @goodov, please let me know if any additional fixes are needed and I'll do a followup. Thanks.

@mkarolin mkarolin merged commit b0a07c7 into master Nov 13, 2021
@mkarolin mkarolin deleted the maxk-fix-tor-reset-connection branch November 13, 2021 23:09
@mkarolin mkarolin added this to the 1.34.x - Nightly milestone Nov 13, 2021
mkarolin added a commit that referenced this pull request Nov 13, 2021
Fixes serialization of ProxyServer for mojo.
mkarolin added a commit that referenced this pull request Nov 13, 2021
Fixes serialization of ProxyServer for mojo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't change exit nodes/receive new IP in Tor window
4 participants