Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[AssetMapper] Add Integrity Hashes to ImportMap (wip) #58722

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

Open
wants to merge 4 commits into
base: 7.3
Choose a base branch
Loading
from

Conversation

smnandre
Copy link
Member

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #54249
License MIT

-- Opening early to (hopefully) gather feedback and ideas --

This is a basic implementation to support integrity hashes within import maps:

  • Computes a base64-encoded SHA-384 digest in the factory.
  • Renders the integrity attribute for JavaScript files in the import map.

TODO

  • Make the integrity hash optional (e.g., through a constructor argument in the factory)
  • Compute hashes only for certain assets / types / paths ?
  • Expose configuration settings
  • Adapt the FrameworkBundle / DI
  • Determine handling approach for CSS files

Sources

PS: I'm a bit short on time lately... so if anyone wants to help or take over, please feel free!

This is a basic implementation to support integrity hashes within import maps:

- Computes a base64-encoded SHA-384 digest in the factory.
- Renders the integrity attribute for JavaScript files in the import map.

**TODO**
- [ ] Make the integrity hash optional (e.g., through a constructor argument in the factory)
- [ ] Compute hashes only for certain assets / types / paths ?
- [ ] Expose configuration settings
- [ ] Adapt the FrameworkBundle / DI
- [ ] Determine handling approach for CSS files

**Sources**
- [Subresource Integrity (SRI) Goals - W3C](https://www.w3.org/TR/SRI/#goals)
- [JSPM: JS Integrity with Import Maps](https://jspm.org/js-integrity-with-import-maps)

_PS: I'm a bit short on time lately... so if anyone wants to help or take over, please feel free!_
@pierreboissinot
Copy link

Hi @smnandre ,

I'll be glad to continue to help after the week-end.

smnandre#1

@pierreboissinot
Copy link

Hi @smnandre , did you check smnandre#1 ?

@smnandre smnandre force-pushed the feat/asset-mapper-integrity branch from 9bd9761 to 82b44da Compare November 7, 2024 01:39
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

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

Such a nice addition 🤩

Comment on lines +82 to +86
if (null !== $content) {
return 'sha384-'.base64_encode(hash('sha384', $content, true));
}

return 'sha384-'.base64_encode(hash_file('sha384', $asset->sourcePath, true));
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified to:

Suggested change
if (null !== $content) {
return 'sha384-'.base64_encode(hash('sha384', $content, true));
}
return 'sha384-'.base64_encode(hash_file('sha384', $asset->sourcePath, true));
$hash = $content !== null ? hash('sha384', $content, true) : hash_file('sha384', $asset->sourcePath, true);
return 'sha384-'.base64_encode($hash);

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if adding a var is worth it here. This code is not in the hotpath, so i'd maybe vote for code readability.

wdyt ?

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot
Copy link
Member

fabpot commented Mar 29, 2025

@smnandre Is it still something you want to finish working on?

@smnandre
Copy link
Member Author

I may find some time to.. but not before mid-week :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AssetMapper] Support SRI (integrity hashes)
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.