Skip to content

Potential fix for code scanning alert no. 5: Server-side request forgery - #84

Draft
aryan4859 wants to merge 1 commit into
mainv2from
alert-autofix-5
Draft

Potential fix for code scanning alert no. 5: Server-side request forgery#84
aryan4859 wants to merge 1 commit into
mainv2from
alert-autofix-5

Conversation

@aryan4859

Copy link
Copy Markdown
Member

Potential fix for https://github.com/FlagForgeCTF/flagForge/security/code-scanning/5

General fix: keep user-controlled URL usage constrained by strict allowlisting not only for the initial URL, but also for any redirect target. The safest minimal approach is to disable automatic redirect following and manually process redirects with re-validation on each hop.

Best fix here (without changing intended functionality of “following redirects”): in app/api/instagram/image/route.ts, replace the single fetch(..., { redirect: "follow" }) with a small helper that:

  • uses redirect: "manual",
  • validates protocol/host for each URL before requesting,
  • if response is redirect (3xx + Location), resolves next URL relative to current URL, re-validates it, and continues up to a bounded redirect count,
  • returns the final non-redirect response.

Needed changes:

  • Add a helper function (e.g., fetchWithValidatedRedirects) above GET.
  • Update line 34 call site to use this helper.
  • No new imports/dependencies required.

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

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
throw new Error("Invalid redirect host");
}

const response = await fetch(currentUrl.toString(), { redirect: "manual" });
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.

2 participants