-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove inline JS event handler from NavMenu component in Blazor Web App template #63828
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
Draft
Conversation
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
@dotnet-policy-service
dotnet-policy-service
bot
added
the
Attention: Shared Code Modified
label
Sep 25, 2025
...h ES6 module Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Copilot
AI
changed the title
(削除) [WIP] Remove the inline JS event handler in the
(追記) Remove inline JS event handler from NavMenu component in Blazor Web App template (追記ここまで)
Sep 25, 2025
NavMenu component? (削除ここまで)
Copilot finished work on behalf of
javiercn
September 25, 2025 14:46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check the different template configurations to make sure we are only adding this when needed? I imagine it'll be something in .templates.json.
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.
Uh oh!
There was an error while loading. Please reload this page.
Fixes #XXXXX
This PR removes the inline JavaScript event handler from the NavMenu component in the Blazor Web App project template and replaces it with a proper ES6 module approach to improve Content Security Policy (CSP) compliance.
Problem
The current NavMenu component contains an inline
onclickattribute:This inline event handler requires CSP configurations to include
'unsafe-hashes'with a specific SHA-256 hash, which goes against web security best practices. The HTML specification discourages this approach as it can lead to security vulnerabilities.Solution
NavMenu.razor.js: Added an ES6 module that properly attaches a click event listener to the navigation scrollable areaNavMenu.razor:<script type="module" src="@Assets["Components/Layout/NavMenu.razor.js"]"></script><div id="nav-scrollable" class="nav-scrollable">The JavaScript module code:
Benefits
'unsafe-hashes'in CSP configurationsReconnectModal.razor.jsandPasskeySubmit.razor.jsTesting
Verified that the navigation toggle functionality works correctly in both desktop and mobile responsive views. The hamburger menu opens and closes the navigation as expected, maintaining full backward compatibility.
Desktop view showing full navigation: Mobile view with hamburger menu:
Mobile Closed
Mobile view with navigation expanded:
Mobile Open
Impact
This change will help developers implement proper Content Security Policies without needing to accommodate inline event handlers, improving the overall security posture of Blazor Web applications created from the template.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.