Skip to content

webui: fix 404 for "View rule in capa-rules" by using proper URL encoding#2868

Merged
mike-hunhoff merged 2 commits into
mandiant:masterfrom
devs6186:fix/2482-webui-url-encoding
Feb 23, 2026
Merged

webui: fix 404 for "View rule in capa-rules" by using proper URL encoding#2868
mike-hunhoff merged 2 commits into
mandiant:masterfrom
devs6186:fix/2482-webui-url-encoding

Conversation

@devs6186

Copy link
Copy Markdown
Contributor

closes #2482

The "View rule in capa-rules" context menu item was constructing URLs by lowercasing the rule name and replacing spaces with hyphens:

// Before (broken)
const ruleName = node.data.name.toLowerCase().replace(/\s+/g, "-");
// → /rules/packaged-as-single-file-.net-application/  (404)

The capa-rules website uses the original rule name with URL encoding (percent-encoding), not hyphen-separated lowercase slugs:

/rules/packaged%20as%20single-file%20.NET%20application/  (200 ✓)

Fix: Replace the manual transformation with encodeURIComponent() on the original rule name, which correctly percent-encodes spaces and other special characters while preserving case.

// After (fixed)
return `https://mandiant.github.io/capa/rules/${encodeURIComponent(node.data.name)}/`;

All existing webui tests pass.

Checklist

  • No CHANGELOG update needed
  • No new tests needed
  • No documentation update needed
  • This submission includes AI-generated code and I have provided details in the description.

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
@google-cla

google-cla Bot commented Feb 18, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 encodeURIComponent, ensuring that links to the capa-rules website resolve properly.

Highlights

  • URL Encoding Fix: Corrected the URL construction for the "View rule in capa-rules" context menu item in the web UI to prevent 404 errors.
  • encodeURIComponent Adoption: Replaced manual string manipulation for rule names with encodeURIComponent() to properly handle spaces and special characters in URLs.

🧠 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
  • CHANGELOG.md
    • Added a changelog entry for the web UI fix regarding URL encoding for capa-rules.
  • web/explorer/src/utils/urlHelpers.js
    • Updated the createCapaRulesUrl function to use encodeURIComponent for rule names.
Activity
  • Pull request opened by devs6186 to fix a 404 error in the web UI.
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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread web/explorer/src/utils/urlHelpers.js Outdated
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)}/`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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)}/`;

@devs6186

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@devs6186 devs6186 closed this Feb 18, 2026
@devs6186 devs6186 reopened this Feb 18, 2026
@devs6186 devs6186 force-pushed the fix/2482-webui-url-encoding branch from 46311fe to adb07b5 Compare February 18, 2026 22:40
@devs6186

Copy link
Copy Markdown
Contributor Author

Good call — updated the function to extract baseUrl as a constant, consistent with how createATTACKHref and createMBCHref are structured in the same file. Pushed in the latest commit.

@mike-hunhoff mike-hunhoff merged commit e41b5fb into mandiant:master Feb 23, 2026
3 checks passed
saniyafatima07 pushed a commit to saniyafatima07/capa that referenced this pull request Jun 17, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webui: "View rule in capa-rules" results in 404 for some rules

3 participants