Feature: #109187 - Automatic SRI hash resolution for resource includes 

See forge#109187

Description 

Setting integrity = auto on any resource include that supports the integrity property causes TYPO3 to automatically compute and inject the Subresource Integrity (SRI) hash for that resource instead of requiring a manually pre-computed hash value.

This works for all integrity-supporting TypoScript include properties:

  • page.includeCSS
  • page.includeCSSLibs
  • page.includeJS
  • page.includeJSLibs
  • page.includeJSFooter
  • page.includeJSFooterlibs

The hash is computed using SHA-256 and the result is cached via cache.assets with a 7-day TTL, so there is no per-request overhead after the first render for a given resource.

For external URL resources, crossorigin="anonymous" is added automatically when the hash is successfully resolved, as required by the SRI specification for cross-origin resources.

The equivalent PHP constant \TYPO3\CMS\Core\Page\ResourceHashCollection::AUTO can be used when calling the PageRenderer or AssetCollector APIs directly.

Impact 

It is now possible to enable SRI for resource includes without manually computing the hash value. Setting integrity = auto is sufficient:

page.includeCSS {
    main = https://cdn.example.com/styles/main.css
    main.integrity = auto
    # crossorigin="anonymous" is added automatically for external URLs
}

page.includeJS {
    app = EXT:my_extension/Resources/Public/JavaScript/app.js
    app.integrity = auto
}
Copied!

This results in output such as:

<link rel="stylesheet" href="https://cdn.example.com/styles/main.css" media="all" integrity="sha256-abc123==" crossorigin="anonymous">
<script src="/typo3conf/ext/my_extension/Resources/Public/JavaScript/app.js" integrity="sha256-xyz789=="></script>
Copied!

When using the PHP API directly, pass ResourceHashCollection::AUTO as the $integrity argument:

use TYPO3\CMS\Core\Page\ResourceHashCollection;

$pageRenderer->addCssFile(
    'EXT:my_extension/Resources/Public/Css/style.css',
    integrity: ResourceHashCollection::AUTO,
);

$pageRenderer->addJsFile(
    'EXT:my_extension/Resources/Public/JavaScript/app.js',
    integrity: ResourceHashCollection::AUTO,
);

$assetCollector->addStyleSheet(
    'my-styles',
    'EXT:my_extension/Resources/Public/Css/style.css',
    ['integrity' => ResourceHashCollection::AUTO],
);
Copied!