-
-
Notifications
You must be signed in to change notification settings - Fork 328
Add unique CVE ID field to Vulnerability #125
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,15 +34,11 @@ def debian_dump(extract_data, base_release='jessie'): | |
| Save data scraped from Debian' security tracker. | ||
| """ | ||
| for data in extract_data: | ||
| vulnerability = Vulnerability.objects.create( | ||
| summary=data.get('description', ''), | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=data.get('vulnerability_id', ''), | ||
| vulnerability, _ = Vulnerability.objects.get_or_create( | ||
| cve_id=data['cve_id'], | ||
| ) | ||
|
|
||
| pkg_name = data.get('package_name', '') | ||
| pkg_name = data['package_name'] | ||
| package = Package.objects.create( | ||
| name=pkg_name, | ||
| type='deb', | ||
|
|
@@ -83,15 +79,11 @@ def ubuntu_dump(html): | |
| Dump data scraped from Ubuntu's security tracker. | ||
| """ | ||
| for data in html: | ||
| vulnerability = Vulnerability.objects.create( | ||
| summary='', | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=data.get('cve_id'), | ||
| vulnerability, _ = Vulnerability.objects.get_or_create( | ||
| cve_id=data['cve_id'], | ||
| ) | ||
| package = Package.objects.create( | ||
| name=data.get('package_name'), | ||
| name=data['package_name'], | ||
| type='deb', | ||
| namespace='ubuntu' | ||
| ) | ||
|
|
@@ -105,90 +97,96 @@ def archlinux_dump(extract_data): | |
| """ | ||
| Save data scraped from archlinux' security tracker. | ||
| """ | ||
| for item in extract_data: | ||
| cves = item['issues'] | ||
| group = item['name'] | ||
|
|
||
| advisories = set(item['advisories']) | ||
| vulnerabilities = cves + list(advisories) | ||
| vulnerabilities.append(group) | ||
| packages_name = item['packages'] | ||
|
|
||
| affected_version = item['affected'] | ||
| fixed_version = item['fixed'] | ||
| if not fixed_version: | ||
| fixed_version = 'None' | ||
|
|
||
| vulnerability = Vulnerability.objects.create( | ||
| summary=item['type'], | ||
| ) | ||
| base_url = 'https://security.archlinux.org' | ||
|
|
||
| for vulnerability_id in vulnerabilities: | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=vulnerability_id, | ||
| url=f'https://security.archlinux.org/{vulnerability_id}', | ||
| ) | ||
| for avg in extract_data: | ||
| affected_packages = [] | ||
| fixed_packages = [] | ||
|
|
||
| for package_name in packages_name: | ||
| package_affected = Package.objects.create( | ||
| for package_name in avg['packages']: | ||
| ap, _ = Package.objects.get_or_create( | ||
| name=package_name, | ||
| type='pacman', | ||
| namespace='archlinux', | ||
| version=affected_version | ||
| ) | ||
| ImpactedPackage.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_affected | ||
| ) | ||
| PackageReference.objects.create( | ||
| package=package_affected, | ||
| repository=f'https://security.archlinux.org/package/{package_name}', | ||
| version=avg['affected'], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is affected always a single version?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a string in all the records I looked at so I'm pretty sure, but haven't tried to verify it any further. In general I think it's not really a problem if the import crashes due to unexpected schemas. In fact, I'd argue we want it to crash as soon as possible instead of writing lots of empty values into the database due to overly defensive code. |
||
| ) | ||
| package_fixed = Package.objects.create( | ||
| affected_packages.append(ap) | ||
|
|
||
| fp, _ = Package.objects.get_or_create( | ||
| name=package_name, | ||
| type='pacman', | ||
| namespace='archlinux', | ||
| version=fixed_version | ||
| version=avg['fixed'], | ||
| ) | ||
| ResolvedPackage.objects.create( | ||
| fixed_packages.append(fp) | ||
|
|
||
| for cve_id in avg['issues']: | ||
| vulnerability, _ = Vulnerability.objects.get_or_create( | ||
| cve_id=cve_id, | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_fixed | ||
| url=f'{base_url}/{cve_id}', | ||
| ) | ||
| PackageReference.objects.create( | ||
| package=package_fixed, | ||
| repository=f'https://security.archlinux.org/package/{package_name}', | ||
| avg_name = avg['name'] | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=avg_name, | ||
| url=f'{base_url}/{avg_name}', | ||
| ) | ||
|
|
||
| for asa in avg['advisories']: | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=asa, | ||
| url=f'{base_url}/{asa}', | ||
| ) | ||
|
|
||
| for ap in affected_packages: | ||
| ImpactedPackage.objects.get_or_create( | ||
| vulnerability=vulnerability, | ||
| package=ap, | ||
| ) | ||
|
|
||
| for fp in fixed_packages: | ||
| ResolvedPackage.objects.get_or_create( | ||
| vulnerability=vulnerability, | ||
| package=fp, | ||
| ) | ||
|
|
||
|
|
||
| def npm_dump(extract_data): | ||
| for data in extract_data: | ||
| vulnerability = Vulnerability.objects.create( | ||
| summary=data.get('summary'), | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=data.get('vulnerability_id'), | ||
| ) | ||
| package_name = data['package_name'] | ||
| advisory = data['advisory'] | ||
|
|
||
| affected_versions = data.get('affected_version', []) | ||
| for version in affected_versions: | ||
| package_affected = Package.objects.create( | ||
| name=data.get('package_name'), | ||
| version=version, | ||
| ) | ||
| ImpactedPackage.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_affected | ||
| for cve_id in data['cve_ids']: | ||
| vulnerability, _ = Vulnerability.objects.get_or_create( | ||
| cve_id=cve_id, | ||
| ) | ||
|
|
||
| fixed_versions = data.get('fixed_version', []) | ||
| for version in fixed_versions: | ||
| package_fixed = Package.objects.create( | ||
| name=data.get('package_name'), | ||
| version=version | ||
| ) | ||
| ResolvedPackage.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_fixed | ||
| ) | ||
| if advisory: | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| url=advisory, | ||
| ) | ||
|
|
||
| for version in data['affected_versions']: | ||
| package_affected = Package.objects.create( | ||
| name=package_name, | ||
| version=version, | ||
| ) | ||
| ImpactedPackage.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_affected | ||
| ) | ||
|
|
||
| for version in data['fixed_versions']: | ||
| package_fixed = Package.objects.create( | ||
| name=package_name, | ||
| version=version | ||
| ) | ||
| ResolvedPackage.objects.create( | ||
| vulnerability=vulnerability, | ||
| package=package_fixed | ||
| ) | ||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is no cve_id in the data? will this crash? And in this case we would likely still want to create a new Vulnerability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the Debian import, where it doesn't look like there will be any entries without CVE ID. At least not in the feed we are currently consuming. The CVE ID is used as a dictionary key: