Skip to content

A free open source IT asset/license management system

Fixed GHSA-579m-9gf4-28jp - strip \ from redirect urls

snipe8e49ba0a99e7
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php
index 373b1479a8..6329e70e42 100644
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@ -1795,7 +1795,12 @@ class Helper
$url = str_replace(["\r", "\n"], '', $url);
- $parts = parse_url($url);
+ // Normalize backslashes to forward slashes before parsing, so that a malicious input like
+ // https:\\evil.com\@example.com\@evil.com\@example.com
+ // doesn't get parsed as a same-origin URL.
+ $normalized = str_replace('\\', '/', $url);
+
+ $parts = parse_url($normalized);
if ($parts === false) {
return null;
}
@@ -1804,6 +1809,14 @@ class Helper
return null;
}
+ // Same-origin redirects never legitimately carry credentials.
+ // Reject any input where parse_url extracted a userinfo component,
+ // closing further parser-differential variants that hide the real
+ // authority behind an `@`.
+ if (isset($parts['user']) || isset($parts['pass'])) {
+ return null;
+ }
+
$host = $parts['host'] ?? null;
$appHost = parse_url(config('app.url'), PHP_URL_HOST);
@@ -1814,6 +1827,30 @@ class Helper
return $url;
}
+ /**
+ * Emission-side replacement for Laravel's redirect()->intended().
+ *
+ * Laravel's redirect()->intended() pulls session('url.intended') and
+ * hands it straight to redirect()->to() with no host validation. The
+ * write-side sanitize we perform in SamlController::acs and similar
+ * places is defense-in-depth, but any writer that skips it (or any
+ * parser-differential bypass of Helper::sameOriginUrl at write time)
+ * leaves an open-redirect surface. This helper reads url.intended,
+ * runs it through sameOriginUrl at emission, and falls back to the
+ * caller-supplied default whenever the stored value is missing or
+ * fails the guard. Every controller that previously called
+ * redirect()->intended(...) directly should call this instead.
+ */
+ public static function safeIntended(?string $default = null): RedirectResponse
+ {
+ $default ??= '/';
+
+ $intended = session()->pull('url.intended');
+ $target = self::sameOriginUrl($intended) ?? $default;
+
+ return redirect()->to($target);
+ }
+
public static function getRedirectOption($request, $id, $table, $item_id = null): RedirectResponse
{
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index 886af7d51f..88f3a40b2b 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -970,7 +970,7 @@ class BulkAssetsController extends Controller
});
if (! $errors) {
- return redirect()->intended(route('hardware.index'))->with('success', trans_choice('admin/hardware/message.multi-checkin.success', count($asset_ids)));
+ return Helper::safeIntended(route('hardware.index'))->with('success', trans_choice('admin/hardware/message.multi-checkin.success', count($asset_ids)));
}
return redirect()->route('hardware.bulkcheckin.show')->withInput()
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index b2133e9c82..6636f56efb 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -76,7 +76,7 @@ class LoginController extends Controller
$this->loginViaRemoteUser($request);
$this->loginViaSaml($request);
if (Auth::check()) {
- return redirect()->intended('/');
+ return Helper::safeIntended('/');
}
if (! $request->session()->has('loggedout')) {
@@ -358,7 +358,7 @@ class LoginController extends Controller
}
// Redirect to the users page
- return redirect()->intended()->with('success', trans('auth/message.signin.success'));
+ return Helper::safeIntended()->with('success', trans('auth/message.signin.success'));
}
/**
@@ -460,7 +460,7 @@ class LoginController extends Controller
$user->saveQuietly();
$request->session()->put('2fa_authed', $user->id);
- return redirect()->intended()->with('success', trans('auth/message.signin.success'));
+ return Helper::safeIntended()->with('success', trans('auth/message.signin.success'));
}
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.invalid_code'));
diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php
index 44f06e1abc..5a1b554056 100755
--- a/app/Http/Controllers/DashboardController.php
+++ b/app/Http/Controllers/DashboardController.php
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
+use App\Helpers\Helper;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Company;
@@ -58,7 +59,7 @@ class DashboardController extends Controller
Session::reflash();
// Redirect to the profile page
- return redirect()->intended('account/view-assets');
+ return Helper::safeIntended('account/view-assets');
}
}
}
diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php
index e39296ff0a..63edcf0445 100644
--- a/app/Http/Middleware/RedirectIfAuthenticated.php
+++ b/app/Http/Middleware/RedirectIfAuthenticated.php
@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
+use App\Helpers\Helper;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -18,7 +19,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
- return redirect()->intended('/');
+ return Helper::safeIntended('/');
}
return $next($request);
diff --git a/tests/Unit/Helpers/HelperTest.php b/tests/Unit/Helpers/HelperTest.php
index a5f013d241..c97e09c16c 100644
--- a/tests/Unit/Helpers/HelperTest.php
+++ b/tests/Unit/Helpers/HelperTest.php
@@ -10,14 +10,7 @@ use Tests\TestCase;
class HelperTest extends TestCase
{
- /**
- * Regression: `<x-form.row type="datetimepicker">` on transient checkout
- * forms (hardware/checkout, bulk-checkout, kits/checkout, etc.) passes
- * `$item = null` down to `Helper::checkIfRequired`. Without the null guard
- * this hit `null::rules()` and threw "Class name must be a valid object or
- * a string", 500ing the whole page. When there's no bound model to
- * introspect, we treat the field as not required.
- */
+
public function test_check_if_required_returns_false_when_class_is_null()
{
$this->assertFalse(Helper::checkIfRequired(null, 'name'));
@@ -341,6 +334,86 @@ class HelperTest extends TestCase
$this->assertNull(Helper::sameOriginUrl('//evil.example.com/steal-session'));
}
+ public function test_same_origin_url_rejects_backslash_userinfo_parser_differential(): void
+ {
+ config(['app.url' => 'https://app.example.com']);
+
+ $this->assertNull(Helper::sameOriginUrl('https://evil.example.com\\@app.example.com/'));
+ $this->assertNull(Helper::sameOriginUrl('https://evil.example.com\\\\@app.example.com/'));
+ }
+
+ public function test_same_origin_url_rejects_userinfo_in_authority(): void
+ {
+ // Same-origin redirects never legitimately carry credentials. Any
+ // input where parse_url extracted userinfo is rejected outright,
+ // closing further parser-differential variants that hide the real
+ // authority behind an `@`.
+ config(['app.url' => 'https://app.example.com']);
+
+ $this->assertNull(Helper::sameOriginUrl('https://[email protected]/'));
+ $this->assertNull(Helper::sameOriginUrl('https://user:[email protected]/'));
+ $this->assertNull(Helper::sameOriginUrl('https://user:[email protected]/'));
+ }
+
+ public function test_safe_intended_returns_stored_url_when_it_passes_the_origin_guard(): void
+ {
+ config(['app.url' => 'https://app.example.com']);
+ Session::put('url.intended', 'https://app.example.com/foo?bar=1');
+
+ $response = Helper::safeIntended('/fallback');
+
+ $this->assertSame(302, $response->getStatusCode());
+ $this->assertSame('https://app.example.com/foo?bar=1', $response->headers->get('Location'));
+ }
+
+ public function test_safe_intended_falls_back_to_default_when_stored_url_is_offsite(): void
+ {
+ // A writer that skipped Helper::sameOriginUrl (or a future
+ // parser-differential bypass at the write) leaves a poisoned
+ // url.intended in session. The read-side guard must fall back to
+ // the caller-supplied default rather than emit the poisoned URL.
+ config(['app.url' => 'https://app.example.com']);
+ Session::put('url.intended', 'https://evil.example.com/steal-session');
+
+ $response = Helper::safeIntended('/fallback');
+
+ $this->assertStringEndsWith('/fallback', $response->headers->get('Location'));
+ }
+
+ public function test_safe_intended_falls_back_to_default_when_stored_url_uses_backslash_bypass(): void
+ {
+ // GHSA-579m-9gf4-28jp regression: even if a writer accepted the
+ // backslash-userinfo payload against an older Helper::sameOriginUrl,
+ // the emission-side guard must reject it.
+ config(['app.url' => 'https://app.example.com']);
+ Session::put('url.intended', 'https://evil.example.com\\@app.example.com/');
+
+ $response = Helper::safeIntended('/fallback');
+
+ $this->assertStringEndsWith('/fallback', $response->headers->get('Location'));
+ }
+
+ public function test_safe_intended_falls_back_to_default_when_session_key_is_absent(): void
+ {
+ Session::forget('url.intended');
+
+ $response = Helper::safeIntended('/fallback');
+
+ $this->assertStringEndsWith('/fallback', $response->headers->get('Location'));
+ }
+
+ public function test_safe_intended_pulls_the_session_key(): void
+ {
+ // pull() semantics: after the redirect is built, url.intended must
+ // be gone so subsequent requests don't re-consume the same target.
+ config(['app.url' => 'https://app.example.com']);
+ Session::put('url.intended', 'https://app.example.com/foo');
+
+ Helper::safeIntended('/fallback');
+
+ $this->assertFalse(Session::has('url.intended'));
+ }
+
/**
* FD-56673 regression coverage: customFieldFormValue collapses the
* gate + decrypt + default fallback that every branch of