def send_to_perimeterx(activity_type, ctx, config, detail): try: if activity_type == 'page_requested' and not config.send_page_activities: print 'Page activities disabled in config - skipping.' return _details = { 'http_method': ctx.http_method, 'http_version': ctx.http_version, 'module_version': config.module_version, 'risk_mode': config.module_mode, } if len(detail.keys()) > 0: _details = dict(_details.items() + detail.items()) data = { 'type': activity_type, 'headers': dict(ctx.headers), 'timestamp': int(round(time.time() * 1000)), 'socket_ip': ctx.ip, 'px_app_id': config.app_id, 'url': ctx.full_url, 'details': _details, 'vid': ctx.vid, 'uuid': ctx.uuid } if activity_type == 'page_requested' or activity_type == 'block': px_utils.prepare_custom_params(config, _details) ACTIVITIES_BUFFER.append(data) except: print traceback.format_exception(*sys.exc_info()) return
def prepare_risk_body(ctx, config): logger = config.logger body = { 'request': { 'ip': ctx.ip, 'headers': format_headers(ctx.headers), 'uri': ctx.uri, 'url': ctx.full_url, 'firstParty': 'true' if config.first_party else 'false' }, 'additional': { 's2s_call_reason': ctx.s2s_call_reason, 'http_method': ctx.http_method, 'http_version': ctx.http_version, 'module_version': config.module_version, 'risk_mode': config.module_mode, 'cookie_origin': ctx.cookie_origin } } if ctx.vid: body['vid'] = ctx.vid body['additional']['enforcer_vid_source'] = ctx.enforcer_vid_source if ctx.uuid: body['uuid'] = ctx.uuid if ctx.cookie_hmac: body['additional']['px_cookie_hmac'] = ctx.cookie_hmac if ctx.cookie_names: body['additional']['request_cookie_names'] = ctx.cookie_names if ctx.pxhd: body['pxhd'] = ctx.pxhd body = add_original_token_data(ctx, body) px_utils.prepare_custom_params(config, body['additional']) if ctx.s2s_call_reason == 'cookie_decryption_failed': logger.debug('attaching orig_cookie to request') body['additional']['px_cookie_raw'] = ctx.px_cookie_raw if ctx.s2s_call_reason in ['cookie_expired', 'cookie_validation_failed']: logger.debug('attaching px_cookie to request') body['additional']['px_cookie'] = ctx.decoded_cookie return body