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

callback addon: support intercepting requests #105

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

kegsay
Copy link
Member

@kegsay kegsay commented Jul 4, 2024

This PR modifies the callback mitmproxy addon to allow it to be able to intercept outbound requests before they reach the server. This is the final piece of functionality required in order to get rid of the status_code addon which has historically been used in tests to block outbound requests.

The callback server has now been split into two URLs depending on if you want to intercept requests or responses.

Add a test to ensure blocking works correctly.

kegsay added 3 commits July 4, 2024 16:57
There is now `callback_request_url` to intercept requests and
`callback_response_url` to intercept responses. All code currently
intercepts responses only.
@kegsay kegsay changed the title WIP: support intercepting requests Support intercepting requests Jul 5, 2024
@kegsay kegsay changed the title Support intercepting requests callback addon: support intercepting requests Jul 5, 2024
@kegsay kegsay requested a review from richvdh July 5, 2024 08:29
Comment on lines +23 to +29
# The response to this request can control what gets returned to the client. The response object:
# {
# "respond_status_code": 200,
# "respond_body": { "some": "json_object" }
# }
# If {} is sent back, the response is not modified. Likewise, if `respond_body` is set but
# `respond_status_code` is not, only the response body is modified, not the status code, and vice versa.
Copy link
Member

Choose a reason for hiding this comment

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

This only applies to callback_response_url, right?

I think it might be clearer to document the request and response for the two URLs completely separately, even if there's a bit of duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Sounds good, I'm going to document this in the README where it's more easily accessible. But that will be in the next PR.

Comment on lines +50 to +51
"callback_request_url": "",
"callback_response_url": "",
Copy link
Member

Choose a reason for hiding this comment

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

given that the whole thing is a Callback, the callback_ prefix for these names seems a bit redundant? YMMV

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 prefix this on purpose because there are a lot of request/response keys flying around (the ones you register with the addon, the ones passed in as req body to the callback server, the res body from the callback server) and I've tried to use callback_ for configuring the callback server, respond_ for the response body from the callback server and no special prefix for the callback data itself.

Comment on lines +60 to +61
"callback_request_url": "",
"callback_response_url": "",
Copy link
Member

Choose a reason for hiding this comment

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

seems like the options are, well, optional (we use config.get() rather than config[]) -- so maybe just omit these?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are optional but in absence of having __init__ set all the properties, I've tried to set them all in load, so readers can see what properties the addon uses. They aren't strictly required though as you say.

tests/mitmproxy_addons/callback.py Outdated Show resolved Hide resolved
@kegsay kegsay merged commit 454b0c4 into main Jul 5, 2024
4 checks passed
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.

2 participants