From f9db932a0b504ae95ce344cf4de66e2bf477a0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fukan=20=C3=9Crker?= Date: Tue, 17 Dec 2024 14:55:29 +0300 Subject: [PATCH] Fix code scanning alert no. 98: URL redirection from remote source Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- routes/editPost.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routes/editPost.py b/routes/editPost.py index 88288a1..e126154 100755 --- a/routes/editPost.py +++ b/routes/editPost.py @@ -22,10 +22,15 @@ generateurlID, # urlID generator from post title ) import re +from urllib.parse import urlparse # Create a blueprint for the edit post route editPostBlueprint = Blueprint("editPost", __name__) +VALID_URL_IDS = ["validUrlId1", "validUrlId2", "validUrlId3"] # Example list of valid urlIDs + +def is_valid_url_id(url_id): + return url_id in VALID_URL_IDS # Define a route for editing a post @editPostBlueprint.route("/editpost/", methods=["GET", "POST"]) @@ -286,7 +291,10 @@ def editPost(urlID): category="success", language=session["language"], ) # Display a flash message - return redirect(f"/post/{sessionUrlId}") + if is_valid_url_id(sessionUrlId): + return redirect(f"/post/{sessionUrlId}") + else: + return redirect('/') # Render the edit post template return render_template( "/editPost.html.jinja",