mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
Compare commits
7 Commits
v0.67.2
...
release/v0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
928c7c0f1a | ||
|
|
14a058f608 | ||
|
|
990bc4e828 | ||
|
|
8c6a4a64c4 | ||
|
|
6ae7cd5fd3 | ||
|
|
6fa91bf5cc | ||
|
|
c20d9e2564 |
@@ -1 +1 @@
|
||||
{".":"0.55.0"}
|
||||
{".":"0.55.2"}
|
||||
|
||||
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
||||
# Changelog
|
||||
|
||||
## [0.55.2](https://github.com/aquasecurity/trivy/compare/v0.55.1...v0.55.2) (2024-09-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **java:** use `dependencyManagement` from root/child pom's for dependencies from parents [backport: release/v0.55] ([#7521](https://github.com/aquasecurity/trivy/issues/7521)) ([14a058f](https://github.com/aquasecurity/trivy/commit/14a058f608be403a53019775c8308f4f5718afd7))
|
||||
|
||||
## [0.55.1](https://github.com/aquasecurity/trivy/compare/v0.55.0...v0.55.1) (2024-09-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **report:** change a receiver of MarshalJSON [backport: release/v0.55] ([#7490](https://github.com/aquasecurity/trivy/issues/7490)) ([6fa91bf](https://github.com/aquasecurity/trivy/commit/6fa91bf5cc97043ed0690e1749db502a3287134a))
|
||||
* **report:** fix error with unmarshal of `ExperimentalModifiedFindings` [backport: release/v0.55] ([#7492](https://github.com/aquasecurity/trivy/issues/7492)) ([6ae7cd5](https://github.com/aquasecurity/trivy/commit/6ae7cd5fd3ef820037de36fa197aad4453a50c25))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* **java:** stop supporting of `test` scope for `pom.xml` files [backport: release/v0.55] ([#7489](https://github.com/aquasecurity/trivy/issues/7489)) ([c20d9e2](https://github.com/aquasecurity/trivy/commit/c20d9e25640aa57ca7d73e99ce09760174411669))
|
||||
|
||||
## [0.55.0](https://github.com/aquasecurity/trivy/compare/v0.54.0...v0.55.0) (2024-09-03)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM alpine:3.20.0
|
||||
FROM alpine:3.20.3
|
||||
RUN apk --no-cache add ca-certificates git
|
||||
COPY trivy /usr/local/bin/trivy
|
||||
COPY contrib/*.tpl contrib/
|
||||
|
||||
@@ -12,12 +12,12 @@ Each artifact supports the following scanners:
|
||||
|
||||
The following table provides an outline of the features Trivy offers.
|
||||
|
||||
| Artifact | Internet access | Dev dependencies | [Dependency graph][dependency-graph] | Position | [Detection Priority][detection-priority] |
|
||||
|------------------|:---------------------:|:------------------:|:------------------------------------:|:--------:|:----------------------------------------:|
|
||||
| JAR/WAR/PAR/EAR | Trivy Java DB | Include | - | - | Not needed |
|
||||
| pom.xml | Maven repository [^1] | [Exclude](#scopes) | ✓ | ✓[^7] | - |
|
||||
| *gradle.lockfile | - | Exclude | ✓ | ✓ | Not needed |
|
||||
| *.sbt.lock | - | Exclude | - | ✓ | Not needed |
|
||||
| Artifact | Internet access | Dev dependencies | [Dependency graph][dependency-graph] | Position | [Detection Priority][detection-priority] |
|
||||
|------------------|:---------------------:|:----------------:|:------------------------------------:|:--------:|:----------------------------------------:|
|
||||
| JAR/WAR/PAR/EAR | Trivy Java DB | Include | - | - | Not needed |
|
||||
| pom.xml | Maven repository [^1] | Exclude | ✓ | ✓[^7] | - |
|
||||
| *gradle.lockfile | - | Exclude | ✓ | ✓ | Not needed |
|
||||
| *.sbt.lock | - | Exclude | - | ✓ | Not needed |
|
||||
|
||||
These may be enabled or disabled depending on the target.
|
||||
See [here](./index.md) for the detail.
|
||||
@@ -69,11 +69,6 @@ The vulnerability database will be downloaded anyway.
|
||||
!!! Warning
|
||||
Trivy may skip some dependencies (that were not found on your local machine) when the `--offline-scan` flag is passed.
|
||||
|
||||
### scopes
|
||||
Trivy supports `runtime`, `compile`, `test` and `import` (for `dependencyManagement`) [dependency scopes][dependency-scopes].
|
||||
Dependencies without scope are also detected.
|
||||
|
||||
By default, Trivy doesn't report dependencies with `test` scope. Use the `--include-dev-deps` flag to include them.
|
||||
|
||||
### maven-invoker-plugin
|
||||
Typically, the integration tests directory (`**/[src|target]/it/*/pom.xml`) of [maven-invoker-plugin][maven-invoker-plugin] doesn't contain actual `pom.xml` files and should be skipped to avoid noise.
|
||||
@@ -125,4 +120,3 @@ Make sure that you have cache[^8] directory to find licenses from `*.pom` depend
|
||||
[maven-pom-repos]: https://maven.apache.org/settings.html#repositories
|
||||
[sbt-dependency-lock]: https://stringbean.github.io/sbt-dependency-lock
|
||||
[detection-priority]: ../../scanner/vulnerability.md#detection-priority
|
||||
[dependency-scopes]: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
|
||||
|
||||
8
go.mod
8
go.mod
@@ -26,7 +26,7 @@ require (
|
||||
github.com/aquasecurity/testdocker v0.0.0-20240730042311-4642e94c7fc8
|
||||
github.com/aquasecurity/tml v0.6.1
|
||||
github.com/aquasecurity/trivy-checks v0.13.1-0.20240830230553-53ddbbade784
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240718084044-d23a6ca8ba04
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240910133327-7e0f4d2ed4c1
|
||||
github.com/aquasecurity/trivy-java-db v0.0.0-20240109071736-184bd7481d48
|
||||
github.com/aquasecurity/trivy-kubernetes v0.6.7-0.20240707095038-0300bc49b68b
|
||||
github.com/aws/aws-sdk-go-v2 v1.30.4
|
||||
@@ -97,7 +97,7 @@ require (
|
||||
github.com/owenrumney/squealer v1.2.3
|
||||
github.com/package-url/packageurl-go v0.1.3
|
||||
github.com/quasilyte/go-ruleguard/dsl v0.3.22
|
||||
github.com/samber/lo v1.46.0
|
||||
github.com/samber/lo v1.47.0
|
||||
github.com/secure-systems-lab/go-securesystemslib v0.8.0
|
||||
github.com/sigstore/rekor v1.3.6
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
@@ -116,7 +116,7 @@ require (
|
||||
github.com/xlab/treeprint v1.2.0
|
||||
github.com/zclconf/go-cty v1.15.0
|
||||
github.com/zclconf/go-cty-yaml v1.0.3
|
||||
go.etcd.io/bbolt v1.3.10
|
||||
go.etcd.io/bbolt v1.3.11
|
||||
golang.org/x/crypto v0.26.0
|
||||
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
|
||||
golang.org/x/mod v0.20.0
|
||||
@@ -382,7 +382,7 @@ require (
|
||||
golang.org/x/sys v0.23.0 // indirect
|
||||
golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect
|
||||
golang.org/x/time v0.6.0 // indirect
|
||||
golang.org/x/tools v0.23.0 // indirect
|
||||
golang.org/x/tools v0.24.0 // indirect
|
||||
google.golang.org/api v0.172.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
|
||||
|
||||
16
go.sum
16
go.sum
@@ -350,8 +350,8 @@ github.com/aquasecurity/tml v0.6.1 h1:y2ZlGSfrhnn7t4ZJ/0rotuH+v5Jgv6BDDO5jB6A9gw
|
||||
github.com/aquasecurity/tml v0.6.1/go.mod h1:OnYMWY5lvI9ejU7yH9LCberWaaTBW7hBFsITiIMY2yY=
|
||||
github.com/aquasecurity/trivy-checks v0.13.1-0.20240830230553-53ddbbade784 h1:1rvPiCK8uQd3sarOuZ60nwksHpxsNdrvptz4eDW/V14=
|
||||
github.com/aquasecurity/trivy-checks v0.13.1-0.20240830230553-53ddbbade784/go.mod h1:Ralz7PWmR3LirHlXxVtUXc+7CFmWE82jbLk7+TPvV/0=
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240718084044-d23a6ca8ba04 h1:6/T8sFdNVG/AwOGoK6X55h7hF7LYqK8bsuPz8iEz8jM=
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240718084044-d23a6ca8ba04/go.mod h1:0T6oy2t1Iedt+yi3Ml5cpOYp5FZT4MI1/mx+3p+PIs8=
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240910133327-7e0f4d2ed4c1 h1:G0gnacAORRUqz2Tm5MqivSpldY2GZ74ijhJcMsae+sA=
|
||||
github.com/aquasecurity/trivy-db v0.0.0-20240910133327-7e0f4d2ed4c1/go.mod h1:PYkSRx4dlgFATEt+okGwibvbxVEtqsOdH+vX/saACYE=
|
||||
github.com/aquasecurity/trivy-java-db v0.0.0-20240109071736-184bd7481d48 h1:JVgBIuIYbwG+ekC5lUHUpGJboPYiCcxiz06RCtz8neI=
|
||||
github.com/aquasecurity/trivy-java-db v0.0.0-20240109071736-184bd7481d48/go.mod h1:Ldya37FLi0e/5Cjq2T5Bty7cFkzUDwTcPeQua+2M8i8=
|
||||
github.com/aquasecurity/trivy-kubernetes v0.6.7-0.20240707095038-0300bc49b68b h1:h7gsIzHyrxpQnayOuQI0kX7+8rVcqhV6G5bM3KVFyJU=
|
||||
@@ -1234,8 +1234,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
|
||||
github.com/samber/lo v1.46.0 h1:w8G+oaCPgz1PoCJztqymCFaKwXt+5cCXn51uPxExFfQ=
|
||||
github.com/samber/lo v1.46.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
||||
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
||||
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
||||
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
|
||||
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
|
||||
github.com/sassoftware/relic v7.2.1+incompatible h1:Pwyh1F3I0r4clFJXkSI8bOyJINGqpgjJU3DYAZeI05A=
|
||||
@@ -1418,8 +1418,8 @@ github.com/zclconf/go-cty-yaml v1.0.3/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JApr
|
||||
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
|
||||
github.com/zeebo/errs v1.3.0/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
|
||||
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
|
||||
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
|
||||
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
|
||||
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
|
||||
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
|
||||
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
@@ -1813,8 +1813,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
|
||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
|
||||
golang.org/x/vuln v1.1.3 h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
|
||||
golang.org/x/vuln v1.1.3/go.mod h1:7Le6Fadm5FOqE9C926BCD0g12NWyhg7cxV4BwcPFuNY=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
@@ -11,9 +11,11 @@ import (
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
type args struct {
|
||||
input string
|
||||
format string
|
||||
scanners string
|
||||
input string
|
||||
format string
|
||||
scanners string
|
||||
showSuppressed bool
|
||||
listAllPkgs bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -37,6 +39,16 @@ func TestConvert(t *testing.T) {
|
||||
},
|
||||
golden: "testdata/npm-cyclonedx.json.golden",
|
||||
},
|
||||
{
|
||||
name: "npm with suppressed vulnerability",
|
||||
args: args{
|
||||
input: "testdata/fixtures/convert/npm-with-suppressed.json.golden",
|
||||
format: "json",
|
||||
showSuppressed: true,
|
||||
listAllPkgs: true,
|
||||
},
|
||||
golden: "testdata/fixtures/convert/npm-with-suppressed.json.golden",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -50,6 +62,14 @@ func TestConvert(t *testing.T) {
|
||||
tt.args.format,
|
||||
}
|
||||
|
||||
if tt.args.showSuppressed {
|
||||
osArgs = append(osArgs, "--show-suppressed")
|
||||
}
|
||||
|
||||
if tt.args.listAllPkgs {
|
||||
osArgs = append(osArgs, "--list-all-pkgs")
|
||||
}
|
||||
|
||||
// Set up the output file
|
||||
outputFile := filepath.Join(t.TempDir(), "output.json")
|
||||
if *update {
|
||||
|
||||
195
integration/testdata/fixtures/convert/npm-with-suppressed.json.golden
vendored
Normal file
195
integration/testdata/fixtures/convert/npm-with-suppressed.json.golden
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
{
|
||||
"SchemaVersion": 2,
|
||||
"CreatedAt": "2024-09-09T13:21:09.230231+06:00",
|
||||
"ArtifactName": "package-lock.json",
|
||||
"ArtifactType": "filesystem",
|
||||
"Metadata": {
|
||||
"ImageConfig": {
|
||||
"architecture": "",
|
||||
"created": "0001-01-01T00:00:00Z",
|
||||
"os": "",
|
||||
"rootfs": {
|
||||
"type": "",
|
||||
"diff_ids": null
|
||||
},
|
||||
"config": {}
|
||||
}
|
||||
},
|
||||
"Results": [
|
||||
{
|
||||
"Target": "package-lock.json",
|
||||
"Class": "lang-pkgs",
|
||||
"Type": "npm",
|
||||
"Packages": [
|
||||
{
|
||||
"ID": "debug@3.0.1",
|
||||
"Name": "debug",
|
||||
"Identifier": {
|
||||
"PURL": "pkg:npm/debug@3.0.1",
|
||||
"UID": "45acc377fa09cc3"
|
||||
},
|
||||
"Version": "3.0.1",
|
||||
"Relationship": "direct",
|
||||
"DependsOn": [
|
||||
"ms@2.0.0"
|
||||
],
|
||||
"Layer": {},
|
||||
"Locations": [
|
||||
{
|
||||
"StartLine": 11,
|
||||
"EndLine": 19
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ID": "ms@2.0.0",
|
||||
"Name": "ms",
|
||||
"Identifier": {
|
||||
"PURL": "pkg:npm/ms@2.0.0",
|
||||
"UID": "f51af0181daf2ced"
|
||||
},
|
||||
"Version": "2.0.0",
|
||||
"Indirect": true,
|
||||
"Relationship": "indirect",
|
||||
"Layer": {},
|
||||
"Locations": [
|
||||
{
|
||||
"StartLine": 20,
|
||||
"EndLine": 25
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Vulnerabilities": [
|
||||
{
|
||||
"VulnerabilityID": "CVE-2017-20165",
|
||||
"PkgID": "debug@3.0.1",
|
||||
"PkgName": "debug",
|
||||
"PkgIdentifier": {
|
||||
"PURL": "pkg:npm/debug@3.0.1",
|
||||
"UID": "45acc377fa09cc3"
|
||||
},
|
||||
"InstalledVersion": "3.0.1",
|
||||
"FixedVersion": "3.1.0, 2.6.9",
|
||||
"Status": "fixed",
|
||||
"Layer": {},
|
||||
"SeveritySource": "ghsa",
|
||||
"PrimaryURL": "https://avd.aquasec.com/nvd/cve-2017-20165",
|
||||
"DataSource": {
|
||||
"ID": "ghsa",
|
||||
"Name": "GitHub Security Advisory npm",
|
||||
"URL": "https://github.com/advisories?query=type%3Areviewed+ecosystem%3Anpm"
|
||||
},
|
||||
"Title": "A vulnerability classified as problematic has been found in debug-js d ...",
|
||||
"Description": "A vulnerability classified as problematic has been found in debug-js debug up to 3.0.x. This affects the function useColors of the file src/node.js. The manipulation of the argument str leads to inefficient regular expression complexity. Upgrading to version 3.1.0 is able to address this issue. The identifier of the patch is c38a0166c266a679c8de012d4eaccec3f944e685. It is recommended to upgrade the affected component. The identifier VDB-217665 was assigned to this vulnerability.",
|
||||
"Severity": "HIGH",
|
||||
"CweIDs": [
|
||||
"CWE-1333"
|
||||
],
|
||||
"VendorSeverity": {
|
||||
"ghsa": 3,
|
||||
"nvd": 3
|
||||
},
|
||||
"CVSS": {
|
||||
"ghsa": {
|
||||
"V3Vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
|
||||
"V3Score": 7.5
|
||||
},
|
||||
"nvd": {
|
||||
"V3Vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
|
||||
"V3Score": 7.5
|
||||
}
|
||||
},
|
||||
"References": [
|
||||
"https://github.com/debug-js/debug",
|
||||
"https://github.com/debug-js/debug/commit/c38a0166c266a679c8de012d4eaccec3f944e685",
|
||||
"https://github.com/debug-js/debug/commit/f53962e944a87e6ca9bb622a2a12dffc22a9bb5a",
|
||||
"https://github.com/debug-js/debug/pull/504",
|
||||
"https://github.com/debug-js/debug/releases/tag/2.6.9",
|
||||
"https://github.com/debug-js/debug/releases/tag/3.1.0",
|
||||
"https://nvd.nist.gov/vuln/detail/CVE-2017-20165",
|
||||
"https://vuldb.com/?ctiid.217665",
|
||||
"https://vuldb.com/?id.217665"
|
||||
],
|
||||
"PublishedDate": "2023-01-09T10:15:10.447Z",
|
||||
"LastModifiedDate": "2024-05-17T01:17:24.28Z"
|
||||
}
|
||||
],
|
||||
"ExperimentalModifiedFindings": [
|
||||
{
|
||||
"Type": "vulnerability",
|
||||
"Status": "not_affected",
|
||||
"Statement": "vulnerable_code_not_in_execute_path",
|
||||
"Source": "./vex.json",
|
||||
"Finding": {
|
||||
"VulnerabilityID": "CVE-2017-16137",
|
||||
"PkgID": "debug@3.0.1",
|
||||
"PkgName": "debug",
|
||||
"PkgIdentifier": {
|
||||
"PURL": "pkg:npm/debug@3.0.1",
|
||||
"UID": "45acc377fa09cc3"
|
||||
},
|
||||
"InstalledVersion": "3.0.1",
|
||||
"FixedVersion": "2.6.9, 3.1.0, 3.2.7, 4.3.1",
|
||||
"Status": "fixed",
|
||||
"Layer": {},
|
||||
"SeveritySource": "ghsa",
|
||||
"PrimaryURL": "https://avd.aquasec.com/nvd/cve-2017-16137",
|
||||
"DataSource": {
|
||||
"ID": "ghsa",
|
||||
"Name": "GitHub Security Advisory npm",
|
||||
"URL": "https://github.com/advisories?query=type%3Areviewed+ecosystem%3Anpm"
|
||||
},
|
||||
"Title": "nodejs-debug: Regular expression Denial of Service",
|
||||
"Description": "The debug module is vulnerable to regular expression denial of service when untrusted user input is passed into the o formatter. It takes around 50k characters to block for 2 seconds making this a low severity issue.",
|
||||
"Severity": "LOW",
|
||||
"CweIDs": [
|
||||
"CWE-400"
|
||||
],
|
||||
"VendorSeverity": {
|
||||
"ghsa": 1,
|
||||
"nvd": 2,
|
||||
"redhat": 2
|
||||
},
|
||||
"CVSS": {
|
||||
"ghsa": {
|
||||
"V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L",
|
||||
"V3Score": 3.7
|
||||
},
|
||||
"nvd": {
|
||||
"V2Vector": "AV:N/AC:L/Au:N/C:N/I:N/A:P",
|
||||
"V3Vector": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L",
|
||||
"V2Score": 5,
|
||||
"V3Score": 5.3
|
||||
},
|
||||
"redhat": {
|
||||
"V3Vector": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L",
|
||||
"V3Score": 5.3
|
||||
}
|
||||
},
|
||||
"References": [
|
||||
"https://access.redhat.com/security/cve/CVE-2017-16137",
|
||||
"https://github.com/debug-js/debug/commit/4e2150207c568adb9ead8f4c4528016081c88020",
|
||||
"https://github.com/debug-js/debug/commit/71169065b5262f9858ac78cc0b688c84a438f290",
|
||||
"https://github.com/debug-js/debug/commit/b6d12fdbc63b483e5c969da33ea6adc09946b5ac",
|
||||
"https://github.com/debug-js/debug/commit/f53962e944a87e6ca9bb622a2a12dffc22a9bb5a",
|
||||
"https://github.com/debug-js/debug/issues/797",
|
||||
"https://github.com/visionmedia/debug",
|
||||
"https://github.com/visionmedia/debug/issues/501",
|
||||
"https://github.com/visionmedia/debug/pull/504",
|
||||
"https://lists.apache.org/thread.html/r8ba4c628fba7181af58817d452119481adce4ba92e889c643e4c7dd3%40%3Ccommits.netbeans.apache.org%3E",
|
||||
"https://lists.apache.org/thread.html/r8ba4c628fba7181af58817d452119481adce4ba92e889c643e4c7dd3@%3Ccommits.netbeans.apache.org%3E",
|
||||
"https://lists.apache.org/thread.html/rb5ac16fad337d1f3bb7079549f97d8166d0ef3082629417c39f12d63%40%3Cnotifications.netbeans.apache.org%3E",
|
||||
"https://lists.apache.org/thread.html/rb5ac16fad337d1f3bb7079549f97d8166d0ef3082629417c39f12d63@%3Cnotifications.netbeans.apache.org%3E",
|
||||
"https://nodesecurity.io/advisories/534",
|
||||
"https://nvd.nist.gov/vuln/detail/CVE-2017-16137",
|
||||
"https://www.cve.org/CVERecord?id=CVE-2017-16137"
|
||||
],
|
||||
"PublishedDate": "2018-06-07T02:29:03.817Z",
|
||||
"LastModifiedDate": "2023-11-07T02:40:28.13Z"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -27,7 +27,6 @@ type artifact struct {
|
||||
|
||||
Module bool
|
||||
Relationship ftypes.Relationship
|
||||
Test bool
|
||||
|
||||
Locations ftypes.Locations
|
||||
}
|
||||
|
||||
@@ -214,7 +214,6 @@ func (p *Parser) parseRoot(root artifact, uniqModules map[string]struct{}) ([]ft
|
||||
Licenses: result.artifact.Licenses,
|
||||
Relationship: art.Relationship,
|
||||
Locations: art.Locations,
|
||||
Test: art.Test,
|
||||
}
|
||||
|
||||
// save only dependency names
|
||||
@@ -235,7 +234,6 @@ func (p *Parser) parseRoot(root artifact, uniqModules map[string]struct{}) ([]ft
|
||||
Licenses: art.Licenses,
|
||||
Relationship: art.Relationship,
|
||||
Locations: art.Locations,
|
||||
Dev: art.Test,
|
||||
}
|
||||
pkgs = append(pkgs, pkg)
|
||||
|
||||
@@ -337,8 +335,20 @@ func (p *Parser) analyze(pom *pom, opts analysisOptions) (analysisResult, error)
|
||||
p.releaseRemoteRepos = lo.Uniq(append(pomReleaseRemoteRepos, p.releaseRemoteRepos...))
|
||||
p.snapshotRemoteRepos = lo.Uniq(append(pomSnapshotRemoteRepos, p.snapshotRemoteRepos...))
|
||||
|
||||
// We need to forward dependencyManagements from current and root pom to Parent,
|
||||
// to use them for dependencies in parent.
|
||||
// For better understanding see the following tests:
|
||||
// - `dependency from parent uses version from child pom depManagement`
|
||||
// - `dependency from parent uses version from root pom depManagement`
|
||||
//
|
||||
// depManagements from root pom has higher priority than depManagements from current pom.
|
||||
depManagementForParent := lo.UniqBy(append(opts.depManagement, pom.content.DependencyManagement.Dependencies.Dependency...),
|
||||
func(dep pomDependency) string {
|
||||
return dep.Name()
|
||||
})
|
||||
|
||||
// Parent
|
||||
parent, err := p.parseParent(pom.filePath, pom.content.Parent)
|
||||
parent, err := p.parseParent(pom.filePath, pom.content.Parent, depManagementForParent)
|
||||
if err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("parent error: %w", err)
|
||||
}
|
||||
@@ -402,7 +412,7 @@ func (p *Parser) parseDependencies(deps []pomDependency, props map[string]string
|
||||
// Resolve dependencies
|
||||
d = d.Resolve(props, depManagement, rootDepManagement)
|
||||
|
||||
if (d.Scope != "" && d.Scope != "compile" && d.Scope != "runtime" && d.Scope != "test") || d.Optional {
|
||||
if (d.Scope != "" && d.Scope != "compile" && d.Scope != "runtime") || d.Optional {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -479,7 +489,7 @@ func excludeDep(exclusions map[string]struct{}, art artifact) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Parser) parseParent(currentPath string, parent pomParent) (analysisResult, error) {
|
||||
func (p *Parser) parseParent(currentPath string, parent pomParent, rootDepManagement []pomDependency) (analysisResult, error) {
|
||||
// Pass nil properties so that variables in <parent> are not evaluated.
|
||||
target := newArtifact(parent.GroupId, parent.ArtifactId, parent.Version, nil, nil)
|
||||
// if version is property (e.g. ${revision}) - we still need to parse this pom
|
||||
@@ -501,7 +511,9 @@ func (p *Parser) parseParent(currentPath string, parent pomParent) (analysisResu
|
||||
logger.Debug("Parent POM not found", log.Err(err))
|
||||
}
|
||||
|
||||
result, err := p.analyze(parentPOM, analysisOptions{})
|
||||
result, err := p.analyze(parentPOM, analysisOptions{
|
||||
depManagement: rootDepManagement,
|
||||
})
|
||||
if err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("analyze error: %w", err)
|
||||
}
|
||||
|
||||
@@ -61,19 +61,6 @@ func TestPom_Parse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-test:2.0.0",
|
||||
Name: "org.example:example-test",
|
||||
Version: "2.0.0",
|
||||
Relationship: ftypes.RelationshipDirect,
|
||||
Dev: true,
|
||||
Locations: ftypes.Locations{
|
||||
{
|
||||
StartLine: 49,
|
||||
EndLine: 54,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantDeps: []ftypes.Dependency{
|
||||
{
|
||||
@@ -81,7 +68,6 @@ func TestPom_Parse(t *testing.T) {
|
||||
DependsOn: []string{
|
||||
"org.example:example-api:1.7.30",
|
||||
"org.example:example-runtime:1.0.0",
|
||||
"org.example:example-test:2.0.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -123,19 +109,6 @@ func TestPom_Parse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-test:2.0.0",
|
||||
Name: "org.example:example-test",
|
||||
Version: "2.0.0",
|
||||
Relationship: ftypes.RelationshipDirect,
|
||||
Dev: true,
|
||||
Locations: ftypes.Locations{
|
||||
{
|
||||
StartLine: 49,
|
||||
EndLine: 54,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantDeps: []ftypes.Dependency{
|
||||
{
|
||||
@@ -143,7 +116,6 @@ func TestPom_Parse(t *testing.T) {
|
||||
DependsOn: []string{
|
||||
"org.example:example-api:1.7.30",
|
||||
"org.example:example-runtime:1.0.0",
|
||||
"org.example:example-test:2.0.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1527,6 +1499,102 @@ func TestPom_Parse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
// [INFO] com.example:root-depManagement-in-parent:jar:1.0.0
|
||||
// [INFO] \- org.example:example-dependency:jar:2.0.0:compile
|
||||
// [INFO] \- org.example:example-api:jar:1.0.1:compile
|
||||
{
|
||||
name: "dependency from parent uses version from root pom depManagement",
|
||||
inputFile: filepath.Join("testdata", "use-root-dep-management-in-parent", "pom.xml"),
|
||||
local: true,
|
||||
want: []ftypes.Package{
|
||||
{
|
||||
ID: "com.example:root-depManagement-in-parent:1.0.0",
|
||||
Name: "com.example:root-depManagement-in-parent",
|
||||
Version: "1.0.0",
|
||||
Relationship: ftypes.RelationshipRoot,
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-dependency:2.0.0",
|
||||
Name: "org.example:example-dependency",
|
||||
Version: "2.0.0",
|
||||
Relationship: ftypes.RelationshipDirect,
|
||||
Locations: ftypes.Locations{
|
||||
{
|
||||
StartLine: 25,
|
||||
EndLine: 29,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-api:1.0.1",
|
||||
Name: "org.example:example-api",
|
||||
Version: "1.0.1",
|
||||
Relationship: ftypes.RelationshipIndirect,
|
||||
},
|
||||
},
|
||||
wantDeps: []ftypes.Dependency{
|
||||
{
|
||||
ID: "com.example:root-depManagement-in-parent:1.0.0",
|
||||
DependsOn: []string{
|
||||
"org.example:example-dependency:2.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-dependency:2.0.0",
|
||||
DependsOn: []string{
|
||||
"org.example:example-api:1.0.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// [INFO] com.example:root-depManagement-in-parent:jar:1.0.0
|
||||
// [INFO] \- org.example:example-dependency:jar:2.0.0:compile
|
||||
// [INFO] \- org.example:example-api:jar:2.0.1:compile
|
||||
{
|
||||
name: "dependency from parent uses version from child pom depManagement",
|
||||
inputFile: filepath.Join("testdata", "use-dep-management-from-child-in-parent", "pom.xml"),
|
||||
local: true,
|
||||
want: []ftypes.Package{
|
||||
{
|
||||
ID: "com.example:root-depManagement-in-parent:1.0.0",
|
||||
Name: "com.example:root-depManagement-in-parent",
|
||||
Version: "1.0.0",
|
||||
Relationship: ftypes.RelationshipRoot,
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-dependency:2.0.0",
|
||||
Name: "org.example:example-dependency",
|
||||
Version: "2.0.0",
|
||||
Relationship: ftypes.RelationshipDirect,
|
||||
Locations: ftypes.Locations{
|
||||
{
|
||||
StartLine: 15,
|
||||
EndLine: 19,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-api:2.0.1",
|
||||
Name: "org.example:example-api",
|
||||
Version: "2.0.1",
|
||||
Relationship: ftypes.RelationshipIndirect,
|
||||
},
|
||||
},
|
||||
wantDeps: []ftypes.Dependency{
|
||||
{
|
||||
ID: "com.example:root-depManagement-in-parent:1.0.0",
|
||||
DependsOn: []string{
|
||||
"org.example:example-dependency:2.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "org.example:example-dependency:2.0.0",
|
||||
DependsOn: []string{
|
||||
"org.example:example-api:2.0.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -303,7 +303,6 @@ func (d pomDependency) ToArtifact(opts analysisOptions) artifact {
|
||||
Exclusions: exclusions,
|
||||
Locations: locations,
|
||||
Relationship: ftypes.RelationshipIndirect, // default
|
||||
Test: d.Scope == "test",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,5 @@
|
||||
<version>999</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-test</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-parent</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency</artifactId>
|
||||
<version>2.0.0</version>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-parent</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<api.version>3.0.1</api.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>${api.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
21
pkg/dependency/parser/java/pom/testdata/use-dep-management-from-child-in-parent/pom.xml
vendored
Normal file
21
pkg/dependency/parser/java/pom/testdata/use-dep-management-from-child-in-parent/pom.xml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>root-depManagement-in-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
|
||||
<properties>
|
||||
<api.version>1.0.1</api.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
31
pkg/dependency/parser/java/pom/testdata/use-root-dep-management-in-parent/pom.xml
vendored
Normal file
31
pkg/dependency/parser/java/pom/testdata/use-root-dep-management-in-parent/pom.xml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>root-depManagement-in-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
|
||||
<properties>
|
||||
<api.version>1.0.1</api.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>${api.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -78,7 +78,7 @@ type PkgIdentifier struct {
|
||||
}
|
||||
|
||||
// MarshalJSON customizes the JSON encoding of PkgIdentifier.
|
||||
func (id *PkgIdentifier) MarshalJSON() ([]byte, error) {
|
||||
func (id PkgIdentifier) MarshalJSON() ([]byte, error) {
|
||||
var p string
|
||||
if id.PURL != nil {
|
||||
p = id.PURL.String()
|
||||
@@ -90,7 +90,7 @@ func (id *PkgIdentifier) MarshalJSON() ([]byte, error) {
|
||||
*Alias
|
||||
}{
|
||||
PURL: p,
|
||||
Alias: (*Alias)(id),
|
||||
Alias: (*Alias)(&id),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/package-url/packageurl-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
|
||||
"github.com/aquasecurity/trivy/pkg/clock"
|
||||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/report"
|
||||
"github.com/aquasecurity/trivy/pkg/types"
|
||||
)
|
||||
@@ -156,6 +158,33 @@ func TestReportWriter_Template(t *testing.T) {
|
||||
template: `{{ $high := 0 }}{{ $critical := 0 }}{{ range . }}{{ range .Vulnerabilities}}{{ if eq .Severity "HIGH" }}{{ $high = add $high 1 }}{{ end }}{{ if eq .Severity "CRITICAL" }}{{ $critical = add $critical 1 }}{{ end }}{{ end }}Critical: {{ $critical }}, High: {{ $high }}{{ end }}`,
|
||||
expected: `Critical: 2, High: 1`,
|
||||
},
|
||||
{
|
||||
name: "custom JSON marshaler",
|
||||
detectedVulns: []types.DetectedVulnerability{
|
||||
{
|
||||
VulnerabilityID: "CVE-2019-0000",
|
||||
PkgName: "foo",
|
||||
Status: dbTypes.StatusAffected,
|
||||
PkgIdentifier: ftypes.PkgIdentifier{
|
||||
PURL: &packageurl.PackageURL{
|
||||
Type: packageurl.TypeNPM,
|
||||
Name: "foobar",
|
||||
Version: "1.2.3",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
template: `{{ range . }}{{ range .Vulnerabilities}}{{ toPrettyJson . }}{{ end }}{{ end }}`,
|
||||
expected: `{
|
||||
"VulnerabilityID": "CVE-2019-0000",
|
||||
"PkgName": "foo",
|
||||
"PkgIdentifier": {
|
||||
"PURL": "pkg:npm/foobar@1.2.3"
|
||||
},
|
||||
"Status": "affected",
|
||||
"Layer": {}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "happy path: env var parsing",
|
||||
detectedVulns: []types.DetectedVulnerability{},
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
type FindingType string
|
||||
type FindingStatus string
|
||||
|
||||
@@ -45,3 +51,44 @@ func NewModifiedFinding(f finding, status FindingStatus, statement, source strin
|
||||
Finding: f,
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals ModifiedFinding given the type and `UnmarshalJSON` functions of struct fields
|
||||
func (m *ModifiedFinding) UnmarshalJSON(data []byte) error {
|
||||
type Alias ModifiedFinding
|
||||
aux := &struct {
|
||||
Finding json.RawMessage `json:"Finding"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(m),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Select struct by m.Type to avoid errors with Unmarshal
|
||||
var err error
|
||||
switch m.Type {
|
||||
case FindingTypeVulnerability:
|
||||
m.Finding, err = unmarshalFinding[DetectedVulnerability](aux.Finding)
|
||||
case FindingTypeMisconfiguration:
|
||||
m.Finding, err = unmarshalFinding[DetectedMisconfiguration](aux.Finding)
|
||||
case FindingTypeSecret:
|
||||
m.Finding, err = unmarshalFinding[DetectedSecret](aux.Finding)
|
||||
case FindingTypeLicense:
|
||||
m.Finding, err = unmarshalFinding[DetectedLicense](aux.Finding)
|
||||
default:
|
||||
return xerrors.Errorf("invalid Finding type: %s", m.Type)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return xerrors.Errorf("unable to unmarshal %q type: %w", m.Type, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalFinding[T finding](data []byte) (T, error) {
|
||||
var f T
|
||||
err := json.Unmarshal(data, &f)
|
||||
return f, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user