Fix case-sensitive dependency matching for Python security updates#13439
Fix case-sensitive dependency matching for Python security updates#13439Copilot wants to merge 5 commits into
Conversation
Make allowed_dependencies use case-insensitive matching when filtering dependencies for security updates, consistent with job_dependencies. This fixes an issue where Python dependencies with normalized lowercase names (e.g., "jinja2") were not matching security advisories that use canonical casing (e.g., "Jinja2"), causing them to be excluded from security update PRs. Co-authored-by: AbhishekBhaskar <22154418+AbhishekBhaskar@users.noreply.github.com>
Use Set instead of Array for job_dependency_names to improve lookup performance from O(n) to O(1) in both allowed_dependencies and job_dependencies methods. Co-authored-by: AbhishekBhaskar <22154418+AbhishekBhaskar@users.noreply.github.com>
|
@copilot I'm getting some lint errors in CI: Offenses: updater/lib/dependabot/dependency_snapshot.rb:5:1: W: [Correctable] Lint/RedundantRequireStatement: Remove unnecessary require statement. |
- Remove redundant 'require "set"' statement - Use to_set(&:downcase) instead of map(&:downcase).to_set Co-authored-by: AbhishekBhaskar <22154418+AbhishekBhaskar@users.noreply.github.com>
|
@copilot Two smoke tests are failing with the message: |
Could you share which specific smoke tests are failing? The change intentionally makes dependency name matching case-insensitive for security updates to fix the reported issue where Python dependencies like "Jinja2" (from advisories) weren't matching "jinja2" (from manifests). If the smoke tests expect the old case-sensitive behavior, their expectations would need to be updated to reflect the correct behavior. |
|
@copilot The following smoke tests are failing:
|
Only apply case-insensitive dependency name matching for ecosystems that actually have case-insensitive package names (Python, Gradle, Maven, Nuget). For case-sensitive ecosystems like Bundler, maintain exact name matching. This fixes the smoke test failures for bundler while keeping the fix for Python dependency matching. Co-authored-by: AbhishekBhaskar <22154418+AbhishekBhaskar@users.noreply.github.com>
Fixed in d59b676. The issue was that case-insensitive matching was being applied to all ecosystems, including Bundler which has case-sensitive gem names. Now the fix only applies to ecosystems with case-insensitive package names (Python/pip, Gradle, Maven, Nuget). Bundler and other case-sensitive ecosystems use exact name matching. |
Fix Python Dependency Name Casing Issue ✅
allowed_dependenciesmethodChanges Made
Fixed
allowed_dependenciesmethod in/updater/lib/dependabot/dependency_snapshot.rb:.include?(d.name)to case-insensitive matching using.downcasejob_dependenciesmethod which has the same logicPerformance optimization:
job_dependency_namesto Set for O(1) lookup instead of O(n) usingto_set(&:downcase)allowed_dependenciesandjob_dependenciesmethodsCode quality:
require "set"statement (Set is automatically loaded in Ruby)to_set(&:downcase)instead ofmap(&:downcase).to_setper RuboCop style guidecase_insensitive_package_manager?to determine which ecosystems need case-insensitive matchingAdded test case in
/updater/spec/dependabot/dependency_snapshot_spec.rb:Root Cause
Security advisories use canonical package names (e.g., "Jinja2"), while Python's name normalizer converts all dependency names to lowercase (e.g., "jinja2"). The
allowed_dependenciesmethod was using case-sensitive matching which caused mismatches and excluded valid dependencies from security updates.Testing
Impact
This fix ensures that Python dependencies (and other case-insensitive ecosystems) are correctly included in security update PRs when their names differ in casing between security advisories and manifest files. Case-sensitive ecosystems like Bundler continue to use exact name matching to avoid false positives.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.