-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The validation endpoint is the file primitive\n\nA CAS server's job is to issue tickets to authenticated clients and validate them when service applications come back to verify what the redirect claimed. The validation endpoint is by specification unauthenticated. Any service the CAS server federates with calls `/validate?ticket=ST-...&service=https://my-app.example.org` to confirm that the bearer of `ST-...` is who the redirect said they were. The CAS server reads the ticket from its store, confirms the service URL matches, and responds with the username.\n\nSimpleSAMLphp's `simplesamlphp-module-casserver` is the SimpleSAMLphp project's CAS server. It is the kind of component a university SSO operator picks because it is in the same codebase as the SAML stack their identity federation already runs. The ticket store is pluggable. The default backend is `FileSystemTicketStore`, which writes each ticket to a file under a configured directory with the ticket ID as the filename.\n\nCVE-2026-46491 names the public concatenation. Here is `getTicket` as shipped through v7.0.2, the last release before the May 2026 fix:\n\n```php\npublic function getTicket(string $ticketId): ?array\n{\n $filename = $this->pathToTicketDirectory . '/' . $ticketId;\n\n if (file_exists($filename)) {\n $content = file_get_contents($filename);\n\n return unserialize($content);\n } else {\n return null;\n }\n}\n```\n\n`$ticketId` is the value of the `ticket` query parameter from the public validation endpoint. The handler concatenates it onto the configured directory, calls `file_get_contents`, then `unserialize`. There is no filter on the path. There is no `allowed_classes` argument to `unserialize`.\n\n`?ticket=../../etc/casserver/config.php` reads the configured ticket directory's neighbor. `?ticket=../../../../var/lib/php/sessions/sess_aaaaa` reads a session file. The `file_exists` check fails silently for non-targets and reads the contents of everything else.\n\n## CAS 1.0 deletes the file before it verifies the ticket\n\nThe validation endpoint that takes the worst path is the CAS 1.0 `/validate`. Here is the relevant block of `Cas10Controller::validate`:\n\n```php\ntry {\n // Get the service ticket\n // `getTicket` uses the unserializable method and Objects may throw Throwables in their\n // unserialization handlers.\n $serviceTicket = $this->ticketStore->getTicket($ticket);\n // Delete the ticket\n $this->ticketStore->deleteTicket($ticket);\n} catch (Exception $e) {\n Logger::error('casserver:validate: internal server error. ' . var_export($e->getMessage(), true));\n return new Response(\n $this->cas10Protocol->getValidateFailureResponse(),\n Response::HTTP_INTERNAL_SERVER_ERROR,\n );\n}\n```\n\nRead the ordering. `getTicket` runs, then `deleteTicket` runs, then the controller starts checking whether the ticket is real. The check that the ticket actually identifies a CAS service ticket happens after the file has already been read, unserialized, and unlinked. The two operations resolve the same path: `getTicket` calls `$this->pathToTicketDirectory . '/' . $ticketId`, `deleteTicket` calls `$this->pathToTicketDirectory . '/' . $ticketId`. Same input. Same string. Different syscall.\n\nFor `deleteTicket` to fire, `getTicket` must not have thrown. `getTicket` declares its return type as `?array` under `declare(strict_types=1)`, so a return value of anything other than null or array raises `TypeError`. `unserialize` on garbage returns `false`, which triggers `TypeError` and short-circuits the try block before the delete. `unserialize` on a serialized integer or string triggers the same. The narrow channel is files whose contents unserialize to an array, or to the literal two-byte `N;` (serialized null). Cached PHP application state lives in serialized arrays. Other CAS tickets in the same directory are serialized arrays. Any file written somewhere on the filesystem by a PHP application that called `serialize($somearray)` qualifies.\n\nA campaign reads the disclosure primitive first to map the filesystem and find arrays-on-disk, then comes back with the same primitive to take them out. The author's comment on line 114 admits the read side of this knowingly:\n\n```php\n// `getTicket` uses the unserializable method and Objects may throw Throwables in their\n// unserialization handlers.\n```\n\nThe comment exists because something in the pipeline kept throwing at unserialize time and crashing the validator. The author caught the throw to keep the endpoint up. They did not ask why an unserialize call on a presumed-internal ticket file was producing object handlers that threw. The presumed-internal file was not the only file being unserialized.\n\n## The check existed in 2012\n\nThe original `FileSystemTicketStore` landed on November 29, 2012, in commit `d217e01`, authored by Bjørn Rohde Jensen at Statsbiblioteket, the Danish state library. The first version was a single class with `storeTicket` and `retrieveTicket` methods. `retrieveTicket` opened with:\n\n```php\npublic function retrieveTicket($ticket, $path, $unlink = true) {\n if (!preg_match('/^(ST|PT|PGT)-?[a-zA-Z0-9]+$/D', $ticket))\n throw new Exception('Invalid characters in ticket');\n ...\n}\n```\n\nThe CAS spec says ticket IDs are alphanumeric with a `ST-`, `PT-`, or `PGT-` prefix. The regex enforced that. Path separators were not in the allowed character class. Two-dot sequences were not. Null bytes were not. The check was there.\n\nA few days later, in commit `a806540` titled `moved logic into the ticket store super class`, Bjørn extracted the regex into a helper. A commit a week after that, `98b1d1b`, `moved generate and validate ticket id methods to abstract super class as default implementations`, moved the helper to the abstract `TicketStore` parent class as a default implementation, and wrapped the public methods in it:\n\n```php\nabstract class TicketStore\n{\n public function getTicket($ticket)\n {\n if ($this->validateTicketId($ticket)) {\n return $this->retrieveTicket($ticket);\n } else {\n return null;\n }\n }\n\n public function removeTicket($ticket)\n {\n if ($this->validateTicketId($ticket)) {\n $this->deleteTicket($ticket);\n }\n }\n\n protected function validateTicketId($ticket)\n {\n return preg_match('/^(ST|PT|PGT)-?[a-zA-Z0-9]+$/D', $ticket);\n }\n\n abstract protected function retrieveTicket($ticket);\n abstract protected function deleteTicket($ticket);\n // ...\n}\n```\n\nThis is the template method pattern. The parent class owns the public entrypoint. The public entrypoint runs the safety check, then dispatches to a protected primitive the subclass implements. The subclass's primitive does no validation, because the contract is that callers go through the parent's wrapper. `FileSystemTicketStore::retrieveTicket` was protected. `$this->pathToTicketDirectory . '/' . $ticket` was unsafe on its own. The parent class made it safe by guaranteeing nothing reached it without passing the regex first. The parent class was the gate.\n\n## The 2013 refactor removed the wrapper\n\nOn February 22, 2013, commit `564b9ac`, titled `removed ticket creation from ticket store`, inverted the architecture. The commit moved ticket-creation responsibilities out of the store class and into a separate `TicketFactory`. In doing so, it collapsed the template method:\n\n```diff\n abstract class sspmod_sbcasserver_Cas_Ticket_TicketStore\n {\n- public function getTicket($ticket) {\n- if ($this->validateTicketId($ticket)) {\n- return $this->retrieveTicket($ticket);\n- } else {\n- return null;\n- }\n- }\n- public function removeTicket($ticket) {\n- if ($this->validateTicketId($ticket)) {\n- $this->deleteTicket($ticket);\n- }\n- }\n- protected function validateTicketId($ticket) {\n- return preg_match('/^(ST|PT|PGT)-?[a-zA-Z0-9]+$/D', $ticket);\n- }\n- abstract protected function retrieveTicket($ticket);\n- abstract protected function storeTicket($ticket, $content);\n- abstract protected function deleteTicket($ticket);\n+ abstract public function getTicket($ticketIdIdIdId);\n+ abstract public function addTicket($ticket);\n+ abstract public function removeTicket($ticketIdId);\n }\n```\n\n`$ticketIdIdIdId`. That is not a typo we introduced. The file shipped that day with the variable name literally written with three `Id`s stuttered onto the end of the parameter, and `removeTicket($ticketIdId)` with two. The refactor was fast. Names are honest.\n\nThe subclasses inverted in the same commit. `FileSystemTicketStore::retrieveTicket`, previously protected and called only after `validateTicketId` had passed, was renamed `getTicket` and made public. The validation step was not relocated, it was deleted. The wrapping public method that ran the check was gone. The protected primitive that did the file operations was now the public method. From this commit forward, the public entrypoint to the file store concatenated an attacker-controllable string onto a filesystem path, opened it, and unserialized it.\n\nThe commit body describes a structural change. The commit title describes ticket creation moving out. Neither names the security property the parent class had carried. The validation rode along with the architectural collapse, and was never put back. The casserver module shipped the unguarded primitive on every release for the next thirteen years.\n\n## Three sibling stores were safe by coincidence\n\nThe same refactor flattened `MemCacheTicketStore`, `SQLTicketStore`, and the later-added `RedisTicketStore` in the same way. All four subclasses received the same architectural treatment. None of them got their own path validator.\n\nThe other three were safe anyway. `MemCacheTicketStore::getTicket` does this:\n\n```php\npublic function getTicket(string $ticketId): ?array\n{\n $scopedTicketId = $this->scopeTicketId($ticketId);\n // ... fetches from memcache\n}\n\nprivate function scopeTicketId(string $ticketId): string\n{\n return $this->prefix . '.' . $ticketId;\n}\n```\n\nThe scoped ID is a memcache key. `..` and `/` in a memcache key are weird key strings, not file paths. `RedisTicketStore` does the same with a Redis key. `SQLTicketStore` binds the scoped ID as a query parameter; PDO escapes it.\n\nThe parent class's check had been defense in depth for backends that did not need it. For the one backend that did, it was load-bearing. The pluggable storage layer was supposed to let an operator choose between Memcache and Redis and SQL and the filesystem with interchangeable safety properties. The architecture made all four interchangeable in shape. The path traversal class was always specific to the filesystem. The validation gate that protected the filesystem was deleted because flattening the abstraction reads as cleanup. The three coincidentally-safe stores carried the cleanup forward. The one unsafe store stayed unsafe.\n\n## The patch puts the gate inside the file store\n\nCommit `b84f3e4`, May 15, 2026, restores the check. Not by reviving the parent class's template method; the architecture stays flat. The new check lives inside `FileSystemTicketStore`, where the unsafe primitive lives. Each of the public methods that used to concatenate `$ticketId` now calls a private `validateTicketPath`:\n\n```php\nprivate function validateTicketPath(string $ticketId): string\n{\n if ($ticketId === '') {\n throw new Exception('Invalid ticketId provided.');\n }\n\n // Prevent directory traversal and path separators.\n // CAS tickets are typically like: ST-..., PT-..., PGT-..., etc. Hyphens are ok.\n if (\n str_contains($ticketId, '/')\n || str_contains($ticketId, '\\\\')\n || str_contains($ticketId, '..')\n ) {\n throw new Exception('Invalid ticketId provided.');\n }\n\n $baseDir = realpath($this->pathToTicketDirectory);\n if ($baseDir === false) {\n throw new Exception('Ticket storage directory is not accessible.');\n }\n\n // Store tickets as hashed filenames inside the ticket directory.\n return $baseDir . DIRECTORY_SEPARATOR . sha1($ticketId);\n}\n```\n\nThe patch also hardens the unserialize call:\n\n```diff\n- return unserialize($content);\n+ $result = unserialize($content, ['allowed_classes' => false]);\n+ Assert::isArray($result, \"Failed to unserialize ticket.\");\n+ return $result;\n```\n\n`allowed_classes => false` blocks PHP object injection. A serialized object becomes an `__PHP_Incomplete_Class` instance with no `__wakeup` execution. Until this commit shipped, every casserver running with the default ticket store had not just a file-read and conditional-delete primitive but a PHP object injection sink that fired on any file the read primitive could nudge content into. The patch lays in two fences at once. The bug existed for thirteen years with neither.\n\n## The commit title named the cargo\n\nThis is the part nobody is going to say. The original author wrote the check, then wrote the refactor that removed it. The check existed in `retrieveTicket` for two days, in a helper for one day, in the abstract parent class for a few weeks, and then disappeared in a commit titled `removed ticket creation from ticket store`.\n\nA commit title is testimony. It records what the author intends a reviewer to look for. The reviewer of `removed ticket creation from ticket store` reads it as a refactor scope: did this commit move ticket creation out, yes, ship. The reviewer does not look for a security check the parent class used to carry, because the title does not mention one. The same is true of every static-analysis pass and every audit conducted on the casserver module between 2013 and 2026. The check had been in the parent class. The parent class no longer had a body. There was nothing in the file store's own code to grep for. This is parent-class-was-the-gate as a named class of mistake: the wrapping public method that ran the check is deleted in a refactor, the protected primitive is promoted to the public method, the safety property is lost in the architectural flattening, and the only artifact that ever named the safety property was a commit title that talked about something else.\n\nAnd it is trust inversion as the meta-story. The CAS server is the federation's authorizer. The validation endpoint is the surface the federation deliberately exposes to every consumer, because the consumer's question is the only one a CAS server is supposed to answer. CVE-2026-46491 turns that exposed surface into a file read and conditional file delete primitive on the identity host. SimpleSAMLphp shipped the unguarded primitive on its public CAS validation endpoint to every identity federation deployment that picked the file-backed ticket store from 2013 to 2026. The reporter who finally noticed, kamil-sawicki, filed the bug in May 2026. The patch lands the check thirteen years late.\n\nPoC: [GHSA-jrrg-99xh-5j2q](https://github.com/advisories/GHSA-jrrg-99xh-5j2q)","closing_line":"A CAS server's job is to validate tickets. SimpleSAMLphp casserver's validation endpoint reads and deletes files.","hook_md":"SimpleSAMLphp's casserver module has shipped `FileSystemTicketStore` with no path-traversal check on its public CAS validation endpoint since February 22, 2013. The check existed in 2012. A commit titled `removed ticket creation from ticket store` removed it. The commit title named the cargo. It did not name the safety net riding along. CVE-2026-46491, scored 8.6 and patched on May 15, 2026 in v7.0.3, is what an attacker does with a CAS server that has been a path traversal sink for thirteen years.","post_id":654,"slug":"simplesamlphp-casserver-parent-class-was-the-gate","title":"CVE-2026-46491: SimpleSAMLphp casserver's Validation Endpoint Reads And Deletes Files. The Check Was Removed In A 2013 Refactor.","type":"initial","unreadable_sentence":"The validation rode along. The title named the cargo."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCau+N7QAKCRDeZjl4jgkQ JnpnAQDUMV2QeZ/J8CBpOyXKqc4cRdEGBG80r5loLwdtadVx/gEA3TSPRy8I//sq cLRbNtWh6jkMUXsscETb1tWd2bOAwgQ= =p1lY -----END PGP SIGNATURE-----