-
Notifications
You must be signed in to change notification settings - Fork 99
fix: code quality and safety improvements #913
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ const HTML_ESCAPE_MAP: Record<string, string> = { | |
| * their corresponding named HTML entities. | ||
| * | ||
| * @example | ||
| * element.innerHTML = `<span>${escapeHtml(user.displayName)}</span>`; | ||
| * element.textContent = `<span>${escapeHtml(user.displayName)}</span>`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
💡 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
🤖 Prompt for AI Agents |
||
| * // Input: 'Alice <script>alert(1)</script>' | ||
| * // Output: 'Alice <script>alert(1)</script>' | ||
| */ | ||
|
|
||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: shouri123/Late-Meet
Length of output: 14426
🏁 Script executed:
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.textContenttreats 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 insertbuildDashboardHTML(stats)viainnerHTMLor DOM construction with escaped dynamic values. Thesrc/utils/domHelpers.tsexample also has this issue; create the<span>in the DOM or useinnerHTMLwithescapeHtml().📍 Affects 2 files
src/apiUsageDashboard.ts#L18-L26(this comment)src/utils/domHelpers.ts#L29-L29🤖 Prompt for AI Agents