← PHP / Laravel · Contents

PHP-017 / Beginner

Open redirect (redirect($request->input('next')))

A01:2021 Broken Access Control · CWE-601 URL Redirection to Untrusted Site

Why is this a problem?

Users can be sent to phishing pages.

How to fix it

php
$next = $request->input('next');
return redirect()->intended('/home');  // Alternatively allow only internal paths
// Check: only when parse_url($next, PHP_URL_HOST) is null and the value starts with '/'

Further reading