@fabasoad/sarif-to-slack 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.github/workflows/release.yml +3 -1
  2. package/.github/workflows/send-sarif-to-slack.yml +214 -0
  3. package/.pre-commit-config.yaml +3 -3
  4. package/.tool-versions +1 -1
  5. package/Makefile +9 -2
  6. package/README.md +1 -1
  7. package/dist/Logger.js +15 -6
  8. package/dist/Processors.js +23 -22
  9. package/dist/SarifToSlackService.d.ts.map +1 -1
  10. package/dist/SarifToSlackService.js +5 -6
  11. package/dist/SlackMessageBuilder.js +46 -52
  12. package/dist/index.d.ts +6 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +7 -3
  15. package/dist/model/SarifModelPerRun.d.ts +17 -0
  16. package/dist/model/SarifModelPerRun.d.ts.map +1 -0
  17. package/dist/model/SarifModelPerRun.js +84 -0
  18. package/dist/model/SarifModelPerSarif.d.ts +20 -0
  19. package/dist/model/SarifModelPerSarif.d.ts.map +1 -0
  20. package/dist/model/SarifModelPerSarif.js +97 -0
  21. package/dist/model/types.d.ts +17 -0
  22. package/dist/model/types.d.ts.map +1 -0
  23. package/dist/model/types.js +31 -0
  24. package/dist/sarif-to-slack.d.ts +96 -12
  25. package/dist/tsdoc-metadata.json +1 -1
  26. package/dist/types.d.ts +87 -11
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js +66 -9
  29. package/dist/utils/SarifUtils.d.ts +5 -0
  30. package/dist/utils/SarifUtils.d.ts.map +1 -0
  31. package/dist/utils/SarifUtils.js +32 -0
  32. package/dist/utils/SortUtils.d.ts +5 -0
  33. package/dist/utils/SortUtils.d.ts.map +1 -0
  34. package/dist/utils/SortUtils.js +8 -0
  35. package/dist/version.d.ts +1 -1
  36. package/dist/version.js +1 -1
  37. package/etc/sarif-to-slack.api.md +32 -7
  38. package/jest.config.json +4 -4
  39. package/package.json +9 -7
  40. package/src/Logger.ts +20 -17
  41. package/src/Processors.ts +22 -22
  42. package/src/SarifToSlackService.ts +5 -6
  43. package/src/SlackMessageBuilder.ts +78 -63
  44. package/src/index.ts +10 -2
  45. package/src/model/SarifModelPerRun.ts +114 -0
  46. package/src/model/SarifModelPerSarif.ts +116 -0
  47. package/src/model/types.ts +31 -0
  48. package/src/types.ts +91 -11
  49. package/src/utils/SarifUtils.ts +44 -0
  50. package/src/utils/SortUtils.ts +21 -0
  51. package/src/version.ts +1 -1
  52. package/test-data/sarif/codeql-csharp.sarif +1 -0
  53. package/test-data/sarif/codeql-go.sarif +1 -0
  54. package/test-data/sarif/codeql-python.sarif +1 -0
  55. package/test-data/sarif/codeql-ruby.sarif +1 -0
  56. package/test-data/sarif/codeql-typescript.sarif +1 -0
  57. package/test-data/sarif/grype-container.sarif +1774 -0
  58. package/test-data/sarif/runs-1-tools-1-results-0.sarif +18 -0
  59. package/test-data/sarif/runs-2-tools-1-results-0.sarif +30 -0
  60. package/test-data/sarif/runs-2-tools-1.sarif +656 -0
  61. package/test-data/sarif/runs-2-tools-2-results-0.sarif +44 -0
  62. package/test-data/sarif/runs-2-tools-2.sarif +686 -0
  63. package/test-data/sarif/runs-3-tools-2-results-0.sarif +48 -0
  64. package/test-data/sarif/runs-3-tools-2.sarif +278 -0
  65. package/test-data/sarif/snyk-composer.sarif +934 -0
  66. package/test-data/sarif/snyk-container.sarif +313 -0
  67. package/test-data/sarif/snyk-gomodules.sarif +388 -0
  68. package/test-data/sarif/snyk-gradle.sarif +274 -0
  69. package/test-data/sarif/snyk-hex.sarif +66 -0
  70. package/test-data/sarif/snyk-maven.sarif +274 -0
  71. package/test-data/sarif/snyk-npm.sarif +896 -0
  72. package/test-data/sarif/snyk-nuget.sarif +90 -0
  73. package/test-data/sarif/snyk-pip.sarif +66 -0
  74. package/test-data/sarif/snyk-pnpm.sarif +90 -0
  75. package/test-data/sarif/snyk-poetry.sarif +1952 -0
  76. package/test-data/sarif/snyk-rubygems.sarif +440 -0
  77. package/test-data/sarif/snyk-sbt.sarif +178 -0
  78. package/test-data/sarif/snyk-swift.sarif +112 -0
  79. package/test-data/sarif/snyk-yarn.sarif +2900 -0
  80. package/test-data/sarif/trivy-iac.sarif +134 -0
  81. package/test-data/sarif/wiz-container.sarif +30916 -0
  82. package/test-data/sarif/wiz-iac.sarif +558 -0
  83. package/tests/Processors.spec.ts +3 -3
  84. package/tests/integration/SendSarifToSlack.spec.ts +56 -0
