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 Subresource Integrity support for ModuleFederation #14310

Closed
amitbet opened this issue Sep 23, 2021 · 16 comments
Closed

Add Subresource Integrity support for ModuleFederation #14310

amitbet opened this issue Sep 23, 2021 · 16 comments
Labels

Comments

@amitbet
Copy link

amitbet commented Sep 23, 2021

Feature request

What is the expected behavior?
I am working in a large enterprise org, and we are using ModuleFederation for our MicroFrontEnds implementation.
I would like to have the ability to use SRI (via plugin or some flag in the ModFed settings)

What is motivation or use case for adding/changing the behavior?
The dynamic loading of JS code is an opening for supply chain attack, this concern was raised by our security team and we need some mechanism to ensure the integrity of the loaded JS.

How should this be implemented in your opinion?
the createElement in LoadScriptRuntimeModule.js should be modified to enable adding the "integrity=[contentHash]" attribute, and it should be flaggable in the config.

if there's a better way i would like to hear about it (there is no documentation online about SRI and ModFed)

Are you willing to work on this yourself?
yes, but I would need some help in order to "do no harm"

@alexander-akait
Copy link
Member

Anyway you can do it using plugin

@amitbet
Copy link
Author

amitbet commented Sep 23, 2021

how? the SubResource integrity plugin doesn't work with federated modules as far as I can see...

@sokra
Copy link
Member

sokra commented Sep 23, 2021

Where should we get the integrity from?
The idea with module federation is that the remote script can change independent from the consuming script. So it can't be passed via config. It need to be provided at runtime.

I would recommend to opt-out of automatic remote script loading and let your server compose a html with remote script tags including integrity.

@amitbet
Copy link
Author

amitbet commented Sep 23, 2021

For the chunk level we can hardcode (generate) the integrity into the remote-entry.js file.
For the top level, there are several options depending on what you are implementing, if there is a declaration of the remotes, you can include the integrity hash in that definition, if it is more dynamic than that (as it is in our case as well),
the top level integrity should be coming from the same code that knows which concrete module you will be consuming (in our app we resolve a tree of modules with semver queries into concrete versions, and we can have an integrity hash associated with each widget version).

in summary: in the more dynamic cases, you should leave the top level open to receive the integrity from outside.

@vankop vankop added the module-federation issues related to module federation label Nov 24, 2021
@aversini
Copy link

I am in the same boat as you @amitbet : big corporation with need for both module federation and SRI. Did you figure out a way? I’m wondering if we could simply limit SRI to app level, and ignore it for chunks coming from the remotes? We are using the webpack-subresource-integrity plugin but it doesn’t seem to being able to let us bypass some chunks - it’s all or nothing…

@subeshb1
Copy link

subeshb1 commented Jun 2, 2022

Any updates on this?

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@azinod
Copy link

azinod commented May 12, 2023

+1 to this

@sowtame
Copy link

sowtame commented Aug 21, 2023

bump

@fdecollibus
Copy link

+1

1 similar comment
@AmsterGet
Copy link

+1

@sowtame
Copy link

sowtame commented Sep 27, 2023

hi, I made a temporary package @sowtame/webpack-subresource-integrity, supports wmf.
it's created from this pr

@noahnu
Copy link

noahnu commented Jan 12, 2024

This wasn't actually resolved, was it? That's just the stale bot closing the issue?

@alexander-akait
Copy link
Member

It is a plugin side, there is a PR waysact/webpack-subresource-integrity#220

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

No branches or pull requests

13 participants