Skip to content

fix: code quality and safety improvements - #913

Open
saurabhhhcodes wants to merge 1 commit into
shouri123:mainfrom
saurabhhhcodes:fix/Late-Meet-54513
Open

fix: code quality and safety improvements#913
saurabhhhcodes wants to merge 1 commit into
shouri123:mainfrom
saurabhhhcodes:fix/Late-Meet-54513

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Jul 31, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Bug Fixes

    • Improved the safety and reliability of API usage dashboard updates by using secure text rendering for loading, success, and error messages.
    • Reduced the risk of unintended markup being interpreted when displaying dashboard status information.
  • Documentation

    • Updated the HTML escaping example to demonstrate the safer text-rendering approach.

@github-actions github-actions Bot added gssoc Official GSSoC contribution issue gssoc:approved GSSoC: PR approved and scored bug Something isn't working size/XS type:code Type: Code change needs-issue and removed bug Something isn't working size/XS labels Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you @saurabhhhcodes for your contribution to Late-Meet!

⚠️ Warning: This PR does not seem to link to an open issue. Please edit the PR description to include Closes #XX to ensure your contribution counts for GSSoC points.

Please review any automated suggestions or code review comments that may appear below! We will review your PR as soon as possible!


Please consider starring the repository ⭐ to show your support!

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The dashboard now assigns loading, success, and error messages with textContent. The escapeHtml documentation example also uses textContent.

Changes

DOM rendering

Layer / File(s) Summary
Use textContent for dashboard output
src/apiUsageDashboard.ts, src/utils/domHelpers.ts
Dashboard states and the escapeHtml example now assign markup strings through textContent instead of innerHTML.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: shouri123

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the safety and code-quality improvements made by replacing innerHTML with textContent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Thank You for Contributing to Late-Meet

Please ensure that:

  • the issue was assigned to you before opening this PR
  • the PR references the related issue
  • your changes follow repository contribution guidelines
  • the project builds successfully before submission

Unassigned, duplicate, or low-quality PRs may be closed.

Thank you for contributing 💙

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/apiUsageDashboard.ts`:
- Around line 18-26: Update src/apiUsageDashboard.ts lines 18-26 to render the
loading and error paragraphs as DOM elements and insert
buildDashboardHTML(stats) through innerHTML or equivalent DOM construction,
ensuring dynamic values are escaped; update src/utils/domHelpers.ts line 29
likewise by creating the span through DOM APIs or using innerHTML with
escapeHtml().

In `@src/utils/domHelpers.ts`:
- Line 29: Correct the usage example in the escapeHtml documentation comment:
use raw user.displayName with textContent, or use escapeHtml(user.displayName)
with innerHTML when demonstrating escaped HTML. Do not combine HTML markup with
textContent, since it remains literal text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 16c83056-0592-42d8-9974-cabe1235ef83

📥 Commits

Reviewing files that changed from the base of the PR and between d216444 and 5613bc5.

📒 Files selected for processing (2)
  • src/apiUsageDashboard.ts
  • src/utils/domHelpers.ts

Comment thread src/apiUsageDashboard.ts
Comment on lines +18 to +26
container.textContent = '<p class="usage-loading">Loading API usage stats…</p>';

try {
const stats = await getUsageStats();
container.innerHTML = buildDashboardHTML(stats);
container.textContent = buildDashboardHTML(stats);
attachEventListeners(container);
} catch (err) {
console.error("[LateMeet] Failed to load API usage dashboard:", err);
container.innerHTML = '<p class="usage-error">Failed to load API usage data.</p>';
container.textContent = '<p class="usage-error">Failed to load API usage data.</p>';

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files:\n'
git ls-files | rg '(^|/)apiUsageDashboard\.ts$|(^|/)domHelpers\.ts$' || true

printf '\napiUsageDashboard outline:\n'
ast-grep outline src/apiUsageDashboard.ts || true

printf '\ndomHelpers outline:\n'
ast-grep outline src/utils/domHelpers.ts || true

printf '\nRelevant snippets:\n'
sed -n '1,120p' src/apiUsageDashboard.ts
printf '\n---\n'
sed -n '1,120p' src/utils/domHelpers.ts

printf '\nSearch for helper/dashboard functions:\n'
rg -n "buildDashboardHTML|getUsageStats|escapeHtml|attachEventListeners|usage-loading|usage-error" src || true

Repository: shouri123/Late-Meet

Length of output: 14426


🏁 Script executed:

# Read-only behavioral probe: show exactly what text node content each current assignment produces,
# without executing repository code or modifying files.
node - <<'JS'
const samples = [
  ['loading', '<p class="usage-loading">Loading API usage stats…</p>'],
  ['error', '<p class="usage-error">Failed to load API usage data.</p>'],
  ['example usage', '<div class="usage-dashboard"><div class="usage-card"><span>Tokens</span><strong>42</strong></div></div>'],
  ['example dynamic with angle brace', '<span>Alice <script>alert(1)</script> Smith</span>'],
];

for (const [name, html] of samples) {
  const doc = { body: document.createElement('div') };
  const container = doc.body;

  // Simulate current .textContent assignment.
  container.textContent = html;

  console.log(`${name}:`);
  console.log('textContent produces a single text node containing:', JSON.stringify(container.textContent));
  console.log('outerHTML:', container.outerHTML);
  console.log('firstChild tagName:', container.firstChild?.tagName ?? '<text>');
  console.log('has usage-card class:', container.classList && container.classList.contains('usage-card'));
  console.log('has script element:', container.querySelector?.('script') != null);
  console.log();
}
JS

Repository: shouri123/Late-Meet

Length of output: 793


🌐 Web query:

MDN Node textContent string markup rendered as text vs innerHTML

💡 Result:

The difference between using Node.textContent and Element.innerHTML primarily lies in how the browser handles markup, security, and performance [1][2]. Node.textContent - Rendering: When you set textContent, the browser treats the input string as raw text [1][2]. Any HTML markup included in the string (e.g., hello) will not be rendered as HTML; instead, it will appear literally as text on the page [2][3]. - Security: It is secure against cross-site scripting (XSS) attacks because it does not parse or execute the provided string as HTML [1][4]. - Performance: It is generally faster than innerHTML because the browser does not need to invoke the HTML parser [1][4]. Element.innerHTML - Rendering: When you set innerHTML, the browser parses the provided string as HTML markup [2]. Any valid HTML tags within the string will be rendered according to their standard behaviors [2][3]. - Security: It is a common vector for XSS attacks if the content being inserted comes from an untrusted source, as malicious scripts could be injected and executed [2][4]. - Performance: It is slower than textContent because it must invoke the HTML parser to construct the DOM tree from the provided string [1][4]. In summary, MDN advises using textContent whenever you intend to display plain text, as it is more semantic, performant, and secure [1][4]. You should only use innerHTML when you specifically need to insert and render HTML markup, and even then, you should ensure the content is sanitized or trusted to prevent security vulnerabilities [2][5].

Citations:


Do not assign HTML markup to textContent.

textContent treats the string as raw text, so the dashboard’s loading, error, and generated markup are rendered literally instead of as elements. Render the loading/error <p> elements explicitly, and insert buildDashboardHTML(stats) via innerHTML or DOM construction with escaped dynamic values. The src/utils/domHelpers.ts example also has this issue; create the <span> in the DOM or use innerHTML with escapeHtml().

📍 Affects 2 files
  • src/apiUsageDashboard.ts#L18-L26 (this comment)
  • src/utils/domHelpers.ts#L29-L29
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/apiUsageDashboard.ts` around lines 18 - 26, Update
src/apiUsageDashboard.ts lines 18-26 to render the loading and error paragraphs
as DOM elements and insert buildDashboardHTML(stats) through innerHTML or
equivalent DOM construction, ensuring dynamic values are escaped; update
src/utils/domHelpers.ts line 29 likewise by creating the span through DOM APIs
or using innerHTML with escapeHtml().

