🛡️ Sentinel: [HIGH] Fix XSS by sanitizing go-readability output with bluemonday#138
🛡️ Sentinel: [HIGH] Fix XSS by sanitizing go-readability output with bluemonday#138
Conversation
Co-authored-by: lucasew <15693688+lucasew@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary of ChangesHello @lucasew, 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 application's security posture by mitigating a critical XSS vulnerability. It ensures that all content processed by the service is thoroughly sanitized before being presented to users, thereby preventing malicious script execution and safeguarding user sessions from potential client-side attacks. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical Cross-Site Scripting (XSS) vulnerability by sanitizing the HTML output from go-readability using the bluemonday library. The introduction of the UGCPolicy is a solid choice for this use case. The addition of a new test case, TestXSSPrevention, is excellent as it specifically verifies that malicious vectors are removed, confirming the fix. My review includes a minor suggestion in the new test file to improve code maintainability by using a built-in Go function.
api/xss_test.go
Outdated
| func min(a, b int) int { | ||
| if a < b { | ||
| return a | ||
| } | ||
| return b | ||
| } |
There was a problem hiding this comment.
This custom min function is unnecessary. Since the project uses Go 1.24.7 (as per go.mod), you can use the built-in min function that was introduced in Go 1.21. This improves code clarity and reduces maintenance by relying on the standard library. You can remove this function, and the call on line 64 will automatically use the built-in min.
Co-authored-by: lucasew <15693688+lucasew@users.noreply.github.com>
Co-authored-by: lucasew <15693688+lucasew@users.noreply.github.com>
Severity: HIGH
Vulnerability:
Reflected Cross-Site Scripting (XSS). The application renders HTML content parsed by
go-readabilitydirectly into the response without adequate sanitization. Whilego-readabilitycleans up page structure, it does not guarantee the removal of all malicious attributes (e.g.,<img onerror=...>) or script tags, allowing an attacker to inject arbitrary JavaScript if a user visits a malicious URL processed by the service.Impact:
An attacker could craft a malicious URL that, when processed by this service and viewed by a victim, executes JavaScript in the context of the victim's session. This could lead to cookie theft, redirection, or other client-side attacks.
Fix:
Implemented strict HTML sanitization using
github.com/microcosm-cc/bluemondaywith theUGCPolicy. The sanitization is applied in thehandlerimmediately after the article content is rendered to the buffer, ensuring that all output formats (HTML, JSON, Markdown) are safe.Verification:
Added a new test file
api/xss_test.gowithTestXSSPrevention.go test ./apipasses.PR created automatically by Jules for task 14110619838270003521 started by @lucasew