Skip to content

Commit 4163746

Browse files
committed
chore: Initial commit
0 parents  commit 4163746

File tree

5 files changed

+586
-0
lines changed

5 files changed

+586
-0
lines changed

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

API.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# WebSocket API
2+
3+
This is the WebSocket API specification.
4+
5+
# Message format
6+
7+
Bidirectional messages are implemented in the form of JSON objects. Each API request sent from this addon has a
8+
transaction ID in the `id` field, which should be duplicated in the API response from the client.
9+
10+
_This `id` field isn't mentioned in any object documentation - remember to include it in the responses, or else the
11+
addon won't know what to do with them._
12+
13+
# Multiple clients
14+
This addon supports chaining multiple clients. Requests and responses will be sent through each client in the order of connection,
15+
such that the modifications done by one client become the input of the next.
16+
17+
# Flow stages
18+
19+
The WebSocket API sends an API request object at four stages in every HTTP flow. At each stage, the client is expected
20+
to send a certain API response object back.
21+
22+
Failure to respond to an API request will leave the flow hanging indefinitely.
23+
24+
The following is a brief overview of the interception flow.
25+
> `>` indicates a message sent from the addon to the
26+
> client
27+
`<` indicates a message sent from the client to the addon
28+
29+
`>` Pre-request stage (summarised request and existing fake response messages)
30+
`<` Pre-request settings (which complete messages to send to the client)
31+
`>` Request stage (the complete request and existing fake response messages)
32+
`<` Request overwrites (request and response modifications)
33+
34+
`>` Pre-response stage (summarised request and response messages)
35+
`<` Pre-response settings (which complete messages to send to the client)
36+
`>` Response stage (the complete request and response messages)
37+
`<` Response overwrites (request and response modifications)
38+
39+
The next few sections describe each stage in detail.
40+
41+
## Pre-request stage
42+
43+
At the `pre_request` stage, message set settings are requested from the client. These settings determine which HTTP
44+
messages are sent to the client at the request stage.
45+
46+
This allows for the client to prevent being sent messages that it doesn't need, which can minimize resource usage.
47+
48+
If the sending of both the request and the response messages is disabled, the request stage will be skipped.
49+
50+
### API request object
51+
52+
| Key | Type | Optional? |
53+
|--------------------|---------------------------|--------------------------------------------|
54+
| `request_summary` | A request summary object | No |
55+
| `response_summary` | A response summary object | Yes (provided if set by an earlier client) |
56+
57+
### API response object
58+
59+
The client should respond to this API request with a message set settings object.
60+
61+
## Request stage
62+
63+
At the request stage, the complete request (and any response set by earlier clients) can be sent to the client. At this
64+
point, the client can replace both the request and response data.
65+
66+
If response data is provided by the client, the request will never be sent.
67+
68+
### API request object
69+
70+
The addon will send a message set object to the client.
71+
72+
### API response object
73+
74+
The client must respond to this API request with another message set object.
75+
Any messages in the new message set will overwrite the corresponding messages in the original message set if provided.
76+
77+
## Pre-response stage
78+
79+
This stage serves a similar purpose to the pre-request stage, but it occurs after a request has been sent and a response
80+
has been received.
81+
82+
As with the pre-request stage, if the sending of both the request and the response messages is disabled, the response
83+
stage will be skipped.
84+
85+
### API request object
86+
87+
| Key | Type | Optional? |
88+
|--------------------|---------------------------|-----------|
89+
| `request_summary` | A request summary object | No |
90+
| `response_summary` | A response summary object | No |
91+
92+
### API response object
93+
94+
The client must respond to this API request with a message set settings object.
95+
96+
## Response stage
97+
98+
This stage works in the same way as the request stage.
99+
100+
### API request object
101+
102+
The addon will send a message set object to the client.
103+
104+
### API response object
105+
106+
The client must respond to this API request with another message set object.
107+
Any messages in the new message set will overwrite the corresponding messages in the original message set if provided.
108+
109+
Setting request data at this stage will affect the mitmproxy UI and later clients.
110+
111+
# JSON objects
112+
113+
## Message set settings
114+
115+
| Key | Value | Type | Optional? |
116+
|-----------------|----------------------------------------------------------|---------|--------------------------|
117+
| `send_request` | `true` if the full request should be sent to the client | Boolean | Yes (default is `false`) |
118+
| `send_response` | `true` if the full response should be sent to the client | Boolean | Yes (default is `false`) |
119+
120+
## Message set
121+
122+
| Key | Type | Optional? |
123+
|------------|-------------------|-------------------------------------------------------------------------------------------------------------|
124+
| `request` | A request object | Yes (provided by the addon if requested in the message set settings, or by the client to set request data) |
125+
| `response` | A response object | Yes (provided by the addon if requested in the message set settings, or by the client to set response data) |
126+
127+
## Request summary
128+
129+
| Key | Value | Type | Optional? |
130+
|----------|----------------------------------------|--------------|-----------|
131+
| `method` | The HTTP method (e.g. "GET" or "POST") | String | No |
132+
| `url` | The request URL | String (URI) | No |
133+
134+
## Request
135+
136+
| Key | Value | Type | Optional? |
137+
|-----------|----------------------------------------|------------------------------|-----------|
138+
| `method` | The HTTP method (e.g. "GET" or "POST") | String | No |
139+
| `url` | The request URL | String (URI) | No |
140+
| `headers` | The request headers | Object(String: List(String)) | No |
141+
| `body` | The request body | String (base64) | No |
142+
143+
## Response summary
144+
145+
| Key | Value | Type | Optional? |
146+
|---------------|----------------------------|---------|------------------------------------------------------------|
147+
| `status_code` | The response status code | Integer | No |
148+
| `reason` | The response reason phrase | String | Yes (a default value based on the status code may be used) |
149+
150+
## Response
151+
152+
| Key | Value | Type | Optional? |
153+
|---------------|----------------------------|------------------------------|------------------------------------------------------------|
154+
| `status_code` | The response status code | Integer | No |
155+
| `reason` | The response reason phrase | String | Yes (a default value based on the status code may be used) |
156+
| `headers` | The response headers | Object(String: List(String)) | No |
157+
| `body` | The response body | String (base64) | No |

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# mitmproxy Remote Interceptions
2+
A [mitmproxy] addon that provides a WebSocket-based API for remote interceptions.
3+
4+
## Usage
5+
This addon requires [Python] 3.10 or newer.
6+
```shell
7+
# Install the addon requirements
8+
pip install -r requirements.txt
9+
10+
# Launch mitmdump (or any addon-capable mitmproxy tool) with the addon
11+
mitmdump -s src/mitmproxy_remote_interceptions.py
12+
```
13+
The addon will start a WebSocket server on port `8081` by default, but this can be customized with the `ws_port` option.
14+
```shell
15+
mitmdump -s src/mitmproxy_remote_interceptions.py --set ws_port=8000
16+
```
17+
18+
### WebSocket API
19+
WebSocket API documentation can be found in [`API.md`](API.md).
20+
21+
[mitmproxy]: https://mitmproxy.org
22+
[python]: https://www.python.org

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mitmproxy >= 8.0.0
2+
websockets ~= 10.3

0 commit comments

Comments
 (0)