Comment thread src/utils/domHelpers.ts
*
* @example
* element.innerHTML = `<span>${escapeHtml(user.displayName)}</span>`;
* element.textContent = `<span>${escapeHtml(user.displayName)}</span>`;

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file outline =="
ast-grep outline src/utils/domHelpers.ts || true

echo "== relevant file contents =="
cat -n src/utils/domHelpers.ts | sed -n '1,160p'

echo "== references to domHelpers/escapeHtml =="
rg -n "escapeHtml|domHelpers|textContent|innerHTML" src -S || true

echo "== local script behavior probe for TextContent/InnerHTML semantics in browser would require runtime; instead use Node browserless unavailable by requirement. We'll inspect only source/config."

Repository: shouri123/Late-Meet

Length of output: 25216


🌐 Web query:

MDN textContent property HTML parsing does not parse tags

💡 Result:

The textContent property does not parse HTML tags. When you read the textContent of a node, it returns the concatenated text content of that node and all its descendants, explicitly excluding any HTML tags [1][2]. When you set the textContent of a node, the provided string is treated as raw text rather than HTML markup; it does not invoke the HTML parser [1][3][4]. Consequently, any HTML tags included in the string will be rendered as literal text on the page rather than being interpreted by the browser [4]. This behavior makes textContent a secure way to insert user-provided content into the DOM, as it prevents cross-site scripting (XSS) attacks that could otherwise occur if the input were parsed as HTML [1][3]. In contrast, the innerHTML property does invoke the HTML parser, meaning it treats the input string as markup and converts it into DOM elements [3][4].

Citations:


Correct the escapeHtml example.

textContent does not parse HTML. The example assigns literal <span>...</span> text instead of creating a span. Set the raw user.displayName as textContent, or assign escapeHtml(user.displayName) through innerHTML if the example is meant to demonstrate escaped HTML injection.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/domHelpers.ts` at line 29, Correct the usage example in the
escapeHtml documentation comment: use raw user.displayName with textContent, or
use escapeHtml(user.displayName) with innerHTML when demonstrating escaped HTML.
Do not combine HTML markup with textContent, since it remains literal text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC: PR approved and scored gssoc Official GSSoC contribution issue needs-issue type:code Type: Code change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant