Visit the Wiz Whimzical Shop at AWS re:Invent
Vulnerability DatabaseGHSA-v2m3-jwg5-vv65

GHSA-v2m3-jwg5-vv65: 
PHP vulnerability analysis and mitigation

Summary

Modifiers chained on Router::any() reach only the GET route. Router::any('/admin', $h)->role('admin') (and ->can(...)) therefore enforces the role on GET only: any authenticated user, whatever their role, can call the same path with POST, PUT, PATCH or DELETE.

Details

Router::any() (Tina4/Router.php, v3) registers five routes, then points the chain state (lastRouteMethod / lastRouteIndex) at the GET route alone. role(), can(), secure(), noAuth(), noCsrf(), cache(), noCache() and swagger() all write to that single slot. Only middleware() copies to the other four methods. Two further effects of the same code:

  • any(...)->noAuth() opens GET only; the write methods stay 401 (fails closed).
  • The GET index is taken as count(routes['GET']) - 1. When any() re-registers a path that already has a GET route, the modifier lands on the newest GET route instead: get('/r1'); get('/r2'); any('/r1')->secure(); secures /r2 and leaves /r1 open.

Reproduction

Checked on v3 at 2fbdf9a3 through bin/tina4php serve, CSRF off.

$h = fn($req, $res) => $res->json(['ok' => true]);
Router::any('/admin', $h)->role('admin');

With a valid token whose roles are ["user"]:

MethodResultExpected
GET403403
POST, PUT, PATCH, DELETE200403

Impact

Authorization bypass on write methods for any route declared with Router::any() plus role() or can(). A valid token is still required; the role or permission check is what is skipped.

Fix

Patch below, against v3 2fbdf9a3. The chain state becomes a list of every route the last call registered, and each modifier applies to all of them. middleware() is unchanged. Includes tests/RouterAnyChainTest.php (9 tests): 5 fail on the unpatched tree, all pass with the patch. Full suite: same failing tests before and after (driver and environment tests only). No CI runs on this path, so these are local runs. Behaviour change to note in the release: any()->noAuth() and any()->noCsrf() now apply to all five methods, as written.

diff --git a/Tina4/Router.php b/Tina4/Router.php
index 1f738d18..24881272 100644
--- a/Tina4/Router.php
+++ b/Tina4/Router.php
@@ -127,6 +127,15 @@ class Router
     /** @var string Method of the last registered route */
     private static ?string $lastRouteMethod = null;
 
+    /**
+     * Every [method, index] slot the chained modifiers (->noAuth(), ->secure(),
+     * ->role(), ...) apply to. One slot after get()/post()/...; five after any(),
+     * so a modifier chained on any() reaches every method it registered.
+     *
+     * @var array<int, array{0: string, 1: int}>
+     */
+    private static array $lastRouteTargets = [];
+
     /** @var bool True while devAdminRoutes() runs: routes added then are the dev dashboard's own */
     private static bool $registeringDevAdmin = false;
 
@@ -263,12 +272,17 @@ class Router
      */
     public static function any(string $path, callable $handler, array $middleware = [], array $swaggerMeta = [], ?string $template = null): self
     {
+        $targets = [];
         foreach (['GET', 'POST', 'PUT', 'PATCH', 'DELETE'] as $method) {
             self::addRoute($method, $path, $handler, $swaggerMeta, $middleware, $template);
+            $targets[] = [$method, self::$lastRouteIndex];
         }
-        // Point lastRoute to the GET one for chaining
+        // Point lastRoute to the GET one for middleware(), and at every
+        // method's slot for the other chained modifiers (noAuth, secure,
+        // role, ...) so they reach all five routes, not only GET.
         self::$lastRouteMethod = 'GET';
-        self::$lastRouteIndex = count(self::$routes['GET']) - 1;
+        self::$lastRouteIndex = $targets[0][1];
+        self::$lastRouteTargets = $targets;
         return new self();
     }
 
@@ -353,8 +367,8 @@ class Router
      */
     public function cache(): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['cache'] = true;
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            self::$routes[$m][$i]['cache'] = true;
         }
         return $this;
     }
@@ -366,8 +380,8 @@ class Router
      */
     public function noCache(): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['cache'] = false;
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            self::$routes[$m][$i]['cache'] = false;
         }
         return $this;
     }
@@ -388,9 +402,9 @@ class Router
      */
     public function swagger(array $meta): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            $existing = self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['swagger'] ?? [];
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['swagger'] = array_merge($existing, $meta);
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            $existing = self::$routes[$m][$i]['swagger'] ?? [];
+            self::$routes[$m][$i]['swagger'] = array_merge($existing, $meta);
         }
         return $this;
     }
@@ -402,8 +416,8 @@ class Router
      */
     public function secure(): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['secure'] = true;
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            self::$routes[$m][$i]['secure'] = true;
         }
         return $this;
     }
@@ -418,8 +432,8 @@ class Router
      */
     public function noAuth(): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['noAuth'] = true;
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            self::$routes[$m][$i]['noAuth'] = true;
         }
         return $this;
     }
@@ -438,8 +452,8 @@ class Router
      */
     public function noCsrf(): self
     {
-        if (self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['noCsrf'] = true;
+        foreach (self::$lastRouteTargets as [$m, $i]) {
+            self::$routes[$m][$i]['noCsrf'] = true;
         }
         return $this;
     }
@@ -453,9 +467,11 @@ class Router
      */
     public function role(string ...$names): self
     {
-        if ($names !== [] && self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['roles'][] = $names;
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['secure'] = true;
+        if ($names !== []) {
+            foreach (self::$lastRouteTargets as [$m, $i]) {
+                self::$routes[$m][$i]['roles'][] = $names;
+                self::$routes[$m][$i]['secure'] = true;
+            }
         }
         return $this;
     }
@@ -470,9 +486,11 @@ class Router
      */
     public function can(string ...$permissions): self
     {
-        if ($permissions !== [] && self::$lastRouteMethod !== null && self::$lastRouteIndex !== null) {
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['perms'][] = $permissions;
-            self::$routes[self::$lastRouteMethod][self::$lastRouteIndex]['secure'] = true;
+        if ($permissions !== []) {
+            foreach (self::$lastRouteTargets as [$m, $i]) {
+                self::$routes[$m][$i]['perms'][] = $permissions;
+                self::$routes[$m][$i]['secure'] = true;
+            }
         }
         return $this;
     }
@@ -2989,6 +3007,7 @@ class Router
         self::$groupMiddleware = [];
         self::$lastRouteIndex = null;
         self::$lastRouteMethod = null;
+        self::$lastRouteTargets = [];
         self::$basePath = '.';
         self::$resolvedStringMiddleware = [];
     }
@@ -3069,6 +3088,7 @@ class Router
         }
 
         self::$lastRouteMethod = $method;
+        self::$lastRouteTargets = [[$method, self::$lastRouteIndex]];
 
         return new self();
     }
diff --git a/tests/RouterAnyChainTest.php b/tests/RouterAnyChainTest.php
new file mode 100644
index 00000000..ca123d46
--- /dev/null
+++ b/tests/RouterAnyChainTest.php
@@ -0,0 +1,167 @@
+<?php
+
+/*
+ * Copyright (c) 2026 Code Infinity
+ * SPDX-License-Identifier: MPL-2.0
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * Modifiers chained on Router::any() must reach every method any() registered.
+ *
+ * any() registers GET, POST, PUT, PATCH and DELETE. Chained modifiers used to
+ * touch the GET route only, so ->noAuth() left the four write routes at 401 and
+ * ->role() left them with no role check at all. Real Router::dispatch.
+ */
+
+use PHPUnit\Framework\TestCase;
+use Tina4\Auth;
+use Tina4\Request;
+use Tina4\Response;
+use Tina4\Router;
+
+class RouterAnyChainTest extends TestCase
+{
+    private const SECRET = 'router-any-chain-secret-0123456789abcdef';
+    private const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
+
+    /** @var array<string, string|false> */
+    private array $savedEnv = [];
+
+    protected function setUp(): void
+    {
+        foreach (['TINA4_SECRET', 'TINA4_DEBUG', 'TINA4_API_KEY', 'TINA4_CSRF'] as $key) {
+            $this->savedEnv[$key] = getenv($key);
+        }
+        Router::clear();
+        putenv('TINA4_SECRET=' . self::SECRET);
+        $_ENV['TINA4_SECRET'] = self::SECRET;
+        putenv('TINA4_DEBUG=false');
+        putenv('TINA4_API_KEY');
+        putenv('TINA4_CSRF');
+        unset($_ENV['TINA4_DEBUG'], $_ENV['TINA4_API_KEY'], $_ENV['TINA4_CSRF']);
+    }
+
+    protected function tearDown(): void
+    {
+        Router::clear();
+        foreach ($this->savedEnv as $key => $value) {
+            if ($value === false) {
+                putenv($key);
+                unset($_ENV[$key]);
+            } else {
+                putenv("{$key}={$value}");
+                $_ENV[$key] = $value;
+            }
+        }
+    }
+
+    private function call(string $method, string $path, array $headers = []): int
+    {
+        return Router::dispatch(
+            Request::create(method: $method, path: $path, headers: $headers, remoteIp: '127.0.0.1'),
+            new Response(testing: true)
+        )->getStatusCode();
+    }
+
+    private function bearer(array $payload): array
+    {
+        return ['Authorization' => 'Bearer ' . Auth::getToken($payload, self::SECRET, 600)];
+    }
+
+    private function handler(): callable
+    {
+        return fn(Request $request, Response $response) => $response(['ok' => true]);
+    }
+
+    public function testNoAuthOnAnyOpensEveryMethod(): void
+    {
+        Router::any('/open', $this->handler())->noAuth();
+
+        foreach (self::METHODS as $method) {
+            $this->assertSame(200, $this->call($method, '/open'), "{$method} should be public");
+        }
+    }
+
+    public function testAnyWithoutNoAuthStillSecuresWrites(): void
+    {
+        Router::any('/closed', $this->handler());
+
+        foreach (['POST', 'PUT', 'PATCH', 'DELETE'] as $method) {
+            $this->assertSame(401, $this->call($method, '/closed'), "{$method} should stay secured");
+        }
+    }
+
+    public function testNoAuthOnAnyDoesNotLeakToOtherPaths(): void
+    {
+        Router::any('/open', $this->handler())->noAuth();
+        Router::any('/other', $this->handler());
+
+        $this->assertSame(401, $this->call('POST', '/other'));
+    }
+
+    public function testSecureOnAnySecuresEveryMethod(): void
+    {
+        Router::any('/locked', $this->handler())->secure();
+
+        foreach (self::METHODS as $method) {
+            $this->assertSame(401, $this->call($method, '/locked'), "{$method} should require a token");
+        }
+    }
+
+    public function testRoleOnAnyGatesEveryMethod(): void
+    {
+        Router::any('/admin', $this->handler())->role('admin');
+
+        $user = $this->bearer(['sub' => 'u1', 'roles' => ['user']]);
+        $admin = $this->bearer(['sub' => 'u2', 'roles' => ['admin']]);
+        foreach (self::METHODS as $method) {
+            $this->assertSame(403, $this->call($method, '/admin', $user), "{$method} must refuse a non-admin");
+            $this->assertSame(200, $this->call($method, '/admin', $admin), "{$method} must admit an admin");
+        }
+    }
+
+    public function testCanOnAnyGatesEveryMethod(): void
+    {
+        Router::any('/posts', $this->handler())->can('posts.write');
+
+        $without = $this->bearer(['sub' => 'u1', 'permissions' => ['posts.read']]);
+        foreach (self::METHODS as $method) {
+            $this->assertSame(403, $this->call($method, '/posts', $without), "{$method} must refuse a caller without the permission");
+        }
+    }
+
+    public function testCacheAndSwaggerAndNoCsrfOnAnyReachEveryMethod(): void
+    {
+        Router::any('/meta', $this->handler())->cache()->swagger(['summary' => 'S'])->noCsrf()->secure();
+
+        foreach (self::METHODS as $method) {
+            $route = Router::match($method, '/meta')['route'];
+            $this->assertTrue($route['cache'], "{$method} cache flag");
+            $this->assertSame('S', $route['swagger']['summary'], "{$method} swagger meta");
+            $this->assertTrue($route['noCsrf'], "{$method} noCsrf flag");
+            $this->assertTrue($route['secure'], "{$method} secure flag");
+        }
+    }
+
+    public function testSingleMethodRouteModifiersStillTouchOnlyThatRoute(): void
+    {
+        Router::get('/pair', $this->handler());
+        Router::post('/pair', $this->handler())->noAuth();
+
+        $this->assertSame(200, $this->call('POST', '/pair'));
+        $this->assertTrue(Router::match('POST', '/pair')['route']['noAuth']);
+        $this->assertFalse(Router::match('GET', '/pair')['route']['noAuth']);
+    }
+
+    public function testModifiersAfterAnyDoNotReachAnEarlierAnyRoute(): void
+    {
+        Router::any('/first', $this->handler());
+        Router::any('/second', $this->handler())->noAuth();
+
+        $this->assertSame(401, $this->call('POST', '/first'));
+        $this->assertSame(200, $this->call('POST', '/second'));
+    }
+}

Source: NVD

Related PHP vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

GHSA-77gj-jmpx-g9fqHIGH8.1
  • PHP logoPHP
  • erugooss/erugo
NoYesNov 30, 2026
GHSA-679q-wc28-7wrvMEDIUM6.3
  • PHP logoPHP
  • knplabs/knp-snappy
NoYesNov 30, 2026
GHSA-qjgm-48mm-xm5qMEDIUM4.8
  • PHP logoPHP
  • bitpay/module-bpcheckout
NoYesNov 30, 2026
GHSA-v2m3-jwg5-vv65HIGHN/A
  • PHP logoPHP
  • tina4stack/tina4php
NoYesNov 30, 2026
GHSA-h2mr-m3v3-cq8cLOWN/A
  • JavaScript logoJavaScript
  • tina4-python
NoYesNov 30, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management