MTES-MCT / acceslibre

La plateforme collaborative pour l’accessibilité
https://acceslibre.beta.gouv.fr
MIT License
18 stars 5 forks source link

Fix code scanning alert no. 57: URL redirection from remote source #1712

Closed mlvernay closed 1 week ago

mlvernay commented 1 week ago

Fixes https://github.com/MTES-MCT/acceslibre/security/code-scanning/57

To fix the problem, we need to ensure that the user-provided query parameters do not lead to an open redirect vulnerability. We can use Django's url_has_allowed_host_and_scheme function to validate the constructed URL before redirecting. This function checks that the URL is safe by ensuring it does not contain an untrusted host or scheme.

  1. Import the url_has_allowed_host_and_scheme function from django.utils.http.
  2. Validate the search_url before redirecting.
  3. If the URL is not valid, redirect to a safe default URL (e.g., the home page).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.