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

Content-type checking in proxy.py is too restrictive #70

Closed
Matthalp-zz opened this issue Dec 2, 2015 · 1 comment
Closed

Content-type checking in proxy.py is too restrictive #70

Matthalp-zz opened this issue Dec 2, 2015 · 1 comment

Comments

@Matthalp-zz
Copy link

The following code in: https://github.com/Samsung/jalangi2/blob/master/scripts/proxy.py#L43
misses several files for instrumentation:

  1. Content-Type is case insensitive (i.e can also be content-type or CoNtEnT-tYpE):
    http://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive
def response(context, flow):
    flow.response.decode()
    if 'Content-Type' in flow.response.headers:
        if flow.response.headers['Content-Type'][0].find('javascript') != -1:
            flow.response.content = processFile(flow.response.content, "js")
        if flow.response.headers['Content-Type'][0].find('html') != -1:
            flow.response.content = processFile(flow.response.content, "html")

You could try this:

def content_type(headers):
    for key in headers.keys():
        if key.lower() == "content-type":
            return headers[key].lower()
    return None

def response(context, flow):
    flow.response.decode()
    if 'javascript' in content_type(flow.response.headers):
        flow.response.content = processFile(flow.response.content, "js")
    elif 'html' in content_type(flow.response.headers):
        flow.response.content = processFile(flow.response.content, "html")
  1. You might want to looking at the extension of the path (i.e. filename: flow.request.path.split('/')[-1] or ext flow.request.path.split('.')[-1] -- with appropriate string sanitization)
@ksen007
Copy link
Contributor

ksen007 commented Feb 15, 2016

mitmproxy is kind of broken. I will be happy to merge a pull request which fixes all mitmproxy related issues.

@christofferqa christofferqa mentioned this issue Mar 1, 2016
@ksen007 ksen007 closed this as completed Mar 19, 2016
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

No branches or pull requests

2 participants