Skip to content

Commit

Permalink
Merge pull request #568 from snyk/feat/IDE-453_Extend-Oss-Issue-Data-…
Browse files Browse the repository at this point in the history
…with-annotations

feat: add json mapping
  • Loading branch information
bastiandoetsch authored Jul 10, 2024
2 parents dfa6e53 + 81fe2a4 commit 01e2db1
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 49 deletions.
69 changes: 43 additions & 26 deletions domain/snyk/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,49 @@ type MarkerPosition struct {
}

type OssIssueData struct {
Key string `json:"key"`
Title string `json:"title"`
Name string `json:"name"`
LineNumber int `json:"lineNumber"`
Identifiers Identifiers `jsom:"identifiers"`
Description string `json:"description"`
References []Reference `json:"references,omitempty"`
Version string `json:"version"`
License string `json:"license,omitempty"`
PackageManager string `json:"packageManager"`
PackageName string `json:"packageName"`
From []string `json:"from"`
FixedIn []string `json:"fixedIn,omitempty"`
UpgradePath []any `json:"upgradePath,omitempty"`
IsUpgradable bool `json:"isUpgradable,omitempty"`
CVSSv3 string `json:"CVSSv3,omitempty"`
CvssScore float64 `json:"cvssScore,omitempty"`
Exploit string `json:"exploit,omitempty"`
IsPatchable bool `json:"isPatchable"`
ProjectName string `json:"projectName"`
DisplayTargetFile string `json:"displayTargetFile"`
Language string `json:"language"`
Details string `json:"details"`
MatchingIssues []OssIssueData `json:"matchingIssues"`
Lesson string `json:"lesson,omitempty"`
Remediation string `json:"remediation"`
Key string `json:"key"`
Title string `json:"title"`
Name string `json:"name"`
LineNumber int `json:"lineNumber"`
Identifiers Identifiers `jsom:"identifiers"`
Description string `json:"description"`
References []Reference `json:"references,omitempty"`
Version string `json:"version"`
License string `json:"license,omitempty"`
PackageManager string `json:"packageManager"`
PackageName string `json:"packageName"`
From []string `json:"from"`
FixedIn []string `json:"fixedIn,omitempty"`
UpgradePath []any `json:"upgradePath,omitempty"`
IsUpgradable bool `json:"isUpgradable,omitempty"`
CVSSv3 string `json:"CVSSv3,omitempty"`
CvssScore float64 `json:"cvssScore,omitempty"`
Exploit string `json:"exploit,omitempty"`
IsPatchable bool `json:"isPatchable"`
ProjectName string `json:"projectName"`
DisplayTargetFile string `json:"displayTargetFile"`
Language string `json:"language"`
Details string `json:"details"`
MatchingIssues []OssIssueData `json:"matchingIssues"`
Lesson string `json:"lesson,omitempty"`
Remediation string `json:"remediation"`
AppliedPolicyRules AppliedPolicyRules `json:"appliedPolicyRules,omitempty"`
}

type SeverityChange struct {
OriginalSeverity string `json:"originalSeverity"`
NewSeverity string `json:"newSeverity"`
Reason string `json:"reason"`
}

type AppliedPolicyRules struct {
Annotation Annotation `json:"annotation,omitempty"`
SeverityChange SeverityChange `json:"severityChange,omitempty"`
}

type Annotation struct {
Value string `json:"value,omitempty"`
Reason string `json:"reason,omitempty"`
}

type Identifiers struct {
Expand Down
168 changes: 168 additions & 0 deletions infrastructure/oss/testdata/policyAnnotationsInputData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"id": "SNYK-JS-SEMVER-3247795",
"title": "Regular Expression Denial of Service (ReDoS)",
"CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H/E:P",
"credit": [
"Alessio Della Libera - Snyk Research Team"
],
"semver": {
"vulnerable": [
"<5.7.2",
">=6.0.0 <6.3.1",
">=7.0.0 <7.5.2"
]
},
"exploit": "Proof of Concept",
"fixedIn": [
"5.7.2",
"6.3.1",
"7.5.2"
],
"patches": [],
"insights": {
"triageAdvice": null
},
"language": "js",
"severity": "high",
"cvssScore": 7.5,
"functions": [],
"malicious": false,
"isDisputed": false,
"moduleName": "semver",
"references": [
{
"url": "https://github.com/npm/node-semver/commit/2f8fd41487acf380194579ecb6f8b1bbfe116be0",
"title": "GitHub Commit"
},
{
"url": "https://github.com/npm/node-semver/commit/717534ee353682f3bcf33e60a8af4292626d4441",
"title": "GitHub Commit"
},
{
"url": "https://github.com/npm/node-semver/commit/928e56d21150da0413a3333a3148b20e741a920c",
"title": "GitHub Commit"
},
{
"url": "https://github.com/npm/node-semver/pull/564",
"title": "GitHub PR"
},
{
"url": "https://github.com/npm/node-semver/blob/main/classes/range.js%23L97-L104",
"title": "Vulnerable Code"
},
{
"url": "https://github.com/npm/node-semver/blob/main/internal/re.js%23L138",
"title": "Vulnerable Code"
},
{
"url": "https://github.com/npm/node-semver/blob/main/internal/re.js%23L160",
"title": "Vulnerable Code"
}
],
"cvssDetails": [
{
"assigner": "NVD",
"severity": "high",
"cvssV3Vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"cvssV3BaseScore": 7.5,
"modificationTime": "2024-03-11T09:53:22.600372Z"
},
{
"assigner": "Red Hat",
"severity": "high",
"cvssV3Vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"cvssV3BaseScore": 7.5,
"modificationTime": "2024-03-11T09:54:01.668389Z"
}
],
"cvssSources": [
{
"type": "primary",
"vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H/E:P",
"assigner": "Snyk",
"severity": "high",
"baseScore": 7.5,
"cvssVersion": "3.1",
"modificationTime": "2024-03-06T14:06:32.773457Z"
},
{
"type": "secondary",
"vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"assigner": "NVD",
"severity": "high",
"baseScore": 7.5,
"cvssVersion": "3.1",
"modificationTime": "2024-03-11T09:53:22.600372Z"
},
{
"type": "secondary",
"vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"assigner": "Red Hat",
"severity": "high",
"baseScore": 7.5,
"cvssVersion": "3.1",
"modificationTime": "2024-03-11T09:54:01.668389Z"
}
],
"description": "## Overview\n[semver](https://github.com/npm/node-semver) is a semantic version parser used by npm.\n\nAffected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via the function `new Range`, when untrusted user data is provided as a range.\r\n\r\n\r\n## PoC\r\n\r\n```js\r\n\r\nconst semver = require('semver')\r\nconst lengths_2 = [2000, 4000, 8000, 16000, 32000, 64000, 128000]\r\n\r\nconsole.log(\"n[+] Valid range - Test payloads\")\r\nfor (let i = 0; i =1.2.3' + ' '.repeat(lengths_2[i]) + '<1.3.0';\r\nconst start = Date.now()\r\nsemver.validRange(value)\r\n// semver.minVersion(value)\r\n// semver.maxSatisfying([\"1.2.3\"], value)\r\n// semver.minSatisfying([\"1.2.3\"], value)\r\n// new semver.Range(value, {})\r\n\r\nconst end = Date.now();\r\nconsole.log('length=%d, time=%d ms', value.length, end - start);\r\n}\r\n```\n\n## Details\n\nDenial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.\n\nThe Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.\n\nLet’s take the following regular expression as an example:\n```js\nregex = /A(B|C+)+D/\n```\n\nThis regular expression accomplishes the following:\n- `A` The string must start with the letter 'A'\n- `(B|C+)+` The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the `+` matches one or more times). The `+` at the end of this section states that we can look for one or more matches of this section.\n- `D` Finally, we ensure this section of the string ends with a 'D'\n\nThe expression would match inputs such as `ABBD`, `ABCCCCD`, `ABCBCCCD` and `ACCCCCD`\n\nIt most cases, it doesn't take very long for a regex engine to find a match:\n\n```bash\n$ time node -e '/A(B|C+)+D/.test(\"ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD\")'\n0.04s user 0.01s system 95% cpu 0.052 total\n\n$ time node -e '/A(B|C+)+D/.test(\"ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX\")'\n1.79s user 0.02s system 99% cpu 1.812 total\n```\n\nThe entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.\n\nMost Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as _catastrophic backtracking_.\n\nLet's look at how our expression runs into this problem, using a shorter string: \"ACCCX\". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:\n1. CCC\n2. CC+C\n3. C+CC\n4. C+C+C.\n\nThe engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use [RegEx 101 debugger](https://regex101.com/debugger) to see the engine has to take a total of 38 steps before it can determine the string doesn't match.\n\nFrom there, the number of steps the engine must use to validate a string just continues to grow.\n\n| String | Number of C's | Number of steps |\n| -------|-------------:| -----:|\n| ACCCX | 3 | 38\n| ACCCCX | 4 | 71\n| ACCCCCX | 5 | 136\n| ACCCCCCCCCCCCCCX | 14 | 65,553\n\n\nBy the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.\n\n## Remediation\nUpgrade `semver` to version 5.7.2, 6.3.1, 7.5.2 or higher.\n## References\n- [GitHub Commit](https://github.com/npm/node-semver/commit/2f8fd41487acf380194579ecb6f8b1bbfe116be0)\n- [GitHub Commit](https://github.com/npm/node-semver/commit/717534ee353682f3bcf33e60a8af4292626d4441)\n- [GitHub Commit](https://github.com/npm/node-semver/commit/928e56d21150da0413a3333a3148b20e741a920c)\n- [GitHub PR](https://github.com/npm/node-semver/pull/564)\n- [Vulnerable Code](https://github.com/npm/node-semver/blob/main/classes/range.js#L97-L104)\n- [Vulnerable Code](https://github.com/npm/node-semver/blob/main/internal/re.js#L138)\n- [Vulnerable Code](https://github.com/npm/node-semver/blob/main/internal/re.js#L160)\n",
"epssDetails": {
"percentile": "0.51115",
"probability": "0.00148",
"modelVersion": "v2023.03.01"
},
"identifiers": {
"CVE": [
"CVE-2022-25883"
],
"CWE": [
"CWE-1333"
]
},
"packageName": "semver",
"proprietary": true,
"creationTime": "2023-01-25T16:16:50.073158Z",
"functions_new": [],
"alternativeIds": [],
"disclosureTime": "2023-01-25T16:00:59Z",
"exploitDetails": {
"sources": [
"Snyk"
],
"maturityLevels": [
{
"type": "secondary",
"level": "Proof of Concept",
"format": "CVSSv3"
},
{
"type": "primary",
"level": "Proof of Concept",
"format": "CVSSv4"
}
]
},
"packageManager": "npm",
"publicationTime": "2023-06-20T15:39:58.313421Z",
"severityBasedOn": "CVSS",
"modificationTime": "2024-03-11T09:54:01.668389Z",
"socialTrendAlert": false,
"appliedPolicyRules": {
"annotation": {
"value": "annotate on this SNYK-JS-SEMVER-3247795 09/08/2024",
"reason": "SNYK-JS-SEMVER-3247795 annotating..."
}
},
"severityWithCritical": "high",
"from": [
"[email protected]",
"[email protected]"
],
"upgradePath": [
false,
"[email protected]"
],
"isUpgradable": true,
"isPatchable": false,
"name": "semver",
"version": "2.2.1"
}
Loading

0 comments on commit 01e2db1

Please sign in to comment.