-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy_main.py
41 lines (30 loc) · 1.06 KB
/
proxy_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import copy
from flask import Flask, request, Response
import proxy_main
from util.request_pre_processor import is_invalid_key_present, is_repeat_request
import requests
import urllib
import logging
from config.config import *
app = Flask(__name__)
LAST_REQUEST = None
@app.route('/', methods=HTTP_METHODS)
@app.route('/<path:path>', methods=HTTP_METHODS)
def proxy(path):
# Check for malicous key
if is_invalid_key_present(request):
return Response("Malicious JSON", 403)
# Check for repeats
result = is_repeat_request(request, proxy_main.LAST_REQUEST)
if result:
logging.warning("Repeat request found!")
logging.warning(request)
proxy_main.LAST_REQUEST = copy.copy(request)
# Good request, send it
return requests.request(method=request.method,
url=urllib.parse.urljoin(URL_BASE, path),
headers=request.headers,
data=request.data
).content
if __name__ == '__main__':
app.run(host=HOST, port=PORT)