Skip to content

Adding lock scanner for vulnerabilitiesΒ #42

@rully-saputra15

Description

@rully-saputra15

πŸ“‹ Problem Statement

Currently, fix-react2shell-next only scans package.json files for vulnerable package versions. However, this approach has limitations:

  • ❌ Doesn't detect vulnerable packages in transitive dependencies
  • ❌ Misses vulnerabilities that exist in lock files but not in package.json
  • ❌ Cannot verify the actual resolved versions in the dependency tree
  • ❌ Users may have vulnerable React 19 packages installed that aren't directly specified

πŸ’‘ Proposed Solution

Add a new --scan-lockfiles (or --lockfiles) flag that scans lock files to detect vulnerable React 19 packages anywhere in the dependency tree.

Supported Lock Files

  • βœ… package-lock.json (npm v1, v2, v3)
  • βœ… yarn.lock (yarn v1)
  • βœ… pnpm-lock.yaml (pnpm v6+)
  • βœ… bun.lockb / bun.lock (bun)

React Packages to Scan

  • react
  • react-dom
  • react-server-dom-webpack
  • react-server-dom-parcel
  • react-server-dom-turbopack

🎯 Expected Behavior

New flag to enable lock file scanning

npx fix-react2shell-next --scan-lockfiles

Output example

πŸ”’ Scanning lock files for React 19 vulnerabilities...

Found 1 lock file(s) with vulnerable React packages:

package-lock.json
react-server-dom-webpack: 19.0.0 -> 19.0.2 [CVE-2025-66478, CVE-2025-55184, CVE-2025-55183]
react-dom: 19.1.0 -> 19.1.3 [CVE-2025-55184, CVE-2025-55183]

πŸ’‘ To fix lock file issues, update your package.json versions and run your package manager's install command.## πŸ—οΈ Implementation Details

New Module: lib/utils/lockfile-scanner.js

module.exports = {
scanLockfile(dir), // Scan directory for lock files
analyzeLockfile(data), // Analyze parsed lock file
findAndScanLockfiles(dir), // Recursively scan all lock files
checkPackageVulnerability(), // Check package against CVEs
REACT_PACKAGES // List of packages to scan
};### Integration Points

  • Add --scan-lockfiles / --lockfiles CLI flag
  • Integrate with existing vulnerability checking in lib/index.js
  • Add lock file results to JSON output
  • Display results in CLI output

Lock File Parsers

Each parser will handle its specific format:

  1. npm (package-lock.json):

    • Parse v1, v2, v3 lockfile formats
    • Extract from packages and dependencies sections
  2. yarn (yarn.lock):

    • Parse yarn v1 format
    • Handle quoted/unquoted package names
    • Extract version from declarations
  3. pnpm (pnpm-lock.yaml):

    • Parse YAML format
    • Extract from packages section
    • Handle pnpm's package path format
  4. bun (bun.lockb):

    • Binary format - limited direct support
    • Fallback to package manager detection

✨ Features

  1. Multi-format Support: Parse all major lock file formats
  2. CVE Integration: Check against all 4 existing CVEs
  3. Deduplication: Handle duplicate packages intelligently
  4. Monorepo Support: Scan lock files across all packages
  5. JSON Output: Include results in --json output for CI/CD
  6. Performance: Fast scanning with single-pass parsing

πŸ“Š Benefits

βœ… More Comprehensive: Detects vulnerabilities in entire dependency tree
βœ… Better Coverage: Finds issues that package.json scanning misses
βœ… All Package Managers: Works with npm, yarn, pnpm, bun
βœ… Monorepo-Aware: Scans all lock files in monorepos
βœ… CI/CD Ready: JSON output for automation
βœ… Backward Compatible: Opt-in feature, no breaking changes

πŸ“ Usage Examples

Basic lock file scanning

npx fix-react2shell-next --scan-lockfiles### With JSON output for CI/CD
npx fix-react2shell-next --scan-lockfiles --json > report.json### Combined with dry-run
npx fix-react2shell-next --scan-lockfiles --dry-run### Combined with fix
npx fix-react2shell-next --fix --scan-lockfiles## πŸ§ͺ Testing Requirements

  • Unit tests for each lock file parser
  • Integration tests with CVE modules
  • Edge case handling (malformed files, empty files)
  • Deduplication tests
  • Monorepo scenarios
  • All package managers

Test Coverage Goals

// test/lockfile-scanner.test.js
describe('Lock File Scanner', () => {
describe('scanLockfile', () => {
it('should detect npm package-lock.json');
it('should detect yarn.lock');
it('should detect pnpm-lock.yaml');
it('should return null when no lockfile exists');
});

describe('checkPackageVulnerability', () => {
it('should detect vulnerable React 19.0.0');
it('should not flag patched versions');
it('should return patched version recommendations');
});

describe('analyzeLockfile', () => {
it('should analyze lockfile and find vulnerabilities');
it('should deduplicate packages');
it('should include CVE IDs and severity');
});
});## πŸ“š Documentation Updates

  • Update README.md with new flag documentation
  • Add usage examples
  • Document lock file format support
  • Update CLI help text
  • Add section to "What it does"

README Changes

What it does

  1. Recursively scans all package.json files (handles monorepos)
  2. Scans lock files for vulnerable React packages (optional, use --scan-lockfiles)
  3. Checks for vulnerable versions of Next.js and React RSC packages
  4. Patches to the correct fixed version based on your current version
  5. Refreshes your lockfile with the detected package manager## πŸ”„ Backward Compatibility

This is a new opt-in feature:

βœ… No breaking changes
βœ… All existing functionality preserved
βœ… New flag is optional
βœ… Existing tests continue to pass
βœ… Same output format (unless using new flag)

πŸ”— Related

CVEs Addressed:

Related Files:

  • lib/vulnerabilities/index.js - CVE registry
  • lib/index.js - Main CLI logic
  • lib/utils/package-manager.js - Package manager detection

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions