Skip to content

Commit 2fe8639

Browse files
author
Johnny Tordgeman
authored
Merge pull request #63 from PerimeterX/dev
Version 3.0.1
2 parents 18f0a83 + 13f251f commit 2fe8639

File tree

9 files changed

+44
-18
lines changed

9 files changed

+44
-18
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# Change Log
2+
3+
## [v3.0.1](https://github.com/PerimeterX/perimeterx-python-wsgi) (2019-02-04)
4+
- Monitor mode bug fix
5+
- Better error handling
6+
7+
## [v3.0.0](https://github.com/PerimeterX/perimeterx-python-wsgi) (2019-01-28)
8+
- Added GAE support
9+
- Added PXHD support
10+
- Updated VID source handling
11+
212
## [v2.3.2](https://github.com/PerimeterX/perimeterx-python-wsgi) (2019-01-13)
313
- Changed requirements setting
414

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
[PerimeterX](http://www.perimeterx.com) Python Middleware
66
=============================================================
7-
> Latest stable version: [v3.0.0](https://pypi.org/project/perimeterx-python-wsgi/)
7+
> Latest stable version: [v3.0.1](https://pypi.org/project/perimeterx-python-wsgi/)
88
9-
> Latest GAE stable version: [v3.0.0](https://pypi.org/project/perimeterx-python-wsgi-gae/)
9+
> Latest GAE stable version: [v3.0.1](https://pypi.org/project/perimeterx-python-wsgi-gae/)
1010
1111
Table of Contents
1212
-----------------

perimeterx/middleware.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def __init__(self, app, config=None):
3636

3737
def __call__(self, environ, start_response):
3838
px_activities_client.send_activities_in_thread()
39+
context = None
3940
try:
4041
start = time.time()
41-
context = None
4242

4343
if environ.get('px_disable_request'):
4444
return self.app(environ, start_response)
@@ -76,9 +76,8 @@ def verify(self, request):
7676
if ctx:
7777
self.report_pass_traffic(ctx)
7878
else:
79-
self.report_pass_traffic(PxContext({}, config))
80-
return True
81-
79+
self.report_pass_traffic(PxContext(Request({}), config))
80+
return ctx, True
8281

8382
def report_pass_traffic(self, ctx):
8483
px_activities_client.send_page_requested_activity(ctx, self.config)
@@ -90,12 +89,12 @@ def report_block_traffic(self, ctx):
9089
def config(self):
9190
return self._config
9291

92+
9393
def create_custom_pxhd_callback(context, start_response):
9494
def custom_start_response(status, headers, exc_info=None):
9595
if not context.pxhd or (context.response_pxhd and context.pxhd != context.response_pxhd):
9696
expiry = px_utils.getExpiryDate()
97-
headers.append(('Set-Cookie', "_pxhd={}; path=/; expires={}; ".format(context.response_pxhd, expiry )))
97+
headers.append(('Set-Cookie', "_pxhd={}; path=/; expires={}; ".format(context.response_pxhd, expiry)))
9898
return start_response(status, headers, exc_info)
99-
return custom_start_response
100-
10199

100+
return custom_start_response

perimeterx/px_config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def __init__(self, config_dict):
1919
self._collector_host = 'collector.perimeterx.net' if app_id is None else px_constants.COLLECTOR_URL.format(
2020
app_id.lower())
2121
self._encryption_enabled = config_dict.get('encryption_enabled', True)
22-
self._sensitive_headers = map(lambda header: header.lower(), config_dict.get('sensitive_headers', ['cookie', 'cookies']))
22+
self._sensitive_headers = map(lambda header: header.lower(),
23+
config_dict.get('sensitive_headers', ['cookie', 'cookies']))
2324
self._send_page_activities = config_dict.get('send_page_activities', True)
2425
self._api_timeout_ms = config_dict.get('api_timeout', 1000)
2526
self._custom_logo = custom_logo
@@ -35,8 +36,17 @@ def __init__(self, config_dict):
3536
self._ip_headers = config_dict.get('ip_headers', [])
3637
self._proxy_url = config_dict.get('proxy_url', None)
3738
self._max_buffer_len = config_dict.get('max_buffer_len', 30)
38-
self._sensitive_routes = config_dict.get('sensitive_routes', [])
39-
self._whitelist_routes = config_dict.get('whitelist_routes', [])
39+
40+
sensitive_routes = config_dict.get('sensitive_routes', [])
41+
if not isinstance(sensitive_routes, list):
42+
raise TypeError('sensitive_routes must be a list')
43+
self._sensitive_routes = sensitive_routes
44+
45+
whitelist_routes = config_dict.get('whitelist_routes', [])
46+
if not isinstance(whitelist_routes, list):
47+
raise TypeError('whitelist_routes must be a list')
48+
49+
self._whitelist_routes = whitelist_routes
4050
self._block_html = 'BLOCK'
4151
self._logo_visibility = 'visible' if custom_logo is not None else 'hidden'
4252
self._telemetry_config = self.__create_telemetry_config()

perimeterx/px_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
EMPTY_GIF_B64 = 'R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
3131
COLLECTOR_HOST = 'collector.perimeterx.net'
3232
FIRST_PARTY_FORWARDED_FOR = 'X-FORWARDED-FOR'
33-
MODULE_VERSION = 'Python WSGI Module v3.0.0'
33+
MODULE_VERSION = 'Python WSGI Module v3.0.1'
3434
API_RISK = '/api/v3/risk'
3535
PAGE_REQUESTED_ACTIVITY = 'page_requested'
3636
BLOCK_ACTIVITY = 'block'

perimeterx/px_data_enrichment_cookie.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def __init__(self, config):
1313
self._decoded_cookie = ''
1414

1515
def from_raw_cookie(self, raw_cookie):
16+
if not raw_cookie:
17+
return
18+
1619
spliced_cookie = raw_cookie.split(':')
1720
if len(spliced_cookie) != 2:
1821
return

perimeterx/px_request_verifier.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def handle_verification(self, ctx, request):
5353
config.additional_activity_handler(ctx, config)
5454
if config.module_mode == px_constants.MODULE_MODE_BLOCKING:
5555
data, headers, status = self.px_blocker.handle_blocking(ctx=ctx, config=config)
56-
response_function = generate_blocking_response(data, headers, status)
56+
response_function = generate_blocking_response(data, headers, status)
57+
else:
58+
pass_request = True
5759

5860
if config.custom_request_handler:
5961
data, headers, status = config.custom_request_handler(ctx, self.config, request)
@@ -78,6 +80,8 @@ def px_blocker(self):
7880

7981
def generate_blocking_response(data, headers, status):
8082
result = Response(data)
81-
result.headers = headers
82-
result.status = status
83+
if headers is not None:
84+
result.headers = headers
85+
if status is not None:
86+
result.status = status
8387
return result

setup-gae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import setup, find_packages
44

5-
version = 'v3.0.0'
5+
version = 'v3.0.1'
66
setup(name='perimeterx-python-wsgi-gae',
77
version=version,
88
license='MIT',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import setup, find_packages
44

5-
version = 'v3.0.0'
5+
version = 'v3.0.1'
66
setup(name='perimeterx-python-wsgi',
77
version=version,
88
license='MIT',

0 commit comments

Comments
 (0)