Course outline

Web Security / Intermediate: browser and data interpretation defenses / Lesson 14

Validate redirect destinations at the server boundary

Define and verify an approved navigation policy using benign synthetic destinations in an isolated web application.

About 4 min readContent reviewed
On this page

Lesson goals

  • Define an explicit redirect destination policy.
  • Compare parsed destinations with that policy.
  • Verify allowed and denied paths at the server.

Define a safe navigation policy

A web application may redirect a user after sign-in or after completing a form. If it accepts a destination from an untrusted request, the application needs an explicit policy for where navigation may go. In this synthetic lab, the policy allows a small set of local destinations and denies unapproved external destinations. Agree whether a fallback is used and how it is displayed before writing tests. This exercise is limited to an authorized isolated application and benign test addresses.

Parse before deciding

Parse a proposed destination using the applicationโ€™s supported URL handling, then compare the resulting destination with the approved policy. Treat the origin, path and any normalization consistently with the component that will issue the redirect. Simple string-prefix checks can disagree with a parsed destination; avoid designing authorization around appearances. The first table shows the intended outcomes of the lab policy rather than a complete list of URL forms. Reject malformed or unsupported inputs with a safe response.

text Synthetic navigation policy
Input | Intended decision
/account | allow local destination
external destination | deny unless explicitly approved

The table describes a bounded policy decision, not an executable request.

Keep approval close to the redirect

Perform the decision at the server boundary that produces the redirect, not only in a client-side form. If external destinations are genuinely required, use an explicitly reviewed allowlist and define ownership for changes. Do not place secrets or authentication tokens in a destination URL merely to carry state. The second table distinguishes parsing from the final redirect. Verify that the value used for navigation is the same approved value, including after any intermediate transformation.

text Synthetic navigation policy
Stage | Observation
parse | normalized destination
redirect | approved location only

The table describes a bounded policy decision, not an executable request.

Test allowed and denied cases

In an isolated lab, submit a known allowed local path, an unapproved external destination and a malformed input using a synthetic session. Check the final response location and any fallback, not just the message displayed to the user. Confirm that the rejected input is not later reused by another step in the flow. Preserve sanitized request and response evidence without credentials. A passing example for one input does not establish that all alternate representations are handled safely.

Review the complete flow

Review the entire sign-in or form-completion flow after a fix, including a permitted user journey and a denied navigation attempt. Record the policy version, parser assumptions and boundaries tested, and assign an owner for approved destination changes. Revisit the tests when the application moves behind a new proxy or changes URL handling. These observations support the selected synthetic scenarios; they do not prove every redirect endpoint or browser context enforces the same policy.

Common errors and fixes

Trusting a client-provided redirect destination

Why it happens
The requester controls the value.
How to fix it
Validate the parsed destination against the approved policy.
Prevent it next time
Keep the server decision and tests near the redirect.

Using a visual string prefix as an origin decision

Why it happens
Text comparison can differ from URL parsing.
How to fix it
Use consistent parsing and an explicit allowlist.
Prevent it next time
Test malformed and unapproved destinations in a lab.

Putting credentials in the redirect URL

Why it happens
URLs can appear in history and logs.
How to fix it
Remove the secret and follow the credential response process.
Prevent it next time
Use an appropriate protected state mechanism.

2 practice exercises

1. The lab accepts /account and receives an external destination not in its allowlist. What is expected?

Show worked solution

Deny it or use the documented safe fallback; inspect the final response location to confirm the unapproved destination was not used.

2. A client form validates a destination, but the server redirects without checking it. What is missing?

Show worked solution

The server must make the policy decision on the parsed destination, because the request can be sent without using that form.

Key takeaways

  • Treat requested destinations as untrusted input.
  • Apply and test the policy at the redirect boundary.

Official references