Repository navigation
Restrict JavaScript root component operations - #69240
Merged
Merged
Conversation
Restricts parameter updates and removal to roots created by JavaScript. ---- #### AI description (iteration 1) #### PR Classification Security enhancement to restrict JavaScript root component operations by validating component ownership. #### PR Summary This pull request adds validation to ensure that JavaScript can only modify or remove root components that it originally created, preventing unauthorized operations on server-rendered components. - `JSComponentInterop.cs`: Added `_jsComponentIds` HashSet to track JS-added components and `EnsureValidJSComponentId()` validation method that throws `InvalidOperationException` for unauthorized operations in `SetRootComponentParameters()` and `RemoveRootComponent()`. - `JSComponentInteropTest.cs`: Added comprehensive unit tests verifying that operations on server-rendered components are rejected while JS-added components remain accessible. - `JSRootComponentsTest.cs` and test assets: Added E2E test case and supporting JavaScript helpers to verify parameters cannot be updated on non-JS root components, with UI elements to trigger and display validation errors. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The E2E coverage targets the wrong root, and its assertion does not verify the intended rejection.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Restricts parameter updates and removal to root components created through JavaScript interop.
Changes:
- Tracks JavaScript-created root IDs and validates operations.
- Adds unit and end-to-end coverage for unauthorized operations.
- Adds renderer interop test plumbing and a non-JavaScript root scenario.
File summaries
| File | Summary |
|---|---|
src/Components/Web/test/JSComponents/JSComponentInteropTest.cs |
Tests authorized and unauthorized operations. |
src/Components/Web/src/JSComponents/JSComponentInterop.cs |
Tracks and validates JavaScript root IDs. |
src/Components/test/testassets/Components.TestServer/Pages/_ServerHost.cshtml |
Captures renderer interop for tests. |
src/Components/test/testassets/BasicTestApp/wwwroot/js/jsRootComponentInitializers.js |
Adds renderer interop helpers. |
src/Components/test/testassets/BasicTestApp/wwwroot/index.html |
Enables WebAssembly interop capture. |
src/Components/test/testassets/BasicTestApp/JavaScriptRootComponents.razor |
Adds the unauthorized-update scenario. |
src/Components/test/testassets/BasicTestApp/Index.razor |
Adds a non-JavaScript root parameter. |
src/Components/test/E2ETest/Tests/JSRootComponentsTest.cs |
Adds end-to-end rejection coverage. |
Review details
Suppressed comments (1)
src/Components/test/E2ETest/Tests/JSRootComponentsTest.cs:117
- This assertion only checks the locally generated prefix; any failure in the helper itself (for example, if
rendererInteropwas never captured) is caught and formatted with the same prefix, so the test can pass without reachingEnsureValidJSComponentId. Assert that the displayed error also containswas not added by JavaScriptto verify the intended rejection.
Browser.Contains("Error setting parameters on non-JS root", () => app.FindElement(By.Id("message")).Text);
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
|
|
||
| async function setNonJSRootParameters() { | ||
| const error = await myJsRootComponentInitializers.setRootComponentParameters( | ||
| 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restricts parameter updates and removal to roots created by JavaScript.