Skip to content

Sanitize onboarding HTML rendering#17

Merged
jonmartin721 merged 3 commits intomainfrom
touchup/dom-sanitization
Mar 9, 2026
Merged

Sanitize onboarding HTML rendering#17
jonmartin721 merged 3 commits intomainfrom
touchup/dom-sanitization

Conversation

@jonmartin721
Copy link
Owner

Summary

  • escape onboarding token-step status content before inserting HTML
  • sanitize popular repository suggestion rendering in onboarding
  • add regression coverage for malicious repository metadata and saved token values

Testing

  • eslint on changed files
  • jest tests/onboarding.test.js --runInBand

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 significantly enhances the security of the onboarding process by implementing robust HTML sanitization. It addresses potential cross-site scripting (XSS) vulnerabilities by escaping user-controlled data before it is rendered into the DOM, specifically for token validation status messages and popular repository suggestions. Comprehensive regression tests have also been added to ensure the effectiveness of these security measures against various forms of malicious input.

Highlights

  • HTML Sanitization: Implemented HTML escaping for token-step status messages to prevent Cross-Site Scripting (XSS) vulnerabilities.
  • Repository Suggestion Security: Ensured popular repository suggestions are sanitized before rendering to mitigate malicious data injection.
  • Regression Testing: Added new regression tests to cover scenarios involving malicious repository metadata and saved token values.
Changelog
  • popup/views/onboarding-view.js
    • Imported escapeHtml utility function for content sanitization.
    • Introduced getStatusMarkup helper to consistently render status messages with HTML escaping.
    • Created renderRepoSuggestion helper to safely render repository details, escaping all dynamic data.
    • Refactored token step status updates to use getStatusMarkup.
    • Applied escapeHtml to the token input value and the token URL link.
    • Updated popular repository rendering to utilize the new renderRepoSuggestion function.
  • tests/onboarding.test.js
    • Imported _renderOnboardingStep for testing purposes.
    • Added a test case to verify that renderReposStep correctly escapes malicious repository metadata.
    • Included a test to confirm that renderOnboardingStep escapes saved token values and usernames to prevent XSS.
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.

@sentry
Copy link

sentry bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 67.85714% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
popup/views/onboarding-view.js 67.85% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

@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

This pull request effectively addresses and prevents Cross-Site Scripting (XSS) vulnerabilities by correctly implementing HTML sanitization for user-provided data in the onboarding flow. The introduction of helper functions like getStatusMarkup and renderRepoSuggestion, along with a robust escapeHtml utility, centralizes the sanitization logic and applies it to all untrusted data sources. Regression tests have also been added to ensure malicious input is properly handled. There is one suggestion to improve the clarity of the renderRepoSuggestion function.

const name = escapeHtml(repo?.name || 'unknown');
const description = escapeHtml(repo?.description || `${repo?.language || 'Popular'} project`);
const language = escapeHtml(repo?.language || '');
const repoFullName = `${owner}/${name}`;

Choose a reason for hiding this comment

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

medium

This line constructs repoFullName from already-escaped parts. While this works due to how dataset API handles HTML entities, it's clearer and more robust to work with raw data for logic and escape only at the moment of rendering into HTML. This avoids confusion and makes the code's intent more explicit.

I suggest changing this line to use the raw owner and name. Consequently, you would then need to wrap repoFullName with escapeHtml() on line 36 where it's inserted into the data-repo attribute to ensure it's safely rendered.

Example for line 36:

<button class="add-repo-btn" data-repo="${escapeHtml(repoFullName)}">+</button>
Suggested change
const repoFullName = `${owner}/${name}`;
const repoFullName = `${repo?.owner?.login || 'unknown'}/${repo?.name || 'unknown'}`;

Copy link
Owner Author

Choose a reason for hiding this comment

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

Adjusted repoFullName to use the raw owner/name values and escape only at render time while updating the coverage on this branch. Thanks.

@jonmartin721
Copy link
Owner Author

Follow-up pushed in 78cb805: applied the repoFullName cleanup in renderRepoSuggestion and expanded onboarding sanitization tests to cover the token-step status paths that were dragging patch coverage.

@jonmartin721 jonmartin721 merged commit 6ba6662 into main Mar 9, 2026
2 checks passed
@jonmartin721 jonmartin721 deleted the touchup/dom-sanitization branch March 9, 2026 01:57
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.

1 participant