Skip to content

Commit

Permalink
Fix for LFI
Browse files Browse the repository at this point in the history
  • Loading branch information
sarperavci committed Aug 10, 2024
1 parent f888ccc commit ac6457e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import re
from urllib.parse import urlparse

from CloudflareBypasser import CloudflareBypasser
from DrissionPage import ChromiumPage, ChromiumOptions
Expand All @@ -19,6 +21,7 @@
"-deny-permission-prompts",
"-disable-gpu",
"-accept-lang=en-US",
"-disable-l"
]
browser_path = "/usr/bin/google-chrome"
app = FastAPI()
Expand All @@ -28,6 +31,15 @@ class CookieResponse(BaseModel):
cookies: dict


def isSafeURL(url):
parsed_url = urlparse(url)
ip_pattern = re.compile(r"^(127\.0\.0\.1|localhost|0\.0\.0\.0|::1|10\.\d+\.\d+\.\d+|172\.1[6-9]\.\d+\.\d+|172\.2[0-9]\.\d+\.\d+|172\.3[0-1]\.\d+\.\d+|192\.168\.\d+\.\d+)$")
hostname = parsed_url.hostname
if (hostname and ip_pattern.match(hostname)) or parsed_url.scheme == "file":
return False
return True


def bypass_cloudlflare(url, retries):
# Set up Chromium options
options = ChromiumOptions()
Expand All @@ -48,6 +60,8 @@ def bypass_cloudlflare(url, retries):

@app.get("/cookies", response_model=CookieResponse)
async def get_cookies(url: str, retries: int = 5):
if not isSafeURL(url):
raise HTTPException(status_code=400, detail="Invalid URL")
try:
driver = bypass_cloudlflare(url, retries)
cookies = driver.cookies(as_dict=True)
Expand All @@ -59,6 +73,8 @@ async def get_cookies(url: str, retries: int = 5):

@app.get("/html")
async def get_cookies(url: str, retries: int = 5):
if not isSafeURL(url):
raise HTTPException(status_code=400, detail="Invalid URL")
try:
driver = bypass_cloudlflare(url, retries)
html = driver.html
Expand Down

0 comments on commit ac6457e

Please sign in to comment.