Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRI integrity hash to assets #3256

Merged
merged 8 commits into from
Mar 8, 2021

Conversation

miguelsalespereira
Copy link
Contributor

Having the website pre-generated and hosted on a CDN, I would like to have integrity hashes included in CSS and JS assets.

This PR will allow:

  • User to set if wants the integrity hash to be generated and added to their <script> and elements
    • controlled via new system.assets.enable_asset_sri config option
  • When true, this option will generate the integrity hash and add it to both pipelined and not pipelined assets

@w00fz
Copy link
Member

w00fz commented Mar 5, 2021

Sweet, thanks!

@w00fz w00fz requested review from rhukster and mahagr March 5, 2021 16:49

if ( !empty($assetsConfig['enable_asset_sri']) && $assetsConfig['enable_asset_sri'] )
{
$dataToHash = file_get_contents( GRAV_ROOT . $input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@w00fz I think we should cache this part and maybe just check file modification time when hash recalculation isn't needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, also it should probably also use the Grav File instance and locator for the asset content and path, rather than file_get_contents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably merge then optimized to be honest.


if ( !empty($assetsConfig['enable_asset_sri']) && $assetsConfig['enable_asset_sri'] )
{
$dataToHash = file_get_contents( GRAV_ROOT . $input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably merge then optimized to be honest.

@rhukster rhukster merged commit 3b6f535 into getgrav:develop Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants