Skip to content
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

Added rehypeSanitize to improve preview xss issues #323

Merged
merged 3 commits into from
Aug 28, 2024

Conversation

taeng0204
Copy link
Contributor

@taeng0204 taeng0204 commented Aug 28, 2024

Added rehypeSanitize to handle dangerous markdown
Added options for rehypeKatex to ensure formula marking

What this PR does / why we need it:
Prevents dangerous HTML from being rendered verbatim to prevent XSS attacks.
Added rehypeSanitize to integrate with existing rehypePlugins to solve the issue

Which issue(s) this PR fixes:

Fixes #320

Special notes for your reviewer:
Added an option to ensure rehypeKatex's expression of formulas.
In addition to the option, the order of rehypeSanitize and rehypeKatex is also important.

code: [["className", /^language-./, "math-inline", "math-display"]],

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Enhanced security for rendering user-generated HTML content by integrating a sanitization plugin.
    • Improved handling of syntax highlighting through customizable class attributes for code elements.
  • Bug Fixes

    • Ensured compatibility with existing plugins for a more robust content processing pipeline.

Added rehypeSanitize to handle dangerous markdown
Added options for rehypeKatex to ensure formula marking
@CLAassistant
Copy link

CLAassistant commented Aug 28, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes enhance the Preview component by integrating the rehype-sanitize plugin for improved security, specifically against XSS vulnerabilities. This update sanitizes user-generated HTML content while allowing specific attributes for code elements. The overall processing pipeline remains intact, ensuring compatibility with existing plugins.

Changes

Files Change Summary
frontend/src/components/editor/Preview.tsx Enhanced Preview component with rehype-sanitize for HTML content security and attribute control.
frontend/package.json Added new dependency "rehype-sanitize": "^6.0.0" to improve HTML sanitization.

Assessment against linked issues

Objective Addressed Explanation
Needs preview improvements for XSS attack vulnerabilities (#320)

🐇 In the meadow, where the code does play,
A sprinkle of safety kept the bugs at bay.
With rehype-sanitize, our HTML's secure,
No more XSS fears, the content is pure!
Hopping along, we celebrate this feat,
A safer CodePair makes our project complete! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 995e4d0 and 3b4084a.

Files selected for processing (1)
  • frontend/src/components/editor/Preview.tsx (2 hunks)
Additional comments not posted (1)
frontend/src/components/editor/Preview.tsx (1)

9-9: Review the import of rehypeSanitize and defaultSchema.

The import statement for rehypeSanitize and defaultSchema is correct and follows standard practices for importing modules in JavaScript/TypeScript.

The import statement is correctly implemented.

frontend/src/components/editor/Preview.tsx Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3b4084a and 30a55df.

Files selected for processing (1)
  • frontend/package.json (1 hunks)
Additional comments not posted (1)
frontend/package.json (1)

74-74: Approved addition of rehype-sanitize dependency.

The addition of "rehype-sanitize": "^6.0.0" to the dependencies is aligned with the PR objectives to enhance security by preventing XSS vulnerabilities. This is a crucial step towards improving the safety of the application's content rendering.

The code changes are approved.

Run the following script to verify if additional configurations are needed:

Verification successful

Integration of rehype-sanitize verified and approved.

The rehype-sanitize package is correctly listed as a dependency in frontend/package.json and is being used in frontend/src/components/editor/Preview.tsx. This confirms that the integration is in place and aligns with the PR's security objectives. No additional configuration updates are required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for additional configurations or setups needed for `rehype-sanitize`.

# Test: Search for configuration files that might need updates. Expect: List of files that might need updates.
fd 'config|setup' --type f --exec grep -H 'rehype' {}

Length of output: 55


Script:

#!/bin/bash
# Description: Search for any usage of `rehype-sanitize` within the codebase to ensure it is correctly integrated.

# Test: Search for any file that imports or uses `rehype-sanitize`.
rg 'rehype-sanitize' --type js -A 5

Length of output: 35


Script:

#!/bin/bash
# Description: Search for any usage of `rehype-sanitize` across all file types to ensure it is correctly integrated.

# Test: Search for any file that imports or uses `rehype-sanitize`.
rg 'rehype-sanitize' -A 5

Length of output: 901

@taeng0204 taeng0204 self-assigned this Aug 28, 2024
@taeng0204 taeng0204 added the enhancement 🌟 New feature or request label Aug 28, 2024
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

frontend/src/components/editor/Preview.tsx Show resolved Hide resolved
@devleejb devleejb merged commit 09fd1f8 into main Aug 28, 2024
2 checks passed
@devleejb devleejb deleted the preview-xss-improvements branch August 28, 2024 10:12
@coderabbitai coderabbitai bot mentioned this pull request Nov 2, 2024
2 tasks
minai621 pushed a commit that referenced this pull request Nov 5, 2024
* Added rehypeSanitize to improve preview xss issues

Added rehypeSanitize to handle dangerous markdown
Added options for rehypeKatex to ensure formula marking

* Add the rehype-sanitize dependency

* Add package-lock.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
Status: Done
Status: Backlog
Development

Successfully merging this pull request may close these issues.

Needs preview improvements for XSS attack vulnerabilities
3 participants