-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSky
More file actions
48 lines (40 loc) · 1.41 KB
/
Sky
File metadata and controls
48 lines (40 loc) · 1.41 KB
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
42
43
44
45
46
47
48
from flask import Flask, request, Response
import requests
from urllib.parse import urlparse
app = Flask(__sky__)
# Optional: Domains to block for safety
BLOCKED_DOMAINS = [
"examplebad.com",
"malicious-site.org"
]
# Sanitize and validate URLs
def is_safe_url(url):
parsed = urlparse(url)
if parsed.scheme != 'https':
return False
if any(bad in parsed.netloc for bad in BLOCKED_DOMAINS):
return False
return True
@app.route('/proxy')
def proxy():
url = request.args.get('url')
if not url or not is_safe_url(url):
return "Blocked or Invalid URL", 400
try:
headers = {
'User-Agent': 'Mozilla/5.0 (ProxySafeBot)',
'Accept': '*/*',
}
# Make the request
resp = requests.get(url, headers=headers, timeout=10)
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
response_headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]
return Response(resp.content, resp.status_code, response_headers)
except Exception as e:
return f"Proxy Error: {str(e)}", 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=443, ssl_context='adhoc') # Run HTTPS server with self-signed cert
import os
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port)