-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add SRI Hash support to Static Web Assets in Blazor #61180
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
Comments
@Tornhoof thanks for contacting us. We don't populate this, but this information is already available on the resource collection. The integrity property contains the We would definitely not add a public property on component base for this. |
Yeah, i know about the importmap, but this applies only to scripts and not to styles correct? Some way e.g. interface to access that build time static web assets data would bei quite nice.
Perfectly fine, I think you missed a few opportunities when you added |
@Tornhoof thanks for the additional details. The point of showing you the code that we reference is to give you a guide on how you can implement this feature/functionality yourself if you choose to do so. The ability to do this is already there (it's no coincidence that we chose to include the integrity and to do so in that format) so you can write your components/extensions around it. |
Thank you for your clarification. I'll see how far I'll get myself. |
Now I found out, why I couldn't find "integrity" in any of those collections during debugging. aspnetcore/src/StaticAssets/src/Development/StaticAssetDevelopmentRuntimeHandler.cs Lines 184 to 189 in d24486f
|
I pulled the git commit ID out of the Blazor library and used that as the version string.
So when you reference a new version of the Blazor library, your clients will download a new version of the blazor.web.js file. Maybe not totally perfect since the js file might stay the same from one version to the next, but it's probably "good enough". I've omitted my caching code from this sample, you should calculate the hash in Program.cs once rather than using reflection for each page load ;-> |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I'm trying to calculate SRI hashes for the static web assets in my Blazor Web App.
At the moment, the suggested way for static data is simply to calculate it elsewhere and paste the SRI hash into my App..razor.
See https://learn.microsoft.com/en-us/aspnet/core/blazor/security/content-security-policy?view=aspnetcore-9.0#adopt-subresource-integrity-sri
I'd like an built-in way to do that
Describe the solution you'd like
Something like a new method in ComponentBase, similar to
Assets
, calledAssetIntegrity
Additional context
I looked at the build-time staticwebassets.build.json, there is already a property called Integrity, which is used for ETag and (I think) for
ImportMap
. https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/static-files?view=aspnetcore-9.0#import-mapsI looked at runtime into the data structures behind
Assets
,ResourceAssetCollection
, but I couldn't find theIntegrity
property anywhere.There is some prior discussins about CSP in #6001, but that includes a fully features CSP builder.
The text was updated successfully, but these errors were encountered: