Skip to content

Commit 5b5c77e

Browse files
abhinavsinghpyup-botmikenyedependabot[bot]pasccom
authored
v2.3.0 (#470)
* Update mypy from 0.780 to 0.781 (#379) * Add FilterByClientIpPlugin example (#381) * Update mypy from 0.781 to 0.782 (#382) * Update twine from 3.1.1 to 3.2.0 (#384) * Update tox from 3.15.2 to 3.16.0 (#385) * Update tox from 3.16.0 to 3.16.1 (#386) * Document FilterByClientIpPlugin & ModifyChunkResponsePlugin (#387) * Refactor plugin base classes for plugin specific flags (#388) * Update to latest code signing recommendations * Move HttpProtocolHandlerPlugin into separate file * Dont add subject attributes if not provided by upstream. Also handle subprocess.TimeoutExpired raised during certificate generation. Instead of retries, we simply close the connection on timeout * Remove plugin specific flag initialization methods for now * Update coverage from 5.1 to 5.2 (#390) * Core acceptor pool doc, cleanup and standalone example (#393) * Better document acceptor module and add a TCP Echo Server example * autopep8 formating * Rename ThreadlessWork --> Work class * Make initialize, is_inactive and shutdown as optional interface methods. Also introduce Readables & Writables custom types. * Move websocket code into its own module * Add websocket client example * Cleanup websocket client * Decouple SSL wrap logic into connection classes (#394) * Move wrap functionality within respective connection classes. Also decouple websocket client handshake method * Add a TCP echo client example that works with TCP echo server example * Add SSL echo server & client example (#395) * Move wrap_socket for SSL server within utils. Also complete proxy.common.pki gen_csr and sign_csr actions. Used by Makefile sign-https-certificates. * Add SSL echo server and client example * Add examples documentation * Add core pubsub eventing example and add menubar item skeleton (#396) * Initialize menu bar items with click handler and open a popover for preferences * Add Core PubSub eventing example * Remove hardcoded request ids * Move codecov.yml to top level directory (#400) * Add cross ref for how to generate SSL certs. (#401) * Add plugin "FilterByURLRegexPlugin" (#397) * Initial draft of filter_by_url_regex.py * Add FilterByURLRegexPlugin * Fix dictionary key & add logging * Add proper logging * Add better logging * Add logging * move code to handle_client_request * development logging * development * development * development * dev * dev * dev * dev * dev * dev * dev * dev * dev * dev * dev * Fix blocked log * Add to FILTER_LIST, some tidy up * Update FILTER_LIST * dev * remove scheme from url * Add to FILTER_LIST * Add to FILTER_LIST * Update FILTER_LIST * commenting * Update FILTER_LIST * After autopep8 * Fix Anomalous backslash in string (pep8) * Address code quality checks - flake8 F401 & W605 * Address flake8 errors * Attempt to fix flake8 errors * Fix linting issues * Address flake8 W292 * Attempt to create tests * Add FilterByURLRegexPlugin * Rename test * Work on tests * Work on tests * Work on tests Co-authored-by: Abhinav Singh <[email protected]> * Update tox from 3.16.1 to 3.17.0 (#402) * Update codecov from 2.1.7 to 2.1.8 (#404) * Update tox from 3.17.0 to 3.17.1 (#403) Co-authored-by: Abhinav Singh <[email protected]> * Bump lodash from 4.17.15 to 4.17.19 in /dashboard (#405) Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](lodash/lodash@4.17.15...4.17.19) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update tox from 3.17.1 to 3.18.0 (#406) * Update coverage from 5.2 to 5.2.1 (#407) * Update tox from 3.18.0 to 3.18.1 (#408) * Fix docker build by using correct pip flags (#417) * Update tox from 3.18.1 to 3.19.0 (#416) Co-authored-by: Abhinav Singh <[email protected]> * Update autopep8 from 1.5.3 to 1.5.4 (#412) Co-authored-by: Abhinav Singh <[email protected]> * Update pytest from 5.4.3 to 6.0.1 (#410) Co-authored-by: Abhinav Singh <[email protected]> * npm upgrade (#418) * Remove test for 'HttpWebServerRouteHandler' This does not exist (as fas as I can see) and it bother the linter (Mypy), when I tell it `klass` is a `type` instance. * Pass a list plugin class objects or bytes to proxy when used in embeded mode. No automated tests for the feature yet. * Tests for Flags.load_plugins method. * Ensure plugins are loaded only once. Also changed module name for plugins passed by type. * Update wheel from 0.34.2 to 0.35.0 (#421) * Allow to use types when embeding Proxy (#420) * Remove test for 'HttpWebServerRouteHandler' This does not exist (as fas as I can see) and it bother the linter (Mypy), when I tell it `klass` is a `type` instance. * Pass a list plugin class objects or bytes to proxy when used in embeded mode. No automated tests for the feature yet. * Tests for Flags.load_plugins method. * Ensure plugins are loaded only once. Also changed module name for plugins passed by type. Co-authored-by: Abhinav Singh <[email protected]> * Documentation for plugin loading in embedded mode (#422) * Update pytest-cov from 2.10.0 to 2.10.1 (#423) * Update wheel from 0.35.0 to 0.35.1 (#424) * Update typing-extensions from 3.7.4.2 to 3.7.4.3 (#428) * Update codecov from 2.1.8 to 2.1.9 (#427) Co-authored-by: Abhinav Singh <[email protected]> * Update pylint from 2.5.3 to 2.6.0 (#426) Co-authored-by: Abhinav Singh <[email protected]> * Update paramiko from 2.7.1 to 2.7.2 (#429) * Update pytest from 6.0.1 to 6.1.0 (#436) * Update coverage from 5.2.1 to 5.3 (#433) Co-authored-by: Abhinav Singh <[email protected]> * Update tox from 3.19.0 to 3.20.0 (#430) Co-authored-by: Abhinav Singh <[email protected]> * Update flake8 from 3.8.3 to 3.8.4 (#439) * Allow plugins to add custom command line flags (#438) * Allow plugins to add custom command line flags. Addresses #301 * Reduce dependency over Flags class. This will be deprecated so that adhoc flags can be added without any additional manual configuration * Fix: Argument 1 to "mock_default_args" of "TestMain" has incompatible type "Namespace"; expected "Mock" * Reduce Flags class to just the initializer. * Store list of action dest in FlagParser * Update pytest from 6.1.0 to 6.1.1 (#440) * More examples (#444) * Refactor into BaseServerHandler and BaseEchoServerHandler classes * Add connect tunnel example * Update rope from 0.17.0 to 0.18.0 (#445) * Update tox from 3.20.0 to 3.20.1 (#446) * Update codecov from 2.1.9 to 2.1.10 (#447) * Update mypy (#449) * Fix path to devtools websocket endpoint, broken after refactoring (#450) * Relax proxy auth requirement to allow mixed case for the auth type e.g. "basic", "Basic", "BaSiC" are all allowed (#451) * Go flagless to allow custom user defined flags. (#452) * Go flagless to allow custom user defined flags. Fixes #301 * Add --cache-dir flag for cache plugin (when used with on-disk store) * Enable discovery of flags from external plugins, example those that reside outside of proxy.py package and loaded on demand. This also allows external flags to surface in --help section * Define --filtered-client-ips flag for FilterByClientIpPlugin * Separate basic auth plugin outside of core server (#453) * Separate basic auth plugin outside of core * Put basic auth plugin at top * Create codeql-analysis.yml (#454) * Create SECURITY.md (#455) * Refactor (#456) * Update pytest from 6.1.1 to 6.1.2 (#457) * npm update (#460) * Refactor base server interfaces into core modules (#461) * Ensure pending buffers are flushed before shutting down in base_server.py Handle unsupported scheme cases within connect_tunnel.py * Move base implementations within core module * Update ssl_echo_server * Update wheel from 0.35.1 to 0.36.0 (#462) * Update wheel from 0.36.0 to 0.36.1 (#463) * Update pytest from 6.1.2 to 6.2.0 (#465) * Update wheel from 0.36.1 to 0.36.2 (#466) * Update pytest from 6.2.0 to 6.2.1 (#467) * Update codecov from 2.1.10 to 2.1.11 (#469) * Add version check for README.md (#471) Co-authored-by: pyup.io bot <[email protected]> Co-authored-by: Mike <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pascal COMBES <[email protected]>
1 parent 7ccdc2a commit 5b5c77e

File tree

88 files changed

+3768
-1661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3768
-1661
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
name: "CodeQL"
7+
8+
on:
9+
push:
10+
branches: [develop, master]
11+
pull_request:
12+
# The branches below must be a subset of the branches above
13+
branches: [develop]
14+
schedule:
15+
- cron: '0 14 * * 1'
16+
17+
jobs:
18+
analyze:
19+
name: Analyze
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
# Override automatic language detection by changing the below list
26+
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
27+
language: ['python', 'javascript']
28+
# Learn more...
29+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
with:
35+
# We must fetch at least the immediate parents so that if this is
36+
# a pull request then we can checkout the head.
37+
fetch-depth: 2
38+
39+
# If this run was triggered by a pull request event, then checkout
40+
# the head of the pull request instead of the merge commit.
41+
- run: git checkout HEAD^2
42+
if: ${{ github.event_name == 'pull_request' }}
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
# - name: Autobuild
57+
# uses: github/codeql-action/autobuild@v1
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v1

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ COPY README.md /app/
77
COPY proxy/ /app/proxy/
88
WORKDIR /app
99
RUN pip install --upgrade pip && \
10-
pip install --install-option="--prefix=/deps" .
10+
pip install --prefix=/deps .
1111

1212
FROM base
1313

Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ IMAGE_TAG := $(NS)/$(IMAGE_NAME):$(VERSION)
88

99
HTTPS_KEY_FILE_PATH := https-key.pem
1010
HTTPS_CERT_FILE_PATH := https-cert.pem
11+
HTTPS_CSR_FILE_PATH := https-csr.pem
12+
HTTPS_SIGNED_CERT_FILE_PATH := https-signed-cert.pem
1113

1214
CA_KEY_FILE_PATH := ca-key.pem
1315
CA_CERT_FILE_PATH := ca-cert.pem
@@ -25,6 +27,7 @@ devtools:
2527
pushd dashboard && npm run devtools && popd
2628

2729
autopep8:
30+
autopep8 --recursive --in-place --aggressive examples
2831
autopep8 --recursive --in-place --aggressive proxy
2932
autopep8 --recursive --in-place --aggressive tests
3033
autopep8 --recursive --in-place --aggressive setup.py
@@ -40,6 +43,20 @@ https-certificates:
4043
--private-key-path $(HTTPS_KEY_FILE_PATH) \
4144
--public-key-path $(HTTPS_CERT_FILE_PATH)
4245

46+
sign-https-certificates:
47+
# Generate CSR request
48+
python -m proxy.common.pki gen_csr \
49+
--csr-path $(HTTPS_CSR_FILE_PATH) \
50+
--private-key-path $(HTTPS_KEY_FILE_PATH) \
51+
--public-key-path $(HTTPS_CERT_FILE_PATH)
52+
# Sign CSR with CA
53+
python -m proxy.common.pki sign_csr \
54+
--csr-path $(HTTPS_CSR_FILE_PATH) \
55+
--crt-path $(HTTPS_SIGNED_CERT_FILE_PATH) \
56+
--hostname example.com \
57+
--private-key-path $(CA_KEY_FILE_PATH) \
58+
--public-key-path $(CA_CERT_FILE_PATH)
59+
4360
ca-certificates:
4461
# Generate CA key
4562
python -m proxy.common.pki gen_private_key \
@@ -73,8 +90,8 @@ lib-clean:
7390
rm -rf .hypothesis
7491

7592
lib-lint:
76-
flake8 --ignore=W504 --max-line-length=127 --max-complexity=19 proxy/ tests/ setup.py
77-
mypy --strict --ignore-missing-imports proxy/ tests/ setup.py
93+
flake8 --ignore=W504 --max-line-length=127 --max-complexity=19 examples/ proxy/ tests/ setup.py
94+
mypy --strict --ignore-missing-imports examples/ proxy/ tests/ setup.py
7895

7996
lib-test: lib-clean lib-version lib-lint
8097
pytest -v tests/
@@ -93,7 +110,7 @@ lib-coverage:
93110
open htmlcov/index.html
94111

95112
lib-profile:
96-
sudo py-spy -F -f profile.svg -d 3600 proxy.py
113+
sudo py-spy record -o profile.svg -t -F -s -- python -m proxy
97114

98115
dashboard:
99116
pushd dashboard && npm run build && popd

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Table of Contents
5757
* [Cache Responses Plugin](#cacheresponsesplugin)
5858
* [Man-In-The-Middle Plugin](#maninthemiddleplugin)
5959
* [Proxy Pool Plugin](#proxypoolplugin)
60+
* [FilterByClientIpPlugin](#filterbyclientipplugin)
61+
* [ModifyChunkResponsePlugin](#modifychunkresponseplugin)
6062
* [HTTP Web Server Plugins](#http-web-server-plugins)
6163
* [Reverse Proxy](#reverse-proxy)
6264
* [Web Server Route](#web-server-route)
@@ -70,6 +72,7 @@ Table of Contents
7072
* [Embed proxy.py](#embed-proxypy)
7173
* [Blocking Mode](#blocking-mode)
7274
* [Non-blocking Mode](#non-blocking-mode)
75+
* [Loading Plugins](#loading-plugins)
7376
* [Unit testing with proxy.py](#unit-testing-with-proxypy)
7477
* [proxy.TestCase](#proxytestcase)
7578
* [Override Startup Flags](#override-startup-flags)
@@ -669,6 +672,57 @@ Make a curl request via `8899` proxy:
669672
Verify that `8899` proxy forwards requests to upstream proxies
670673
by checking respective logs.
671674
675+
### FilterByClientIpPlugin
676+
677+
Reject traffic from specific IP addresses. By default this
678+
plugin blocks traffic from `127.0.0.1` and `::1`.
679+
680+
Start `proxy.py` as:
681+
682+
```bash
683+
❯ proxy \
684+
--plugins proxy.plugin.FilterByClientIpPlugin
685+
```
686+
687+
Send a request using `curl -v -x localhost:8899 http://google.com`:
688+
689+
```bash
690+
... [redacted] ...
691+
> Proxy-Connection: Keep-Alive
692+
>
693+
< HTTP/1.1 418 I'm a tea pot
694+
< Connection: close
695+
<
696+
* Closing connection 0
697+
```
698+
699+
Modify plugin to your taste e.g. Allow specific IP addresses only.
700+
701+
### ModifyChunkResponsePlugin
702+
703+
This plugin demonstrate how to modify chunked encoded responses. In able to do so, this plugin uses `proxy.py` core to parse the chunked encoded response. Then we reconstruct the response using custom hardcoded chunks, ignoring original chunks received from upstream server.
704+
705+
Start `proxy.py` as:
706+
707+
```bash
708+
❯ proxy \
709+
--plugins proxy.plugin.ModifyChunkResponsePlugin
710+
```
711+
712+
Verify using `curl -v -x localhost:8899 http://httpbin.org/stream/5`:
713+
714+
```bash
715+
... [redacted] ...
716+
modify
717+
chunk
718+
response
719+
plugin
720+
* Connection #0 to host localhost left intact
721+
* Closing connection 0
722+
```
723+
724+
Modify `ModifyChunkResponsePlugin` to your taste. Example, instead of sending hardcoded chunks, parse and modify the original `JSON` chunks received from the upstream server.
725+
672726
## HTTP Web Server Plugins
673727
674728
### Reverse Proxy
@@ -774,6 +828,22 @@ Verify using `curl -x https://localhost:8899 --proxy-cacert https-cert.pem https
774828
}
775829
```
776830
831+
If you want to avoid passing `--proxy-cacert` flag, also consider signing generated SSL certificates. Example:
832+
833+
First, generate CA certificates:
834+
835+
```bash
836+
make ca-certificates
837+
```
838+
839+
Then, sign SSL certificate:
840+
841+
```bash
842+
make sign-https-certificates
843+
```
844+
845+
Now restart the server with `--cert-file https-signed-cert.pem` flag. Note that you must also trust generated `ca-cert.pem` in your system keychain.
846+
777847
TLS Interception
778848
=================
779849
@@ -1103,6 +1173,36 @@ Note that:
11031173
input arguments e.g. `start(['--port', '8899'])` or
11041174
by using passing flags as kwargs e.g. `start(port=8899)`.
11051175
1176+
## Loading Plugins
1177+
1178+
You can, of course, list plugins to load in the input arguments list of `proxy.main`, `proxy.start` or the `Proxy` constructor. Use the `--plugins` flag as when starting from command line:
1179+
1180+
```python
1181+
import proxy
1182+
1183+
if __name__ == '__main__':
1184+
proxy.main([
1185+
'--plugins', 'proxy.plugin.CacheResponsesPlugin',
1186+
])
1187+
```
1188+
1189+
However, for simplicity you can pass the list of plugins to load as a keyword argument to `proxy.main`, `proxy.start` or the `Proxy` constructor:
1190+
1191+
```python
1192+
import proxy
1193+
from proxy.plugin import FilterByUpstreamHostPlugin
1194+
1195+
if __name__ == '__main__':
1196+
proxy.main([], plugins=[
1197+
b'proxy.plugin.CacheResponsesPlugin',
1198+
FilterByUpstreamHostPlugin,
1199+
])
1200+
```
1201+
1202+
Note that it supports:
1203+
1. The fully-qualified name of a class as `bytes`
1204+
2. Any `type` instance for a Proxy.py plugin class. This is espacially useful for custom plugins defined locally.
1205+
11061206
Unit testing with proxy.py
11071207
==========================
11081208
@@ -1603,7 +1703,7 @@ usage: proxy [-h] [--backlog BACKLOG] [--basic-auth BASIC_AUTH]
16031703
[--static-server-dir STATIC_SERVER_DIR] [--threadless]
16041704
[--timeout TIMEOUT] [--version]
16051705
1606-
proxy.py v2.2.0
1706+
proxy.py v2.3.0
16071707
16081708
optional arguments:
16091709
-h, --help show this help message and exit

SECURITY.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- | ------------------ |
7+
| 2.x | :white_check_mark: |
8+
| < 2.x | :x: |
9+
10+
## Reporting a Vulnerability
11+
12+
Follow these steps:
13+
14+
1. Start by [emailing developers](mailto:[email protected])
15+
2. If unresponsive, [create a public issue](https://github.com/abhinavsingh/proxy.py/issues/new/choose)
16+
3. [Pull requests](https://github.com/abhinavsingh/proxy.py/pulls) are always welcome
File renamed without changes.

0 commit comments

Comments
 (0)