Skip to content

Add SRI Hash support to Static Web Assets in Blazor #61180

Open
@Tornhoof

Description

@Tornhoof

Is there an existing issue for this?

  • I have searched the existing issues

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, called AssetIntegrity

<link rel="stylesheet" integrity="@AssetIntegrity["MyApp.styles.css"]" crossorigin="anonymous" href="@Assets["MyApp.styles.css"]" />

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-maps

I looked at runtime into the data structures behind Assets, ResourceAssetCollection, but I couldn't find the Integrity property anywhere.

There is some prior discussins about CSP in #6001, but that includes a fully features CSP builder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions