| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8b02485 commit 373304b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,19 +6,29 @@ in Node's dependencies. | |||
| 6 | 6 | ||
| 7 | 7 | ## How to use | |
| 8 | 8 | ||
| 9 | - In order to query the GitHub Advisory Database, | ||
| 10 | - a [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) | ||
| 11 | - has to be created (no permissions need to be given to the token, since it's only used to query the public database). | ||
| 9 | + ### Database authentication | ||
| 10 | + | ||
| 11 | + - In order to query the GitHub Advisory Database, | ||
| 12 | + a [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) | ||
| 13 | + has to be created (no permissions need to be given to the token, since it's only used to query the public database). | ||
| 14 | + - The NVD can be queried without authentication, but it will be rate limited to one query every six seconds. In order to | ||
| 15 | + remove | ||
| 16 | + that limitation [request an API key](https://nvd.nist.gov/developers/request-an-api-key) and pass it as a parameter. | ||
| 17 | + | ||
| 18 | + ### Running the script | ||
| 19 | + | ||
| 12 | 20 | Once acquired, the script can be run as follows: | |
| 13 | 21 | ||
| 14 | 22 | ```shell | |
| 15 | 23 | cd node/tools/dep_checker/ | |
| 16 | 24 | pip install -r requirements.txt | |
| 17 | 25 | ||
| 18 | 26 | # Python >= 3.9 required | |
| 19 | - python main.py --gh-token=$PERSONAL_ACCESS_TOKEN | ||
| 27 | + python main.py --gh-token=$PERSONAL_ACCESS_TOKEN --nvd-key=$NVD_API_KEY | ||
| 20 | 28 | ||
| 21 | - # or to skip querying the GitHub Advisory Database, simply run: | ||
| 29 | + # The command can also be run without parameters | ||
| 30 | + # This will skip querying the GitHub Advisory Database, and query the NVD | ||
| 31 | + # using the anonymous (rate-limited) API | ||
| 22 | 32 | python main.py | |
| 23 | 33 | ``` | |
| 24 | 34 | ||
@@ -51,8 +61,8 @@ non-affected version. | |||
| 51 | 61 | - The queries can return false positives ( | |
| 52 | 62 | see [this](https://github.com/nodejs/security-wg/issues/802#issuecomment-1144207417) comment for an example). These | |
| 53 | 63 | can be ignored by adding the vulnerability to the `ignore_list` in `dependencies.py` | |
| 54 | - - The script takes a while to finish (~2 min) because queries to the NVD | ||
| 55 | - are [rate-limited](https://nvd.nist.gov/developers) | ||
| 64 | + - If no NVD API key is provided, the script will take a while to finish (~2 min) because queries to the NVD | ||
| 65 | + are [rate-limited](https://nvd.nist.gov/developers/start-here) | ||
| 56 | 66 | - If any vulnerabilities are found, the script returns 1 and prints out a list with the ID and a link to a description | |
| 57 | 67 | of | |
| 58 | 68 | the vulnerability. This is the case except when the ID matches one in the ignore-list (inside `dependencies.py`) in | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ | |||
| 18 | 18 | from gql.transport.aiohttp import AIOHTTPTransport | |
| 19 | 19 | from nvdlib import searchCVE # type: ignore | |
| 20 | 20 | from packaging.specifiers import SpecifierSet | |
| 21 | + from typing import Optional | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | class Vulnerability: | |
@@ -105,7 +106,7 @@ def query_ghad(gh_token: str) -> dict[str, list[Vulnerability]]: | |||
| 105 | 106 | return found_vulnerabilities | |
| 106 | 107 | ||
| 107 | 108 | ||
| 108 | - def query_nvd() -> dict[str, list[Vulnerability]]: | ||
| 109 | + def query_nvd(api_key: Optional[str]) -> dict[str, list[Vulnerability]]: | ||
| 109 | 110 | """Queries the National Vulnerability Database for vulnerabilities reported for Node's dependencies. | |
| 110 | 111 | ||
| 111 | 112 | The database supports querying by CPE (Common Platform Enumeration) or by a keyword present in the CVE's | |
@@ -121,7 +122,9 @@ def query_nvd() -> dict[str, list[Vulnerability]]: | |||
| 121 | 122 | for name, dep in deps_in_nvd.items(): | |
| 122 | 123 | query_results = [ | |
| 123 | 124 | cve | |
| 124 | - for cve in searchCVE(cpeMatchString=dep.get_cpe(), keyword=dep.keyword) | ||
| 125 | + for cve in searchCVE( | ||
| 126 | + cpeMatchString=dep.get_cpe(), keyword=dep.keyword, key=api_key | ||
| 127 | + ) | ||
| 125 | 128 | if cve.id not in ignore_list | |
| 126 | 129 | ] | |
| 127 | 130 | if query_results: | |
@@ -140,15 +143,24 @@ def main(): | |||
| 140 | 143 | "--gh-token", | |
| 141 | 144 | help="the GitHub authentication token for querying the GH Advisory Database", | |
| 142 | 145 | ) | |
| 146 | + parser.add_argument( | ||
| 147 | + "--nvd-key", | ||
| 148 | + help="the NVD API key for querying the National Vulnerability Database", | ||
| 149 | + ) | ||
| 143 | 150 | gh_token = parser.parse_args().gh_token | |
| 151 | + nvd_key = parser.parse_args().nvd_key | ||
| 144 | 152 | if gh_token is None: | |
| 145 | 153 | print( | |
| 146 | 154 | "Warning: GitHub authentication token not provided, skipping GitHub Advisory Database queries" | |
| 147 | 155 | ) | |
| 156 | + if nvd_key is None: | ||
| 157 | + print( | ||
| 158 | + "Warning: NVD API key not provided, queries will be slower due to rate limiting" | ||
| 159 | + ) | ||
| 148 | 160 | ghad_vulnerabilities: dict[str, list[Vulnerability]] = ( | |
| 149 | 161 | {} if gh_token is None else query_ghad(gh_token) | |
| 150 | 162 | ) | |
| 151 | - nvd_vulnerabilities = query_nvd() | ||
| 163 | + nvd_vulnerabilities: dict[str, list[Vulnerability]] = query_nvd(nvd_key) | ||
| 152 | 164 | ||
| 153 | 165 | if not ghad_vulnerabilities and not nvd_vulnerabilities: | |
| 154 | 166 | print(f"No new vulnerabilities found ({len(ignore_list)} ignored)") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,3 @@ | |||
| 1 | 1 | gql[aiohttp] | |
| 2 | - nvdlib | ||
| 2 | + nvdlib==0.5.8 | ||
| 3 | 3 | packaging | |
| Back | FazBrowse Home | New Git URL |
0 commit comments