forked from PrivateCoffee/wikimore
fix(proxy): validate URL to prevent invalid inputs
Added a URL validation check in the proxy endpoint to ensure the URL starts with "https://upload.wikimedia.org/". This prevents potential misuse or errors caused by processing invalid URLs. Ensures only acceptable and expected URLs are processed, improving security and stability.
This commit is contained in:
parent
c436885cbc
commit
fcb6a4aa96
1 changed files with 4 additions and 0 deletions
4
app.py
4
app.py
|
@ -27,6 +27,10 @@ def get_proxy_url(url):
|
||||||
@app.route("/proxy")
|
@app.route("/proxy")
|
||||||
def proxy():
|
def proxy():
|
||||||
url = request.args.get("url")
|
url = request.args.get("url")
|
||||||
|
|
||||||
|
if not url or not url.startswith("https://upload.wikimedia.org/"):
|
||||||
|
return "Invalid URL"
|
||||||
|
|
||||||
with urllib.request.urlopen(url) as response:
|
with urllib.request.urlopen(url) as response:
|
||||||
data = response.read()
|
data = response.read()
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue