Browse Source

always pass user_agent for proper redis key construction

pull/43/head
Jonathan Cobb 4 years ago
parent
commit
67c3705c1a
1 changed files with 9 additions and 9 deletions
  1. +9
    -9
      bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_modify.py

+ 9
- 9
bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_modify.py View File

@@ -22,7 +22,7 @@ STANDARD_FILTER_HEADERS = {HEADER_CONTENT_TYPE: CONTENT_TYPE_BINARY}
REDIS_FILTER_PASSTHRU_PREFIX = '__chunk_filter_pass__' REDIS_FILTER_PASSTHRU_PREFIX = '__chunk_filter_pass__'
REDIS_FILTER_PASSTHRU_DURATION = 600 REDIS_FILTER_PASSTHRU_DURATION = 600


def filter_chunk(flow, chunk, req_id, last, content_encoding=None, content_type=None, user_agent=None, content_length=None, csp=None):
def filter_chunk(flow, chunk, req_id, user_agent, last, content_encoding=None, content_type=None, content_length=None, csp=None):
if debug_capture_fqdn: if debug_capture_fqdn:
host = None host = None
if flow.client_conn.tls_established: if flow.client_conn.tls_established:
@@ -49,7 +49,7 @@ def filter_chunk(flow, chunk, req_id, last, content_encoding=None, content_type=
redis_passthru_key = REDIS_FILTER_PASSTHRU_PREFIX + flow.request.method + '~~~' + user_agent + ':' + flow.request.url redis_passthru_key = REDIS_FILTER_PASSTHRU_PREFIX + flow.request.method + '~~~' + user_agent + ':' + flow.request.url
do_pass = REDIS.get(redis_passthru_key) do_pass = REDIS.get(redis_passthru_key)
if do_pass: if do_pass:
# bubble_log('filter_chunk: req_id='+req_id+': passthru found in redis, returning chunk')
bubble_log('filter_chunk: req_id='+req_id+': passthru found in redis, returning chunk')
REDIS.touch(redis_passthru_key) REDIS.touch(redis_passthru_key)
return chunk return chunk


@@ -94,7 +94,7 @@ def filter_chunk(flow, chunk, req_id, last, content_encoding=None, content_type=
return response.content return response.content




def bubble_filter_chunks(flow, chunks, req_id, content_encoding, content_type, user_agent, csp):
def bubble_filter_chunks(flow, chunks, req_id, user_agent, content_encoding, content_type, csp):
""" """
chunks is a generator that can be used to iterate over all chunks. chunks is a generator that can be used to iterate over all chunks.
""" """
@@ -111,20 +111,20 @@ def bubble_filter_chunks(flow, chunks, req_id, content_encoding, content_type, u
else: else:
last = False last = False
if first: if first:
yield filter_chunk(flow, chunk, req_id, last, content_encoding, content_type, user_agent, content_length, csp)
yield filter_chunk(flow, chunk, req_id, user_agent, last, content_encoding, content_type, content_length, csp)
first = False first = False
else: else:
yield filter_chunk(flow, chunk, req_id, last)
yield filter_chunk(flow, chunk, req_id, user_agent, last)
if not content_length: if not content_length:
yield filter_chunk(flow, None, req_id, True) # get the last bits of data
yield filter_chunk(flow, None, req_id, user_agent, True) # get the last bits of data
except Exception as e: except Exception as e:
bubble_log('bubble_filter_chunks: exception='+repr(e)) bubble_log('bubble_filter_chunks: exception='+repr(e))
traceback.print_exc() traceback.print_exc()
yield None yield None




def bubble_modify(flow, req_id, content_encoding, content_type, user_agent, csp):
return lambda chunks: bubble_filter_chunks(flow, chunks, req_id, content_encoding, content_type, user_agent, csp)
def bubble_modify(flow, req_id, user_agent, content_encoding, content_type, csp):
return lambda chunks: bubble_filter_chunks(flow, chunks, req_id, user_agent, content_encoding, content_type, csp)




def send_bubble_response(response): def send_bubble_response(response):
@@ -205,7 +205,7 @@ def responseheaders(flow):


content_length_value = flow.response.headers.pop(HEADER_CONTENT_LENGTH, None) content_length_value = flow.response.headers.pop(HEADER_CONTENT_LENGTH, None)
bubble_log(prefix+'content_encoding='+repr(content_encoding) + ', content_type='+repr(content_type)) bubble_log(prefix+'content_encoding='+repr(content_encoding) + ', content_type='+repr(content_type))
flow.response.stream = bubble_modify(flow, req_id, content_encoding, content_type, user_agent, csp)
flow.response.stream = bubble_modify(flow, req_id, user_agent, content_encoding, content_type, csp)
if content_length_value: if content_length_value:
flow.response.headers['transfer-encoding'] = 'chunked' flow.response.headers['transfer-encoding'] = 'chunked'
# find server_conn to set fake_chunks on # find server_conn to set fake_chunks on


Loading…
Cancel
Save