githubEdit

422.44 Invalid forwarding and redirecting

Prevent attackers from manipulating redirects and forwards to bypass access controls, deliver malicious payloads, or trick users.

422.44 Invalid Forwarding and Redirecting

Prevent attackers from manipulating redirects and forwards to bypass access controls, deliver malicious payloads, or trick users.

Overview

Invalid forwarding and redirecting occur when an application redirects or forwards a user to another page without validating the destination. Attackers can exploit this by crafting links that appear legitimate but lead users to untrusted or dangerous locations, or even gain access to restricted areas of a system.

These flaws are often overlooked because redirects and forwards are standard features in login workflows, post-submission pages, and internal navigation. When misused, they can lead to phishing, privilege escalation, and session hijacking.

Learning Targets

In this topic, students learn to:

  • Explain how unvalidated redirects and forwards create vulnerabilities

  • Identify common scenarios where redirects or forwards are used in Flask applications

  • Implement secure checks before performing any redirect or forward

  • Validate all user-supplied URLs and destinations

What is an Invalid Redirect?

Redirects send users from one URL to another. If an attacker can control the destination URL, they can trick users into visiting a fake or malicious site that looks trustworthy.

Vulnerable Flask Example

Real Attack Scenario

What is an Invalid Forward?

Forwards transfer control internally to another part of the application. If input isn't validated, attackers may access restricted files or bypass security checks.

Vulnerable Forward Example

Secure Redirect Implementation

Method 1: Whitelist Allowed URLs

Method 2: Relative URLs Only

Secure Forward Implementation

Validate Page Names

Role-Based Page Access

External Redirect with Warning

Sometimes you need to redirect to external sites. In these cases, warn the user first:

Code Interpretation Examples

Real-World Examples in Student Projects

Common Attack Patterns to Prevent

Prevention Checklist

Summary

  • Invalid redirects can send users to malicious sites that appear legitimate

  • Invalid forwards can give attackers access to restricted files or functionality

  • Whitelist validation is the most secure approach for both redirects and forwards

  • Relative URLs are safer than absolute URLs for internal navigation

  • User warnings should be shown before external redirects

  • Input validation must be applied to all user-controlled navigation parameters

By implementing proper validation and using safe defaults, you can prevent attackers from manipulating your Flask application's navigation to trick users or bypass security controls.

Last updated

Was this helpful?