Skip to content

Comments

fix(sri): add integrity attributes with native html plugin#7133

Merged
chenjiahan merged 1 commit intomainfrom
native_html_sri_0203
Feb 3, 2026
Merged

fix(sri): add integrity attributes with native html plugin#7133
chenjiahan merged 1 commit intomainfrom
native_html_sri_0203

Conversation

@chenjiahan
Copy link
Member

Summary

  • Adds support and tests for generating SRI attributes when using the native HTML plugin
  • Adds new E2E tests to verify that SRI attributes are generated correctly when using the native HTML plugin.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings February 3, 2026 10:31
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chenjiahan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where Subresource Integrity (SRI) attributes were not being correctly applied when Rsbuild was configured to use its native HTML plugin. The changes involve adjusting the SRI plugin's configuration logic and adding new end-to-end tests to confirm that SRI attributes are now properly generated for enhanced security across different build and development setups.

Highlights

  • SRI Plugin Logic Refinement: The Subresource Integrity (SRI) plugin has been updated to conditionally apply the htmlPlugin option. This ensures that SRI attributes are correctly generated when using the native HTML plugin, by only setting the htmlPlugin path when the HTML implementation is JavaScript-based.
  • New E2E Test Coverage: Comprehensive end-to-end tests have been introduced to validate the proper generation of SRI attributes. These tests cover scenarios for both build and development environments when the native HTML plugin is enabled, ensuring the feature works as expected.
Changelog
  • e2e/cases/security/sri-native-html-plugin/index.test.ts
    • Added new E2E tests to verify that integrity attributes are generated correctly for scripts and stylesheets when using the native HTML plugin in both build and dev modes.
  • e2e/cases/security/sri-native-html-plugin/rsbuild.config.ts
    • Added a new Rsbuild configuration file for the E2E test case, enabling SRI and explicitly setting the HTML implementation to 'native'.
  • e2e/cases/security/sri-native-html-plugin/src/index.css
    • Added a basic CSS file (index.css) for the new E2E test case.
  • e2e/cases/security/sri-native-html-plugin/src/index.js
    • Added a basic JavaScript entry file (index.js) for the new E2E test case, including a CSS import and DOM manipulation.
  • packages/core/src/plugins/sri.ts
    • Modified the SRI plugin to conditionally set the htmlPlugin option for rspack.SubresourceIntegrityPlugin. The htmlPlugin option is now only applied if config.html.implementation is 'js' and config.tools.htmlPlugin is not false, allowing SRI to function correctly with the native HTML plugin.
Activity
  • The author has implemented support for Subresource Integrity (SRI) attributes to work with the native HTML plugin.
  • New end-to-end tests have been added to validate the correct generation of SRI attributes in both build and development environments.
  • The author has indicated that tests have been updated as part of this change.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully implements support for Subresource Integrity (SRI) attributes when using the native HTML plugin. The changes in sri.ts correctly introduce conditional logic to apply the htmlPlugin option to the SubresourceIntegrityPlugin only when the JavaScript-based HTML implementation is active. The new E2E tests adequately verify the generation of SRI attributes for both script and link tags in build and development environments, ensuring the functionality works as expected.

@chenjiahan chenjiahan merged commit a14cb3a into main Feb 3, 2026
10 checks passed
@chenjiahan chenjiahan deleted the native_html_sri_0203 branch February 3, 2026 10:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for generating Subresource Integrity (SRI) attributes when using Rspack's native HTML plugin implementation. Previously, the SRI plugin only configured the htmlPlugin option for the JavaScript implementation, which prevented SRI attributes from being generated when using the native implementation.

Changes:

  • Modified the SRI plugin to conditionally set the htmlPlugin option only for the JS implementation
  • Added E2E tests to verify SRI attribute generation with the native HTML plugin

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/src/plugins/sri.ts Refactored to conditionally set htmlPlugin option only when using JS implementation, allowing native plugin to work automatically
e2e/cases/security/sri-native-html-plugin/rsbuild.config.ts Test configuration enabling SRI with native HTML implementation
e2e/cases/security/sri-native-html-plugin/src/index.js Test entry point importing CSS and setting HTML content
e2e/cases/security/sri-native-html-plugin/src/index.css Test CSS file to verify integrity attributes on link tags
e2e/cases/security/sri-native-html-plugin/index.test.ts E2E tests verifying SRI attributes in both build and dev modes with native HTML plugin

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/<script crossorigin defer integrity="sha384-[A-Za-z0-9+/=]+"/,
);
expect(html).toMatch(
/link crossorigin href="\/static\/css\/index\.\w{8}\.css" integrity="sha384-[A-Za-z0-9+/=]+"/,
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The regex pattern is missing the opening < character before link. This will cause the test to match any substring containing "link crossorigin" instead of properly matching an HTML link tag. The pattern should be /<link crossorigin href=... to match the opening of a link element.

Suggested change
/link crossorigin href="\/static\/css\/index\.\w{8}\.css" integrity="sha384-[A-Za-z0-9+/=]+"/,
/<link crossorigin href="\/static\/css\/index\.\w{8}\.css" integrity="sha384-[A-Za-z0-9+/=]+"/,

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +12
expect(html).toMatch(
/<script crossorigin defer integrity="sha384-[A-Za-z0-9+/=]+"/,
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The regex pattern for the script tag does not include the src attribute. While this pattern will match script tags with integrity attributes, it's too permissive and doesn't verify that the script tag is actually loading a JavaScript file. Consider adding the src attribute pattern to be consistent with the sri-basic test and ensure the pattern matches complete script tags like: /<script crossorigin defer src="\/static\/js\/index\.\w{8}\.js" integrity="sha384-[A-Za-z0-9+/=]+"/

Copilot uses AI. Check for mistakes.
@chenjiahan chenjiahan mentioned this pull request Feb 3, 2026
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.

1 participant