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

implement nodejs fetcher #175

Closed
wants to merge 4 commits into from
Closed

implement nodejs fetcher #175

wants to merge 4 commits into from

Conversation

liangchenye
Copy link
Contributor

@liangchenye liangchenye commented May 16, 2016

Implement nodejs fetcher by parsing api.nodesecurity.io/advisories.
Cache the last 'updated_at' time of advisories to send a valid 'update' notification.
(#40)

One problem is: there might be more than one fixed/affected package versions in a nodejs advisory.
For example: https://nodesecurity.io/advisories/77

Vulnerable: < 3.1.3 || >= 4.0.0 <4.1.1
Patched: >=3.1.3 < 4.0.0 || >=4.1.1

The current Feature seems not be able to handle this.

Signed-off-by: liang chenye liangchenye@huawei.com

@liangchenye liangchenye changed the title [WIP] implement nodejs fetcher implement nodejs fetcher May 17, 2016
@liangchenye
Copy link
Contributor Author

liangchenye commented May 17, 2016

The implementation does the following things:

  1. using data from api.nodesecurity.io/advisories
  2. drop advisory which doesn't have CVE fields
  3. convert cvss score to priority (https://www.first.org/cvss/specification-document)
  4. add node_version just as my previous comment
    Now I pick up the max fixed version. If we want to solve it throughly, we need to change the comparing logic (https://github.com/coreos/clair/blob/master/database/pgsql/feature.go#L218).
  5. add fetcher_node_test.json which is a part of api.nodesecurity.io/advisories
    It has 5 advisories. One of them has no CVE, two of them share a same CVE, one of them has complicate 'version' and the remain one is 'normal'. I think they are representative.

@jzelinskie @Quentin-M PTAL

@jzelinskie jzelinskie added kind/feature request wishes for new functionality/docs lacking/review needs to be reviewed by a maintainer component/fetcher labels May 17, 2016
if err != nil {
log.Errorf("could not download Node's update: %s", err)
return resp, cerrors.ErrCouldNotDownload
}
Copy link
Contributor

Choose a reason for hiding this comment

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

defer r.Body.Close()

@jzelinskie jzelinskie added reviewed/needs rework will be closed if review not addressed and removed lacking/review needs to be reviewed by a maintainer labels May 17, 2016
@liangchenye
Copy link
Contributor Author

liangchenye commented May 18, 2016

Thanks @jzelinskie for the review, commit 'e0a450d' fixes all the issues mentioned in your comment.

The commit 'e4b50f1' fixes a similar 'io reader close' issue in other fetchers.

@jzelinskie jzelinskie added lacking/review needs to be reviewed by a maintainer and removed reviewed/needs rework will be closed if review not addressed labels May 18, 2016

const (
url = "https://api.nodesecurity.io/advisories"
cveURLPrefix = "http://cve.mitre.org/cgi-bin/cvename.cgi?name="
Copy link
Contributor

Choose a reason for hiding this comment

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

Could/Should we give a link back to nodesecurity.io?

Copy link
Contributor

Choose a reason for hiding this comment

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

Especially if we could see the specific version ranges then!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use 'cve.mitres.org' because one CVE may links to multiple advisories.

@Quentin-M Quentin-M removed the lacking/review needs to be reviewed by a maintainer label Jun 15, 2016
@liangchenye
Copy link
Contributor Author

ping @jzelinskie

cveURLPrefix = "http://cve.mitre.org/cgi-bin/cvename.cgi?name="
updaterFlag = "nodejsUpdater"
defaultNodejsVersion = "all"
//FIXME: Add a suffix when an advisory is fixed `after` a certain version.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this still need to be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the 'FIXME'. I added 'FIXME' just to remind it needs a better way to check if a package is vulnerable.

In current fetchers, if a package's version is recorded as '1.0.1', it means the security issue will be fixed when the package version '>=' 1.0.1. But in nodejs, it is more complicated. Sometimes, it should '>=' 1.0.1, sometimes it should '>' 1.0.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

ovs := getOperVersions(version)
for _, ov := range ovs {
if ov.Oper == ">" {
if curVersion, err := types.NewVersion(ov.Version + defaultVersionSuffix); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how I feel about this. If we invent this version and people query the API, won't the FixedIn package always be $version-1, which isn't a real package, but one we made up? That's pretty confusing for end users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a thorough solution is changing the current 'version' from types.NewVersion to a full description string like ">=2.5.0 <= 3.0.0 || >=3.1.0". It could solve both this issue and false-positive issue.

It may not necessary to System package managers, but useful for 'Application updaters' and 'Library package managers'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a type 'fixedInVersions' to FeatureVersion. WIP

Signed-off-by: liang chenye <liangchenye@huawei.com>
Signed-off-by: liang chenye <liangchenye@huawei.com>
Signed-off-by: liang chenye <liangchenye@huawei.com>
Signed-off-by: liang chenye <liangchenye@huawei.com>
@liangchenye
Copy link
Contributor Author

liangchenye commented Jul 12, 2016

The commit 'cb42892: add FixedInVersions to check affected packages' made the following changes:

  • add a FixedInVersions to FeatureVersion struct

    'Version' was used both as the detected package version and the patched version of fetched vulnerability. After this change, 'Version' will be used only as the detected package version.
    'FixedInVersions' is a more complicate but more user friendly patched version ( > 1.0 || <0.8 for example)

  • add a FixedInVersions struct to utils/types

    In order to be compatible with previous Clair, the default operation is '>=' if no operation was assigned.

  • reuse the 'version' key of the 'vulnerability_fixedIn_feature' table

    It is not changed to 'fixed_in_versions' because I don't want to add too many sql migration files. If it should be modified, I'll do it in support multiple namespaces in one layer #193.

@jzelinskie

@Quentin-M Quentin-M mentioned this pull request Jul 13, 2016
4 tasks
@guypod
Copy link

guypod commented Jul 25, 2016

If I may chime in here, WDYT about supporting Snyk with this integration?

Can use the open source VulnDB (https://github.com/snyk/vulndb) as a source.
Here's the auto-generated JSON feed that combines all the vulns: https://github.com/Snyk/vulndb/blob/snapshots/master/snapshot.json

Using Snyk will open up the possibility of supporting patches for the (frequent) case of vulnerabilities you can't upgrade away. More on that here: https://snyk.io/docs/security/#snyk-s-process-for-creating-patches

It's online, but can also consider using Snyk's API when finding issues, to get more detailed remediation advice.
For instance this API call: https://snyk.io/api/v1/vuln/github/snyk/goof
Will provide the details from this page: https://snyk.io/test/github/snyk/goof

Snyk's DB is AGPL licensed, which makes it fine for internal use. Either way, it's no more restrictive than Node Security's terms of use: https://nodesecurity.io/tos

@guypod
Copy link

guypod commented Jul 25, 2016

One more note - you pointed out you drop all the issues with no CVE.
In Snyk's DB (nsp is roughly the same), only about a third of the vulns have a CVE.
I'd strongly encourage not to drop those without a CVE, but rather use our IDs for them.

@Quentin-M Quentin-M added lacking/review needs to be reviewed by a maintainer and removed reviewed/lgtm labels Aug 5, 2016
@jzelinskie
Copy link
Contributor

@liangchenye what do you think about @guypod's proposal? We've discussed the topic a little bit with NodeSecurity and they aren't 100% clear on how they want their data to be licensed in scenarios like this.

@Quentin-M
Copy link
Contributor

Quentin-M commented Sep 7, 2016

Here what's nsp's attorney would like us to add to Clair's license if we were to use their database. tl;dr Use of Clair in a paid product would require a separate, paid licensing with nsp.

SEPARATE LICENSING NEEDED FOR COMMERCIAL USE: Clair is licensed under the [insert license], but leverages security advisories drawn from the Node Security Platform ("nsp") API. These advisories are licensed under a separate terms of service available here: https://nodesecurity.io/tos. By accessing the advisories through Clair you agree to be bound by these terms of service. nsp may only be used for your own personal or internal business purposes. You may not reproduce, duplicate, copy, sell, trade, lease, rent or provide to any other third-party (i) any data retrieved through the nsp, (ii) any report or analysis developed using nsp, (iii) use of nsp, or (iv) access to nsp. Separate licensing must be arranged for these commercial uses by contacting contact@nodesecurity.io.

@liangchenye
Copy link
Contributor Author

I never think of the license issue :( From my point of view, SnykDB is a better choose to be the 'default nodejs fetcher' in this case.

@jzelinskie I agree with 'not to drop non-CVE' vulns, it helps users to better understand their security status. We can add this to README.md to mention about it: Clair is not only a CVE scanner and ID might be a problem in the future if we keep adding different security types, maybe we can use 'snyk#123456'.

@liangchenye
Copy link
Contributor Author

@Quentin-M @jzelinskie is SnykDB OK for you, I'll change to that implementation.

Another question is do we plan to provide a document ('implementation.md' for example) to list third-party fetchers?

@johanneswuerbach
Copy link

Looks like the nsp licensing issue will soon be resolved upstream https://nodejs.org/en/blog/announcements/nodejs-security-project

@jzelinskie
Copy link
Contributor

This PR is very out of date. I'm going to close it.
The groundwork provided by #432 should enable both layers supporting multiple namespaces and version ranges. If work was to resume on nodejs vulnerability detection, it should be done through these new APIs.

@jzelinskie jzelinskie closed this Aug 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature request wishes for new functionality/docs lacking/review needs to be reviewed by a maintainer
Development

Successfully merging this pull request may close these issues.

None yet

6 participants