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

Add WebSockets connection pool limit when shields are enabled. #11609

Merged
merged 7 commits into from
Jan 6, 2022

Conversation

goodov
Copy link
Member

@goodov goodov commented Dec 15, 2021

Resolves brave/brave-browser#19990

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
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • 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:

@goodov goodov requested review from a team as code owners December 15, 2021 14:32
@goodov goodov self-assigned this Dec 15, 2021
@github-actions github-actions bot added the CI/run-network-audit Run network-audit label Dec 15, 2021
@goodov goodov force-pushed the issues/19990 branch 2 times, most recently from e75a1a3 to a5cddac Compare December 16, 2021 05:30
@iefremov
Copy link
Contributor

Most probably we don't need a formal sec review, but I'd double-check with someone from the sec team. Maybe @fmarier you could take a quick look?

@@ -40,5 +40,9 @@ const base::Feature kFileSystemAccessAPI{"FileSystemAccessAPI",
const base::Feature kPartitionBlinkMemoryCache{
"PartitionBlinkMemoryCache", base::FEATURE_DISABLED_BY_DEFAULT};

// Enable WebSockets connection pool limit per eTLD+1 for each renderer.
const base::Feature kRestrictWebSocketsPool{"RestrictWebSocketsPool",
base::FEATURE_DISABLED_BY_DEFAULT};
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we can enable by default, the change doesn't look very dangerous?

Copy link
Member Author

Choose a reason for hiding this comment

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

👌 I'll make it enabled by default and will add a brave://flag to be safe.

@@ -0,0 +1,60 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

is almost 2022! (in all files)

@iefremov
Copy link
Contributor

perhaps a browser test?

@goodov
Copy link
Member Author

goodov commented Dec 17, 2021

perhaps a browser test?

of course. currently working on it.

@goodov goodov force-pushed the issues/19990 branch 2 times, most recently from 00a5a0f to 849b8d1 Compare December 17, 2021 16:20
Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

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

Most probably we don't need a formal sec review, but I'd double-check with someone from the sec team.

The high-level approach sounds good to me. It's not adding (or really modifying) any new networks requests, so I don't think we need to do a full sec review.

I assume @pes10k has confirmed that this mitigation is effective against the pool party attack?

@pes10k
Copy link
Contributor

pes10k commented Dec 17, 2021

Yep! Limiting each eTLD+1 to a maximum of 10 websockets would effectively defeat the attack (an attacker could hypothetically still carry out the attack by controlling ~20 domains at the same time, and coordinating between them, but this approach makes the attack sufficiently difficult to carry out that I think we can consider it solved (at least when carried out through the WebSocket pool, which is the most concerning example).

Just to confirm @goodov, this PR does

Partition: impose a per-site (as determined by top-level frame eTLD+1) cap of how many websockets can be open. Initial suggestion is 10, but any cap thats << the global cap would work

but not

De-limit: remove, or greatly expand, the global cap, to increase the number of eTLD+1s an attack has to control to carry out the attack

Is that correct?

@goodov
Copy link
Member Author

goodov commented Dec 20, 2021

Just to confirm @goodov, this PR does

Partition: impose a per-site (as determined by top-level frame eTLD+1) cap of how many websockets can be open. Initial suggestion is 10, but any cap thats << the global cap would work

but not

De-limit: remove, or greatly expand, the global cap, to increase the number of eTLD+1s an attack has to control to carry out the attack

Is that correct?

yes, that is correct!

if (auto* top_frame_security_context =
frame->Top()->GetSecurityContext()) {
return top_frame_security_context->GetSecurityOrigin()
->GetOriginOrPrecursorOriginIfOpaque();
Copy link
Member Author

Choose a reason for hiding this comment

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

see SandboxedFramesAreLimited test.

@goodov goodov force-pushed the issues/19990 branch 3 times, most recently from 56dc1ab to 68176d5 Compare December 27, 2021 09:17
@goodov
Copy link
Member Author

goodov commented Dec 30, 2021

@bridiver chromium_src, patches review ping, other reviewers are currently on PTO.

@iefremov
Copy link
Contributor

iefremov commented Jan 5, 2022

@mkarolin @bridiver PTAL, thanks!


namespace blink {

class MODULES_EXPORT WebSocketChannelImpl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we restore finality here?

const String& resource_id_in_use() const { return resource_id_in_use_; }

private:
String resource_id_in_use_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: seems like this and the getter could just be called resource_id_/resource_id()?


MutexLocker locker(resources_in_use_lock_);
// `insert` doesn't change the value if it already exists.
int& resource_in_use_value =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: resource_in_use_count might be a bit more clear.

int GetResourceLimit(ResourceType resource_type) {
switch (resource_type) {
case ResourceType::kWebSocket:
return 10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be hard-coded? Would it make sense to make it a feature param, for example, and control it via Griffin?

@iefremov
Copy link
Contributor

iefremov commented Jan 5, 2022

@mkarolin turned out we want to merge it asap, would you mind approving it and then we can do a follow-up?

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

++ with a couple of nits and questions that can be address in a followup.

@mkarolin
Copy link
Collaborator

mkarolin commented Jan 5, 2022

@mkarolin turned out we want to merge it asap, would you mind approving it and then we can do a follow-up?

No problem.

@iefremov iefremov merged commit b217cd4 into master Jan 6, 2022
@iefremov iefremov deleted the issues/19990 branch January 6, 2022 05:17
bbondy added a commit that referenced this pull request Jan 6, 2022
This reverts commit b217cd4, reversing
changes made to 8f34773.
@goodov goodov added this to the 1.36.x - Nightly milestone Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-network-audit Run network-audit
Projects
None yet
5 participants