@@ -0,0 +1,48 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3
+ "version": "2.1.0",
4
+ "runs": [
5
+ {
6
+ "tool": {
7
+ "driver": {
8
+ "name": "Snyk Open Source",
9
+ "properties": {
10
+ "artifactsScanned": 1
11
+ },
12
+ "rules": []
13
+ }
14
+ },
15
+ "results": []
16
+ },
17
+ {
18
+ "tool": {
19
+ "driver": {
20
+ "name": "Snyk Open Source",
21
+ "properties": {
22
+ "artifactsScanned": 1
23
+ },
24
+ "rules": []
25
+ }
26
+ },
27
+ "results": []
28
+ },
29
+ {
30
+ "tool": {
31
+ "driver": {
32
+ "fullName": "Trivy Vulnerability Scanner",
33
+ "informationUri": "https://github.com/aquasecurity/trivy",
34
+ "name": "Trivy",
35
+ "rules": [],
36
+ "version": "0.62.1"
37
+ }
38
+ },
39
+ "results": [],
40
+ "columnKind": "utf16CodeUnits",
41
+ "originalUriBaseIds": {
42
+ "ROOTPATH": {
43
+ "uri": "file:///Users/john.doe/Source/personal/business-card-deployment/"
44
+ }
45
+ }
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,278 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3
+ "version": "2.1.0",
4
+ "runs": [
5
+ {
6
+ "tool": {
7
+ "driver": {
8
+ "name": "Snyk Open Source",
9
+ "properties": {
10
+ "artifactsScanned": 1
11
+ },
12
+ "rules": [
13
+ {
14
+ "id": "SNYK-DOTNET-NEWTONSOFTJSON-2774678",
15
+ "shortDescription": {
16
+ "text": "High severity - Insecure Defaults vulnerability in Newtonsoft.Json"
17
+ },
18
+ "fullDescription": {
19
+ "text": "(CVE-2024-21907) Newtonsoft.Json@11.0.2"
20
+ },
21
+ "help": {
22
+ "text": "",
23
+ "markdown": "* Package Manager: nuget\n* Vulnerable module: Newtonsoft.Json\n* Introduced through: nuget@1.0.0 and Newtonsoft.Json@11.0.2\n### Detailed paths\n* _Introduced through_: nuget@1.0.0 › Newtonsoft.Json@11.0.2\n# Overview\n\nAffected versions of this package are vulnerable to Insecure Defaults due to improper handling of StackOverFlow exception (SOE) whenever nested expressions are being processed.\n# PoC\n```dotnet\r\n\r\nusing System;\r\n\r\nusing System.IO;\r\nusing System.Linq;\r\nusing Newtonsoft.Json;\r\nusing Newtonsoft.Json.Linq;\r\n\r\nnamespace JsonTests\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n //Create a string representation of a highly nested object (JSON serialized)\r\n int nRep = 24000;\r\n string json = string.Concat(Enumerable.Repeat(\"{a:\", nRep)) + \"1\" +\r\n string.Concat(Enumerable.Repeat(\"}\", nRep));\r\n\r\n //Parse this object (Parsing works well - no exception is being thrown)\r\n var parsedJson = JObject.Parse(json);\r\n \r\n using (var ms = new MemoryStream())\r\n using (var sWriter = new StreamWriter(ms))\r\n using (var jWriter = new JsonTextWriter(sWriter))\r\n {\r\n //Trying to serialize the object will result in StackOverflowException !!!\r\n parsedJson.WriteTo(jWriter);\r\n }\r\n\r\n //ToString throws StackOverflowException as well (ToString is very unefficient - even for smaller payloads, it will occupy a lot of CPU & Memory)\r\n //parsedJson.ToString();\r\n\r\n //JsonConvert.SerializeObject throws StackOverflowException as well\r\n //string a = JsonConvert.SerializeObject(parsedJson);\r\n\r\n }\r\n }\r\n}\r\n\r\n```\n# Remediation\nUpgrade `Newtonsoft.Json` to version 13.0.1 or higher.\n# References\n- [GitHub Commit](https://github.com/JamesNK/Newtonsoft.Json/commit/7e77bbe1beccceac4fc7b174b53abfefac278b66)\n- [GitHub Issue](https://github.com/JamesNK/Newtonsoft.Json/issues/2457)\n- [GitHub Issue](https://github.com/JamesNK/Newtonsoft.Json/issues/3010)\n- [GitHub PR](https://github.com/JamesNK/Newtonsoft.Json/pull/2462)\n- [Security Advisory](https://alephsecurity.com/vulns/aleph-2018004)\n- [Security Article](https://alephsecurity.com/2018/10/22/StackOverflowException/)\n"
24
+ },
25
+ "properties": {
26
+ "tags": [
27
+ "security",
28
+ "CWE-755",
29
+ "nuget"
30
+ ],
31
+ "cvssv3_baseScore": 7.5,
32
+ "security-severity": "7.5"
33
+ }
34
+ }
35
+ ]
36
+ }
37
+ },
38
+ "results": [
39
+ {
40
+ "ruleId": "SNYK-DOTNET-NEWTONSOFTJSON-2774678",
41
+ "level": "error",
42
+ "message": {
43
+ "text": "This file introduces a vulnerable Newtonsoft.Json package with a high severity vulnerability."
44
+ },
45
+ "locations": [
46
+ {
47
+ "physicalLocation": {
48
+ "artifactLocation": {
49
+ "uri": "obj/project.assets.json"
50
+ },
51
+ "region": {
52
+ "startLine": 1
53
+ }
54
+ },
55
+ "logicalLocations": [
56
+ {
57
+ "fullyQualifiedName": "Newtonsoft.Json@11.0.2"
58
+ }
59
+ ]
60
+ }
61
+ ],
62
+ "fixes": [
63
+ {
64
+ "description": {
65
+ "text": "Upgrade to Newtonsoft.Json@13.0.1"
66
+ },
67
+ "artifactChanges": [
68
+ {
69
+ "artifactLocation": {
70
+ "uri": "obj/project.assets.json"
71
+ },
72
+ "replacements": [
73
+ {
74
+ "deletedRegion": {
75
+ "startLine": 1
76
+ },
77
+ "insertedContent": {
78
+ "text": "Newtonsoft.Json@13.0.1"
79
+ }
80
+ }
81
+ ]
82
+ }
83
+ ]
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ },
89
+ {
90
+ "tool": {
91
+ "driver": {
92
+ "name": "Snyk Open Source",
93
+ "properties": {
94
+ "artifactsScanned": 1
95
+ },
96
+ "rules": [
97
+ {
98
+ "id": "SNYK-PYTHON-PY-1049546",
99
+ "shortDescription": {
100
+ "text": "Medium severity - Regular Expression Denial of Service (ReDoS) vulnerability in py"
101
+ },
102
+ "fullDescription": {
103
+ "text": "(CVE-2020-29651) py@1.4.26"
104
+ },
105
+ "help": {
106
+ "text": "",
107
+ "markdown": "* Package Manager: pip\n* Vulnerable module: py\n* Introduced through: pip@0.0.0 and py@1.4.26\n### Detailed paths\n* _Introduced through_: pip@0.0.0 › py@1.4.26\n# Overview\n[py](https://pypi.org/project/py/) is an a Python development support library.\n\nAffected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). The subpattern `\\d+\\s*\\S+` is ambiguous which makes the pattern subject to catastrophic backtracing given a string like `\"1\" * 5000`.\r\n\r\nSVN blame output seems to always have at least one space between the revision number and the user name, so the ambiguity can be fixed by changing the * to +.\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 `py` to version 1.10.0 or higher.\n# References\n- [GitHub Commit](https://github.com/pytest-dev/py/pull/257/commits/4a9017dc6199d2a564b6e4b0aa39d6d8870e4144)\n- [GitHub Issue](https://github.com/pytest-dev/py/issues/256)\n- [GitHub PR](https://github.com/pytest-dev/py/pull/257)\n"
108
+ },
109
+ "properties": {
110
+ "tags": [
111
+ "security",
112
+ "CWE-400",
113
+ "pip"
114
+ ],
115
+ "cvssv3_baseScore": 4.3,
116
+ "security-severity": "4.3"
117
+ }
118
+ }
119
+ ]
120
+ }
121
+ },
122
+ "results": [
123
+ {
124
+ "ruleId": "SNYK-PYTHON-PY-1049546",
125
+ "level": "warning",
126
+ "message": {
127
+ "text": "This file introduces a vulnerable py package with a medium severity vulnerability."
128
+ },
129
+ "locations": [
130
+ {
131
+ "physicalLocation": {
132
+ "artifactLocation": {
133
+ "uri": "requirements.txt"
134
+ },
135
+ "region": {
136
+ "startLine": 1
137
+ }
138
+ },
139
+ "logicalLocations": [
140
+ {
141
+ "fullyQualifiedName": "py@1.4.26"
142
+ }
143
+ ]
144
+ }
145
+ ]
146
+ }
147
+ ]
148
+ },
149
+ {
150
+ "tool": {
151
+ "driver": {
152
+ "fullName": "Trivy Vulnerability Scanner",
153
+ "informationUri": "https://github.com/aquasecurity/trivy",
154
+ "name": "Trivy",
155
+ "rules": [
156
+ {
157
+ "id": "s3-bucket-logging",
158
+ "name": "Misconfiguration",
159
+ "shortDescription": {
160
+ "text": "S3 Bucket Logging"
161
+ },
162
+ "fullDescription": {
163
+ "text": "Ensures S3 bucket logging is enabled for S3 buckets"
164
+ },
165
+ "defaultConfiguration": {
166
+ "level": "note"
167
+ },
168
+ "helpUri": "https://avd.aquasec.com/misconfig/s3-bucket-logging",
169
+ "help": {
170
+ "text": "Misconfiguration s3-bucket-logging\nType: Terraform Security Check\nSeverity: LOW\nCheck: S3 Bucket Logging\nMessage: Bucket has logging disabled\nLink: [s3-bucket-logging](https://avd.aquasec.com/misconfig/s3-bucket-logging)\nEnsures S3 bucket logging is enabled for S3 buckets",
171
+ "markdown": "**Misconfiguration s3-bucket-logging**\n| Type | Severity | Check | Message | Link |\n| --- | --- | --- | --- | --- |\n|Terraform Security Check|LOW|S3 Bucket Logging|Bucket has logging disabled|[s3-bucket-logging](https://avd.aquasec.com/misconfig/s3-bucket-logging)|\n\nEnsures S3 bucket logging is enabled for S3 buckets"
172
+ },
173
+ "properties": {
174
+ "precision": "very-high",
175
+ "security-severity": "2.0",
176
+ "tags": [
177
+ "misconfiguration",
178
+ "security",
179
+ "LOW"
180
+ ]
181
+ }
182
+ },
183
+ {
184
+ "id": "AVD-AWS-0132",
185
+ "name": "Misconfiguration",
186
+ "shortDescription": {
187
+ "text": "S3 encryption should use Customer Managed Keys"
188
+ },
189
+ "fullDescription": {
190
+ "text": "Encryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.\n"
191
+ },
192
+ "defaultConfiguration": {
193
+ "level": "error"
194
+ },
195
+ "helpUri": "https://avd.aquasec.com/misconfig/avd-aws-0132",
196
+ "help": {
197
+ "text": "Misconfiguration AVD-AWS-0132\nType: Terraform Security Check\nSeverity: HIGH\nCheck: S3 encryption should use Customer Managed Keys\nMessage: Bucket does not encrypt data with a customer managed key.\nLink: [AVD-AWS-0132](https://avd.aquasec.com/misconfig/avd-aws-0132)\nEncryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.\n",
198
+ "markdown": "**Misconfiguration AVD-AWS-0132**\n| Type | Severity | Check | Message | Link |\n| --- | --- | --- | --- | --- |\n|Terraform Security Check|HIGH|S3 encryption should use Customer Managed Keys|Bucket does not encrypt data with a customer managed key.|[AVD-AWS-0132](https://avd.aquasec.com/misconfig/avd-aws-0132)|\n\nEncryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.\n"
199
+ },
200
+ "properties": {
201
+ "precision": "very-high",
202
+ "security-severity": "8.0",
203
+ "tags": [
204
+ "misconfiguration",
205
+ "security",
206
+ "HIGH"
207
+ ]
208
+ }
209
+ }
210
+ ],
211
+ "version": "0.62.1"
212
+ }
213
+ },
214
+ "results": [
215
+ {
216
+ "ruleId": "s3-bucket-logging",
217
+ "ruleIndex": 0,
218
+ "level": "note",
219
+ "message": {
220
+ "text": "Artifact: terraform/s3.tf\nType: terraform\nVulnerability s3-bucket-logging\nSeverity: LOW\nMessage: Bucket has logging disabled\nLink: [s3-bucket-logging](https://avd.aquasec.com/misconfig/s3-bucket-logging)"
221
+ },
222
+ "locations": [
223
+ {
224
+ "physicalLocation": {
225
+ "artifactLocation": {
226
+ "uri": "terraform/s3.tf",
227
+ "uriBaseId": "ROOTPATH"
228
+ },
229
+ "region": {
230
+ "startLine": 16,
231
+ "startColumn": 1,
232
+ "endLine": 44,
233
+ "endColumn": 1
234
+ }
235
+ },
236
+ "message": {
237
+ "text": "terraform/s3.tf"
238
+ }
239
+ }
240
+ ]
241
+ },
242
+ {
243
+ "ruleId": "AVD-AWS-0132",
244
+ "ruleIndex": 1,
245
+ "level": "error",
246
+ "message": {
247
+ "text": "Artifact: terraform/s3.tf\nType: terraform\nVulnerability AVD-AWS-0132\nSeverity: HIGH\nMessage: Bucket does not encrypt data with a customer managed key.\nLink: [AVD-AWS-0132](https://avd.aquasec.com/misconfig/avd-aws-0132)"
248
+ },
249
+ "locations": [
250
+ {
251
+ "physicalLocation": {
252
+ "artifactLocation": {
253
+ "uri": "terraform/s3.tf",
254
+ "uriBaseId": "ROOTPATH"
255
+ },
256
+ "region": {
257
+ "startLine": 16,
258
+ "startColumn": 1,
259
+ "endLine": 44,
260
+ "endColumn": 1
261
+ }
262
+ },
263
+ "message": {
264
+ "text": "terraform/s3.tf"
265
+ }
266
+ }
267
+ ]
268
+ }
269
+ ],
270
+ "columnKind": "utf16CodeUnits",
271
+ "originalUriBaseIds": {
272
+ "ROOTPATH": {
273
+ "uri": "file:///Users/john.doe/Source/personal/business-card-deployment/"
274
+ }
275
+ }
276
+ }
277
+ ]
278
+ }