-
Notifications
You must be signed in to change notification settings - Fork 0
Escape inline markdown output #19
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?
Conversation
|
@claude please review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/lib/markdown.ts
Outdated
| } else if (match[9]) { | ||
| // *italic* | ||
| result += `<em>${escapeHtml(match[10] ?? "")}</em>`; | ||
| } else if (match[11]) { | ||
| // _italic_ | ||
| result += `<em>${escapeHtml(match[12] ?? "")}</em>`; |
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.
Preserve
_italic_ matches in inline Markdown renderer
The regex used in renderInlineMarkdown defines only ten capturing groups, but the underscore branch checks match[11]/match[12]. When the input contains _text_, none of the earlier branches match, match[11] is always undefined, and the loop advances lastIndex without appending anything. This silently drops underscore-based italic segments from the output instead of wrapping them in <em> or escaping them. Adjust the indices (e.g., use match[10]) or add a capturing group so that _italic_ is rendered correctly.
Useful? React with 👍 / 👎.
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.
👍
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.
@claude please review and address this specific bit of feedback.
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.
Claude finished @plx's task —— View job
Tasks
- Read and analyze the current implementation in
src/lib/markdown.ts - Identify the regex capturing group issue
- Fix the underscore italic handling
- Commit and push changes
Analysis
I've identified and fixed the issue. The regex pattern has exactly 10 capturing groups:
1-2: `code` (outer + content)
3-4: **bold** (outer + content)
5-6: __bold__ (outer + content)
7-8: ~~strike~~ (outer + content)
9: *italic* (content only, no outer group)
10: _italic_ (content only, no outer group)
The current code had two bugs:
- Lines 35-37 checked
match[9]but incorrectly usedmatch[10]for content (should usematch[9]) - Lines 38-40 checked
match[11]and usedmatch[12]which don't exist (should usematch[10])
This caused _italic_ text to be silently dropped from the output.
Fix Applied
Updated src/lib/markdown.ts:35-40 to use the correct group indices:
match[9]for both checking and rendering*italic*match[10]for both checking and rendering_italic_
Changes Committed
Committed and pushed the fix to the PR branch. The CI workflow will validate the changes including linting, type checking, and spell checking.
Note: I wasn't able to run the linter locally due to permission restrictions, but the CI pipeline will verify the changes pass all checks.
--- | Latest commit
PR Validation ✅All checks passed! Ready for review. Checks Performed:✓ Linting This is a complete dry-run of the deployment process, ensuring your changes will deploy successfully when merged. |
The regex pattern has 10 capturing groups total, but the code was checking match[11]/match[12] for underscore italics which don't exist. Additionally, asterisk italics were using match[10] instead of match[9]. Fixed both issues: - match[9] now correctly used for *italic* content - match[10] now correctly used for _italic_ content This prevents _italic_ text from being silently dropped from output. Co-authored-by: plx <plx@users.noreply.github.com>
PR Validation ✅All checks passed! Ready for review. Checks Performed:✓ Linting This is a complete dry-run of the deployment process, ensuring your changes will deploy successfully when merged. |
Code Review: PR #19 - Escape inline markdown outputSummaryThis PR refactors the renderInlineMarkdown function to properly escape plain text segments while rendering inline markdown. The changes address a security vulnerability by ensuring all non-markdown text is HTML-escaped. StrengthsSecurity Improvement: The PR correctly addresses the XSS vulnerability. The new approach escapes plain text segments between markdown patterns (lines 19-20, 46-47) and continues to escape content within markdown tags. This is a significant security improvement. Code Quality: The refactored code is cleaner - converts from chained regex replacements to a single-pass parser using one comprehensive regex pattern. More predictable and efficient. Observations & Recommendations1. Test Coverage - CRITICAL There are no automated tests for this security-critical function. I strongly recommend adding unit tests covering:
Example: expect(renderInlineMarkdown("<script>alert('xss')</script>"))
.toBe("<script>alert('xss')</script>");2. Code Maintainability The numbered capture groups (match[1], match[2], etc.) are fragile. Consider adding a comment mapping group numbers to patterns for future maintainers. 3. Documentation Add JSDoc describing the security guarantees this function provides. Final VerdictRecommendation: Approve with Strong Suggestion for Tests The security fix is correct and necessary. Code quality is good. However, given that this function is used with set:html in multiple places (ContentCard.astro, blog pages, briefs pages, project pages), unit tests are highly recommended before merge to validate the fix and prevent regressions. Great work identifying and fixing this security issue! |
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_6907dc099588832798c96f0d10199469