Skip to content

Update Apache_httpd importer from XML to JSON Advisory#425

Merged
sbs2001 merged 18 commits intoaboutcode-org:mainfrom
AmitGupta7580:update-apache-httpd-importer
May 8, 2021
Merged

Update Apache_httpd importer from XML to JSON Advisory#425
sbs2001 merged 18 commits intoaboutcode-org:mainfrom
AmitGupta7580:update-apache-httpd-importer

Conversation

@AmitGupta7580
Copy link
Contributor

@AmitGupta7580 AmitGupta7580 commented Apr 4, 2021

Resolve #423

Tasks :

  • Fetch data into JSON format.
  • Differentiate impacted and resolved packages.
  • Add severity of vulnerability.
  • Create Test Case class for Apache_httpd importer.

Copy link
Collaborator

@sbs2001 sbs2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to be merged with minor changes I suggested

def to_advisory(self, data):
cve = data["CVE_data_meta"]["ID"]
description = data["description"]["description_data"]
summary = next((item["value"] for item in description if item["lang"] == "eng"), "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using next here is a little cryptic. Would there be a more readable and explicit way to do this?
I reckon that description has this shape (and are you sure this is always present?):

  "description": {
    "description_data": [
      {
        "lang": "eng",
        "value": "For configurations using proxying...."
      }
    ]
  }

so what about this?

descriptions = data.get("description", {}).get("description_data", [])
description = None
for desc in descriptions:
    if desc.get("lang") == "eng":
        description = desc.get("value")
        break

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description is always present, @AmitGupta7580 checked it.

Signed-off-by: AmitGupta7580 <amitgupta758000@gmail.com>
Copy link
Collaborator

@sbs2001 sbs2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this needs to rebased and refactored according to new model (which would 1-2 line changes IMHO) See the new importer now for reference

@AmitGupta7580
Copy link
Contributor Author

image

Done 👍

@AmitGupta7580 AmitGupta7580 requested a review from sbs2001 April 22, 2021 16:00
…versions of Apache-httpd from Github API

Signed-off-by: AmitGupta7580 <amitgupta758000@gmail.com>
@AmitGupta7580 AmitGupta7580 requested a review from sbs2001 April 26, 2021 05:53
Copy link
Collaborator

@sbs2001 sbs2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmitGupta7580 thanks, this looks good with minor changes.


def to_advisory(self, data):
cve = data["CVE_data_meta"]["ID"]
descriptions = data.get("description", {}).get("description_data", [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, does this cascade all the way down. Could you point me to an example where descriptions == [] .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, currently there is no example where descriptions == [].

I ran this code but got nothing.

descriptions = data.get("description", {}).get("description_data", [])
if len(descriptions) == 0:
    print("empty descriptions : {}".format(cve))
description = None
for desc in descriptions:
    if desc.get("lang") == "eng":
         description = desc.get("value")
    else:
         print("other language : {}".format(cve))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too defensive then, may mask issues, ideally we want to fail loudly.

Does descriptions = data["description"]["description_data"] work ? If yes then use that, otherwise try
descriptions = data["description"].get("description_data", [])

descriptions = data.get("description", {}).get("description_data", [])
description = None
for desc in descriptions:
if desc.get("lang") == "eng":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this condition not get satisifed, ie does desc.get("lang") == None happen ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that desc.get("lang") is never None ("lang" key is always present in desc) . If yes then use if desc["lang"] == "eng" : .....

for info in issue:
if info.tag == "cve":
cve = info.attrib["name"]
versions = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is misleading because really, it stores some version related data (which includes ranges and such).

Maybe rename this to version_data

)

return advisories
def to_version_ranges(self, versions):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@AmitGupta7580 AmitGupta7580 requested a review from sbs2001 April 28, 2021 17:08

def to_advisory(self, data):
cve = data["CVE_data_meta"]["ID"]
descriptions = data.get("description", {}).get("description_data", [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too defensive then, may mask issues, ideally we want to fail loudly.

Does descriptions = data["description"]["description_data"] work ? If yes then use that, otherwise try
descriptions = data["description"].get("description_data", [])

descriptions = data.get("description", {}).get("description_data", [])
description = None
for desc in descriptions:
if desc.get("lang") == "eng":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that desc.get("lang") is never None ("lang" key is always present in desc) . If yes then use if desc["lang"] == "eng" : .....

impacts = data.get("impact", [])
for impact in impacts:
value = impact.get("other")
if value is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if value: instead, they are the same but concise and easy to read.

@AmitGupta7580 AmitGupta7580 requested a review from sbs2001 April 29, 2021 18:52
if create_etag(data_src=self, url=self.url, etag_key="ETag"):
data = fetch_xml(self.url)
advisories = to_advisories(data)
if create_etag(data_src=self, url=self.base_url, etag_key="ETag"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't valid now because the provided endpoint doesn't provide etags in the headers. Remove this if statement and the emtpy list return below

Copy link
Collaborator

@sbs2001 sbs2001 May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the comments related to etags

Signed-off-by: AmitGupta7580 <amitgupta758000@gmail.com>
@AmitGupta7580 AmitGupta7580 requested a review from sbs2001 May 6, 2021 18:54
from vulnerabilities.data_source import VulnerabilitySeverity
from vulnerabilities.package_managers import GitHubTagsAPI
from vulnerabilities.severity_systems import scoring_systems
from vulnerabilities.helpers import create_etag
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit this isn't used anymore

@sbs2001
Copy link
Collaborator

sbs2001 commented May 8, 2021

@AmitGupta7580 I'm squashing the commits and merging it, consider squashing from your side next time .

@sbs2001 sbs2001 merged commit d7d3206 into aboutcode-org:main May 8, 2021
@AmitGupta7580 AmitGupta7580 deleted the update-apache-httpd-importer branch May 9, 2021 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Apache_httpd importer from XML to JSON Advisory

3 participants