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

fix(worker/repository): add normalized match for pip alertPackageRules #28214

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/workers/repository/init/vulnerability.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,41 @@ describe('workers/repository/init/vulnerability', () => {
expect(res.packageRules).toHaveLength(1);
});

it('returns pip alerts with normalized name', async () => {
// TODO #22198
delete config.vulnerabilityAlerts!.enabled;
platform.getVulnerabilityAlerts.mockResolvedValue([
{
dismissReason: null,
vulnerableManifestFilename: 'requirements.txt',
vulnerableManifestPath: 'requirements.txt',
vulnerableRequirements: '= 1.6.7',
securityAdvisory: {
description: 'Description',
identifiers: [
{ type: 'GHSA', value: 'GHSA-m956-frf4-m2wr' },
{ type: 'CVE', value: 'CVE-2016-2137' },
],
references: [
{ url: 'https://nvd.nist.gov/vuln/detail/CVE-2016-9587' },
],
severity: 'MODERATE',
},
securityVulnerability: {
package: { name: 'Pillow', ecosystem: 'PIP' },
firstPatchedVersion: { identifier: '2.1.4' },
vulnerableVersionRange: '< 2.1.4',
},
},
]);
const res = await detectVulnerabilityAlerts(config);
expect(res.packageRules).toHaveLength(1);
expect(res.packageRules![0].matchPackageNames).toEqual([
'Pillow',
'pillow',
]);
});

it('returns remediations', async () => {
config.transitiveRemediation = true;
// TODO #22198
Expand Down
7 changes: 7 additions & 0 deletions lib/workers/repository/init/vulnerability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NpmDatasource } from '../../../modules/datasource/npm';
import { NugetDatasource } from '../../../modules/datasource/nuget';
import { PackagistDatasource } from '../../../modules/datasource/packagist';
import { PypiDatasource } from '../../../modules/datasource/pypi';
import { normalizeDepName } from '../../../modules/datasource/pypi/common';
import { RubyGemsDatasource } from '../../../modules/datasource/rubygems';
import { platform } from '../../../modules/platform';
import * as allVersioning from '../../../modules/versioning';
Expand Down Expand Up @@ -218,6 +219,12 @@ export async function detectVulnerabilityAlerts(
matchCurrentVersion,
matchFileNames,
};
if (
datasource === PypiDatasource.id &&
normalizeDepName(depName) !== depName
) {
matchRule.matchPackageNames?.push(normalizeDepName(depName));
}
const supportedRemediationFileTypes = ['package-lock.json'];
if (
config.transitiveRemediation &&
Expand Down
Loading