Skip to content

Potential fix for code scanning alert no. 4: URL redirection from remote source#395

Draft
Joe-Heffer-Shef wants to merge 1 commit intomainfrom
alert-autofix-4
Draft

Potential fix for code scanning alert no. 4: URL redirection from remote source#395
Joe-Heffer-Shef wants to merge 1 commit intomainfrom
alert-autofix-4

Conversation

@Joe-Heffer-Shef
Copy link
Copy Markdown
Collaborator

Potential fix for https://github.com/RSE-Sheffield/SORT/security/code-scanning/4

To fix this issue, we need to validate the value of request.META["HTTP_REFERER"] before using it as the redirect target. The best way to do this in Django is to use the built-in utility function django.utils.http.url_has_allowed_host_and_scheme, which determines whether the URL is safe for redirection (i.e., it uses an allowed host and scheme). We should replace the current usage so that if the REFERER is allowed, we redirect to it; otherwise, we should redirect to a safe default such as the survey improvement plan page (as currently coded).

Required changes:

  • Import url_has_allowed_host_and_scheme from django.utils.http, if not already imported.
  • Change the redirect logic in SurveyImprovementPlanUpdateView.post so that before redirecting to the REFERER, we check if it is allowed using the function above.
  • If the REFERER is not allowed, redirect to the default URL (as in the current fallback).

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

…ote source

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Joe-Heffer-Shef Joe-Heffer-Shef changed the base branch from dev to main February 4, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant