#109780Hardening identifier generation: Migrate from insecure uniqid() to cryptographically secure random_bytes()
Description
This PR significantly hardens the TYPO3 core by eliminating the use of the insecure, predictable `uniqid()` function for generating unique identifiers.
It refactors the core `StringUtility::getUniqueId()` method to leverage PHP’s native `random_bytes()` function, establishing a Secure-by-Design standard across the TYPO3 ecosystem that guarantees 100% cryptographically secure, unpredictable, and collision-resistant identifiers. Additionally, it refactors several internal ViewHelpers within the `styleguide` extension that were unsafely invoking `uniqid()` directly, ensuring they now consume the secured, centralized utility.
### What This Patch Does and Why It Is Necessary
The `uniqid()` function in PHP generates identifiers based on the current system time in microseconds. It is explicitly documented as predictable and non-cryptographic, making it unsuitable for use in security-sensitive contexts. Reliance on this function introduces an error-prone design pattern that may lead to identifier predictability, increased risk of token-based attacks, and potential collisions in high-throughput environments.
This patch addresses these concerns by implementing the following changes:
#### 1. Securing the Core Utility
The method `\TYPO3\CMS\Core\Utility\StringUtility::getUniqueId()` has been reimplemented to use `bin2hex(random_bytes(10))` in place of `uniqid()`. This approach ensures the generation of identifiers with 80 bits of cryptographically secure entropy. As a result, it effectively eliminates predictability and timing-based vulnerabilities while preserving backward compatibility in terms of output format.
#### 2. Standardizing Subsystem Implementations
Three ViewHelpers within the `styleguide` extension—`ExampleViewHelper`, `CodeViewHelper`, and `ColorSchemeViewHelper`—have been refactored. These components previously relied on direct calls to `uniqid()` and have now been updated to utilize the secure `StringUtility::getUniqueId()` method, ensuring consistency and adherence to secure coding standards across the system.
#### Security Impact
- Eliminates the use of a predictable and non-cryptographic identifier generation mechanism
- Mitigates the risk of token and identifier-based attacks
- Reduces the likelihood of collisions in concurrent or high-load environments
- Introduces the use of a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG)
#### Conclusion
By replacing an insecure design pattern with a cryptographically secure alternative, this patch strengthens the overall security posture of the application. It establishes a secure-by-design approach for identifier generation and ensures that all dependent subsystems adhere to modern security best practices.
This issue was automatically created from https://github.com/TYPO3/typo3/pull/638
Reviews 1
History 14
-
Gerrit Code Review pushed patch set 1 for main to change 93998 status
NewUnder Review <span data-processor="relativetime" data-value="2026-05-05T22:29:25+00:00" > 05/05/26, 22:29 </span> -
Gerrit Code Review pushed patch set 2 for main to change 93998 <span data-processor="relativetime" data-value="2026-10-06T15:55:08+00:00" > 10/06/26, 15:55 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 93998 <span data-processor="relativetime" data-value="2026-10-07T19:36:07+00:00" > 10/07/26, 19:36 </span>
-
Anonymous commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-10-07T20:10:13+00:00" > 10/07/26, 20:10 </span>
Applied in changeset commit:cb9ef44d612e99bb1e282aa5a254a68ca2c4d271.