Snyk APIを使って脆弱性を検出・修正する
Josh Emerson
2018年1月3日
5 分で読めます
イラスト:Lou Reade
この
以下の
アクセス可能な
組織の 一覧を 取得する 組織に
属する すべての プロジェクトを 取得する プロジェクトの
問題 一覧を 取得する
前提条件
Snyk APIは、有料プランを
まだsnyk monitorを
また、https://snyk.io/accountから
組織の取得
最初に、
curl --include \
--header "Content-Type: application/json; charset=utf-8" \
--header "Authorization: token <API_KEY>" \
'https://snyk.io/api/v1/orgs'組織の
{
"orgs": [
{
"name": "defaultOrg",
"id": "689ce7f9-7943-4a71-b704-2ba575f01089"
},
{
"name": "My Other Org",
"id": "a04d9cbd-ae6e-44af-b573-0556b0ad4bd2"
}
]
}プロジェクトの取得
次に、
curl --include \
--header "Content-Type: application/json" \
--header "Authorization: token <API_KEY>" \
'https://snyk.io/api/v1/org/<ORG_ID>/projects'プロジェクトの
{
"org": {
"name": "defaultOrg",
"id": "689ce7f9-7943-4a71-b704-2ba575f01089"
},
"projects": [
{
"name": "atokeneduser/goof",
"id": "6d5813be-7e6d-4ab8-80c2-1e3e2a454545"
},
{
"name": "atokeneduser/clojure",
"id": "af127b96-6966-46c1-826b-2e79ac49bbd9"
}
]
}プロジェクトの問題を取得する
プロジェクトの
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: token <API_KEY>" \
'https://snyk.io/api/v1/org/orgId/project/<PROJECT_ID>/aggregated-issues'脆弱性の
プロジェクトの
'https://snyk.io/api/v1/org/orgId/project/<PROJECT_ID>/aggregated-issues'curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: token <API_KEY>" \
--data-binary '{
"filters": {
"severities": [ "high" ],
"types": [ "vuln" ],
"ignored": false,
"patched": false
}
}' \
'https://snyk.io/api/v1/org/orgId/project/<PROJECT_ID>/aggregated-issues'この
レスポンスの活用
プロジェクトの
{
"ok": false,
"issues": {
"vulnerabilities": [
{
"id": "npm:ms:20170412",
"url": "https://snyk.io/vuln/npm:ms:20170412",
"title": "Regular Expression Denial of Service (ReDoS)",
"type": "vuln",
"description": "## Overview\n[`ms`](https://www.npmjs.com/package/ms) is a tiny millisecond conversion utility.\n\nAffected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to an incomplete fix for previously reported vulnerability [npm:ms:20151024](https://snyk.io/vuln/npm:ms:20151024). The fix limited the length of accepted input string to 10,000 characters, and turned to be insufficient making it possible to block the event loop for 0.3 seconds (on a typical laptop) with a specially crafted string passed to `ms()` function.\n\n*Proof of concept*\n```js\nms = require('ms');\nms('1'.repeat(9998) + 'Q') // Takes about ~0.3s\n```\n\n**Note:** Snyk's patch for this vulnerability limits input length to 100 characters. This new limit was deemed to be a breaking change by the author.\nBased on user feedback, we believe the risk of breakage is _very_ low, while the value to your security is much greater, and therefore opted to still capture this change in a patch for earlier versions as well. Whenever patching security issues, we always suggest to run tests on your code to validate that nothing has been broken.\n\nFor more information on `Regular Expression Denial of Service (ReDoS)` attacks, go to our [blog](https://snyk.io/blog/redos-and-catastrophic-backtracking/).\n\n## Disclosure Timeline\n- Feb 9th, 2017 - Reported the issue to package owner.\n- Feb 11th, 2017 - Issue acknowledged by package owner.\n- April 12th, 2017 - Fix PR opened by Snyk Security Team.\n- May 15th, 2017 - Vulnerability published.\n- May 16th, 2017 - Issue fixed and version `2.0.0` released.\n- May 21th, 2017 - Patches released for versions `>=0.7.1, <=1.0.0`.\n\n## Remediation\nUpgrade `ms` to version 2.0.0 or higher.\n\n## References\n- [GitHub PR](https://github.com/zeit/ms/pull/89)\n- [GitHub Commit](https://github.com/zeit/ms/pull/89/commits/305f2ddcd4eff7cc7c518aca6bb2b2d2daad8fef)\n",
"from": [
"mongoose@4.2.4",
"mquery@1.6.3",
"debug@2.2.0",
"ms@0.7.1"
],
"package": "ms",
"version": "0.7.1",
"severity": "low",
"language": "js",
"packageManager": "npm",
"semver": {
"unaffected": ">=2.0.0",
"vulnerable": "<2.0.0"
},
"publicationTime": "2017-05-15T06:02:45.497Z",
"disclosureTime": "2017-04-11T21:00:00.000Z",
"isUpgradable": true,
"isPatchable": true,
"identifiers": {
"CVE": [],
"CWE": [
"CWE-400"
],
"ALTERNATIVE": [
"SNYK-JS-MS-10509"
]
},
"credit": [
"Snyk Security Research Team"
],
"CVSSv3": "CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L",
"cvssScore": 3.7,
"patches": [
{
"id": "patch:npm:ms:20170412:0",
"urls": [
"https://s3.amazonaws.com/snyk-rules-pre-repository/snapshots/develop/patches/npm/ms/20170412/ms_100.patch"
],
"version": "=1.0.0",
"comments": [],
"modificationTime": "2017-05-16T10:12:18.990Z"
},
{
"id": "patch:npm:ms:20170412:1",
"urls": [
"https://s3.amazonaws.com/snyk-rules-pre-repository/snapshots/develop/patches/npm/ms/20170412/ms_072-073.patch"
],
"version": "=0.7.2 || =0.7.3",
"comments": [],
"modificationTime": "2017-05-16T10:12:18.990Z"
},
{
"id": "patch:npm:ms:20170412:2",
"urls": [
"https://s3.amazonaws.com/snyk-rules-pre-repository/snapshots/develop/patches/npm/ms/20170412/ms_071.patch"
],
"version": "=0.7.1",
"comments": [],
"modificationTime": "2017-05-16T10:12:18.990Z"
}
],
"isIgnored": true,
"isPatched": false,
"upgradePath": [
"mongoose@4.10.2",
"mquery@2.3.1",
"debug@2.6.8",
"ms@2.0.0"
]
}
],
"licenses": []
},
"dependencyCount": 250,
"packageManager": "npm"
}脆弱性の
curl --request POST \
--header "Content-Type: application/json" \
--header "Authorization: token <API_KEY>" \
'https://snyk.io/api/v1/org/orgId/project/<PROJECT_ID>/issues' \
| jq '"Vulnerability: \(.issues.vulnerabilities[].title) in \(.issues.vulnerabilities[].package)@\(.issues.vulnerabilities[].version) - \(.issues.vulnerabilities[].url)"'次のような
Regular Expression Denial of Service (ReDoS) in ms@0.7.1 - https://snyk.io/vuln/npm:ms:20170412Reporting API
次回の


