Skip to content

Commit

Permalink
mitm - don't proxy if marked dead
Browse files Browse the repository at this point in the history
- This is a new situation; access-filter may mark
  proxy dead inside the code proxying data.

  Safeguard dead state and not allow bytes pass.
  • Loading branch information
astibal committed Nov 2, 2023
1 parent 8f11390 commit d2bb116
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/proxy/mitmproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ void MitmProxy::proxy(baseHostCX* from, baseHostCX* to, side_t side, bool redire

void MitmProxy::on_left_bytes(baseHostCX* cx) {

if(not cx) return;
if(not cx or state().dead()) return;

if(writer_opts()->write_payload) {

Expand All @@ -1005,13 +1005,21 @@ void MitmProxy::on_left_bytes(baseHostCX* cx) {
std::for_each(
right_sockets.begin(),
right_sockets.end(),
[&](auto* to) { proxy(cx, to, side_t::LEFT, redirected); });
[&](auto* to) {
if(not state().dead()) {
proxy(cx, to, side_t::LEFT, redirected);
}
});

// because we have left bytes, let's copy them into all right side sockets!
std::for_each(
right_delayed_accepts.begin(),
right_delayed_accepts.end(),
[&](auto* to) { proxy(cx, to, side_t::LEFT, redirected); });
[&](auto* to) {
if(not state().dead()) {
proxy(cx, to, side_t::LEFT, redirected);
}
});

}

Expand Down Expand Up @@ -1041,7 +1049,7 @@ bool MitmProxy::handle_requirements(baseHostCX* cx) {

void MitmProxy::on_right_bytes(baseHostCX* cx) {

if(not cx) return;
if(not cx or state().dead()) return;

if(writer_opts()->write_payload) {

Expand Down Expand Up @@ -1081,13 +1089,21 @@ void MitmProxy::on_right_bytes(baseHostCX* cx) {
std::for_each(
left_sockets.begin(),
left_sockets.end(),
[&](auto* to) { proxy(cx, to, side_t::RIGHT, redirected); });
[&](auto* to) {
if(not state().dead()) {
proxy(cx, to, side_t::RIGHT, redirected);
}
});

// because we have left bytes, let's copy them into all right side sockets!
std::for_each(
left_delayed_accepts.begin(),
left_delayed_accepts.end(),
[&](auto* to) { proxy(cx, to, side_t::RIGHT, redirected); });
[&](auto* to) {
if(not state().dead()) {
proxy(cx, to, side_t::RIGHT, redirected);
}
});

}

Expand Down

0 comments on commit d2bb116

Please sign in to comment.