webui: fix 404 for "View rule in capa-rules" by using proper URL encoding#2868
Conversation
The createCapaRulesUrl function was constructing URLs by lowercasing the rule name and replacing spaces with hyphens, which produced URLs like /rules/packaged-as-single-file-.net-application/ (404). The capa-rules website uses the original rule name with URL encoding (e.g. /rules/packaged%20as%20single-file%20.NET%20application/). Use encodeURIComponent() on the rule name to produce correct URLs. Fixes mandiant#2482
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @devs6186, 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 a bug in the capa Explorer web UI where clicking "View rule in capa-rules" resulted in a 404 error. The fix involves updating the URL generation logic to correctly encode rule names using Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where URLs for 'View rule in capa-rules' were being generated incorrectly, leading to 404 errors. The fix replaces a manual string transformation with encodeURIComponent, which is the proper way to encode URL components. The change is simple, effective, and also includes an update to the changelog. I've added one suggestion to improve code consistency within the urlHelpers.js file by extracting the base URL into a constant.
| if (!node || !node.data) return null; | ||
| const ruleName = node.data.name.toLowerCase().replace(/\s+/g, "-"); | ||
| return `https://mandiant.github.io/capa/rules/${ruleName}/`; | ||
| return `https://mandiant.github.io/capa/rules/${encodeURIComponent(node.data.name)}/`; |
There was a problem hiding this comment.
For consistency with other URL helper functions in this file (e.g., createATTACKHref) and to improve maintainability by avoiding magic strings, it's a good practice to define the base URL as a constant.
const baseUrl = "https://mandiant.github.io/capa/rules/";
return `${baseUrl}${encodeURIComponent(node.data.name)}/`;|
I have read the CLA Document and I hereby sign the CLA |
46311fe to
adb07b5
Compare
|
Good call — updated the function to extract |
…ding (mandiant#2868) * webui: fix 404 for \"View rule in capa-rules\" links The createCapaRulesUrl function was constructing URLs by lowercasing the rule name and replacing spaces with hyphens, which produced URLs like /rules/packaged-as-single-file-.net-application/ (404). The capa-rules website uses the original rule name with URL encoding (e.g. /rules/packaged%20as%20single-file%20.NET%20application/). Use encodeURIComponent() on the rule name to produce correct URLs. Fixes mandiant#2482 * refactor: extract baseUrl constant in createCapaRulesUrl per code review
closes #2482
The "View rule in capa-rules" context menu item was constructing URLs by lowercasing the rule name and replacing spaces with hyphens:
The capa-rules website uses the original rule name with URL encoding (percent-encoding), not hyphen-separated lowercase slugs:
Fix: Replace the manual transformation with
encodeURIComponent()on the original rule name, which correctly percent-encodes spaces and other special characters while preserving case.All existing webui tests pass.
Checklist