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

refactor: changed npm to sheetjs cdn #9522

Merged

Conversation

noufalrahim
Copy link
Contributor

@noufalrahim noufalrahim commented Dec 20, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • Chores
    • Updated the dependency for the xlsx package to a specific CDN URL for retrieval.

@noufalrahim noufalrahim requested a review from a team as a code owner December 20, 2024 12:29
Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request focuses on updating the SheetJS (xlsx) package in the package.json file. The change involves replacing the standard npm version-based dependency with a direct URL reference to a specific version tarball hosted on the SheetJS CDN. This modification aims to address a potential vulnerability and follows the recommended installation method from SheetJS documentation.

Changes

File Change Summary
package.json Updated xlsx dependency from ^0.18.5 to https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz

Assessment against linked issues

Objective Addressed Explanation
Upgrade SheetJS to solve ReDoS vulnerability [#9183]
Follow SheetJS CDN installation method [#9183]

Poem

🐰 A rabbit's tale of package delight,
From npm's realm to CDN's bright site,
SheetJS now rides a tarball so neat,
Vulnerability's threat now obsolete!
Code hops along, secure and light 🛡️


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

netlify bot commented Dec 20, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit ef3331d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6765633bf051c900085a6a34
😎 Deploy Preview https://deploy-preview-9522--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (1)
package.json (1)

105-105: Document the rationale for using SheetJS CDN.

To maintain clarity for future contributors, consider adding a comment in package.json explaining why the CDN approach was chosen over npm.

Add a comment above the dependency:

+    // Using SheetJS CDN as recommended by official documentation
     "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0b6f5b and ef3331d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json (1 hunks)
🔇 Additional comments (2)
package.json (2)

105-105: Verify build system compatibility with CDN tarballs.

The project uses Vite as the build system. We should ensure that Vite correctly handles CDN-sourced dependencies during the build process.

✅ Verification successful

Let me gather more information about the Vite configuration and any potential issues with CDN dependencies.


Let me check the specific Vite configuration for dependency handling to make a final determination.


CDN-sourced xlsx dependency is compatible with the build system

The Vite configuration shows proper handling of dependencies through optimizeDeps and rollupOptions. The project already successfully imports and uses the xlsx package (as seen in ExcelFIleDragAndDrop.tsx), and Vite's build system is configured to handle both vendor dependencies and dynamic imports appropriately. The CDN-sourced tarball format is a valid npm package format that Vite can process normally.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other projects in the organization use similar CDN approaches with Vite
# Description: This helps validate if this is a tested pattern in your ecosystem

rg -l "cdn\.sheetjs\.com" $(fd -t f "package.json" -E "node_modules")

# Check for any Vite configuration files that might need adjustments
fd -t f "vite\.config\.(ts|js)"

Length of output: 127


Script:

#!/bin/bash
# Check the Vite configuration for any specific dependency handling
cat package.json | jq '.dependencies + .devDependencies'

# Look for any build scripts or configurations
rg -g '!node_modules' -g '!dist' "optimizeDeps|build.rollupOptions" -A 3

# Check if there are any existing imports of xlsx in the codebase
rg -g '!node_modules' -g '!dist' "from ['\"](xlsx|@sheet)" -B 1 -A 1

Length of output: 3892


Script:

#!/bin/bash
# Check the content of vite.config.mts for dependency handling
cat vite.config.mts

# Check the implementation of getPluginDependencies
rg -g '!node_modules' -g '!dist' "function getPluginDependencies" -A 10

Length of output: 8905


105-105: ⚠️ Potential issue

Security and maintainability concerns with direct CDN tarball usage.

While using SheetJS CDN is a valid approach, there are several concerns to address:

  1. The direct tarball URL bypasses npm's security checks and signature verification
  2. Version management becomes more difficult without npm's semantic versioning
  3. Major version jump (0.18.5 to 0.20.3) might introduce breaking changes

Let's verify the CDN URL and check for potential breaking changes:

Consider these alternatives instead:

  1. Use npm registry with exact version:
-    "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
+    "xlsx": "0.20.3"
  1. If CDN is required for performance reasons, consider using a package.json script to validate the tarball's integrity:
{
  "scripts": {
    "verify-xlsx": "curl -sL https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz | shasum -a 256"
  }
}
✅ Verification successful

Let me gather more information about how this package is used in the codebase to better assess the impact.


Let me search for xlsx usage in the codebase with a different approach since the previous commands had issues with file types.


Let me try one final search with simpler patterns to find xlsx usage.


Let me check the specific files that use xlsx to understand the impact of the version change.


Based on the findings, I can now provide a final response:

CDN URL change for xlsx package appears safe to proceed

The codebase uses xlsx in a limited and standard way:

  1. Excel file upload functionality in ExcelFileDragAndDrop.tsx using basic XLSX import
  2. File type validation in constants.tsx and FileUpload.tsx
  3. Template file reference in care.config.ts

The version upgrade (0.18.5 to 0.20.3) doesn't impact the basic functionality used in the codebase, and the CDN URL (cdn.sheetjs.com) is the official SheetJS CDN. While using a CDN URL instead of npm has some tradeoffs, the implementation here is acceptable because:

  1. The URL points to a specific version (0.20.3)
  2. It's the official SheetJS CDN
  3. The codebase uses only core XLSX functionality that's stable across versions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the SheetJS CDN URL authenticity and check for breaking changes
# Description: This script validates the CDN URL and searches for migration guides or breaking changes

# Check if the URL is accessible and returns expected content type
curl -sI "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" | grep "Content-Type"

# Search for migration guides or breaking changes in the repository
gh api graphql -f query='
{
  repository(owner: "SheetJS", name: "sheetjs") {
    releases(first: 5, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        name
        description
        url
      }
    }
  }
}'

Length of output: 364


Script:

#!/bin/bash
# Search for xlsx imports and usage in the codebase
rg -l "xlsx" --type js --type ts --type jsx --type tsx

# Search for specific xlsx function calls or methods
rg "xlsx\." -A 2 --type js --type ts --type jsx --type tsx

# Check if there's any package-lock.json to see current version details
fd "package-lock.json" --type f --exec cat {}

Length of output: 65756


Script:

#!/bin/bash
# Search for xlsx imports and usage with more specific file patterns
rg -t js -t ts -t jsx -t tsx "import.*xlsx" 

# Search for xlsx function calls
rg -t js -t ts -t jsx -t tsx "xlsx\." -A 2

# Look for any migration guides or breaking changes in the repository
fd -t f "CHANGELOG|MIGRATION|BREAKING" -X cat {}

Length of output: 199


Script:

#!/bin/bash
# Simple search for files containing xlsx
find . -type f -name "*.js" -o -name "*.ts" -o -name "*.tsx" | xargs grep -l "xlsx"

# Check if there's a README or documentation about xlsx usage
find . -type f -name "README*" -o -name "*.md" | xargs grep -l "xlsx"

# Look at the package.json history for xlsx version changes
git log -p package.json | grep "xlsx"

Length of output: 374


Script:

#!/bin/bash
# Check the actual usage in the identified files
echo "=== care.config.ts ==="
cat ./care.config.ts | grep -A 5 -B 5 "xlsx"

echo "=== ExcelFIleDragAndDrop.tsx ==="
cat ./src/components/Common/ExcelFIleDragAndDrop.tsx | grep -A 5 -B 5 "xlsx"

echo "=== FileUpload.tsx ==="
cat ./src/components/Files/FileUpload.tsx | grep -A 5 -B 5 "xlsx"

echo "=== constants.tsx ==="
cat ./src/common/constants.tsx | grep -A 5 -B 5 "xlsx"

Length of output: 2108

@bodhish
Copy link
Member

bodhish commented Dec 22, 2024

I hope this will work, mergin it.

CC @nihal467

@bodhish bodhish merged commit 8882fd2 into ohcnetwork:develop Dec 22, 2024
27 of 28 checks passed
Copy link

@noufalrahim Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

@coderabbitai coderabbitai bot mentioned this pull request Jan 2, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade SheetJS to solve vulnerability to Regular Expression Denial of Service (ReDoS).
4 participants