This PR addresses an insecure design pattern by replacing occurrences of
the unsafe `uniqid()` function within the Styleguide ViewHelpers
(`ExampleViewHelper`, `CodeViewHelper`, and `ColorSchemeViewHelper`).
The `uniqid()` function produces predictable values based on the current
system time in microseconds, which violates secure-by-design principles
when generating unique identifiers. This patch eliminates this unsafe
library call by migrating to TYPO3's own `StringUtility::getUniqueId()`,
which securely utilizes `random_bytes()` under the hood to generate
cryptographically safe randomness.
How the patch works:
The patch systematically replaces all usages of `uniqid()` in the
Styleguide extension's ViewHelpers with `StringUtility::getUniqueId()`.
- In `ExampleViewHelper.php` and `CodeViewHelper.php`, `uniqid('code')`
was updated to `StringUtility::getUniqueId('code')`, and the `use
TYPO3\CMS\Core\Utility\StringUtility;` import statement was added to the
file header.
- In `ColorSchemeViewHelper.php`, `uniqid($defaultScheme)` was updated to
`StringUtility::getUniqueId($defaultScheme)`. The file already had the
`StringUtility` import, so no header changes were required.
Security Impact:
The primary security impact is proactive hardening. By removing
`uniqid()`, we eliminate an error-prone design pattern.
`StringUtility::getUniqueId()` delegates to `random_bytes(13)`, which
provides high-entropy, cryptographically secure randomness, ensuring that
the generated identifiers cannot be easily guessed or predicted.