Skip to content

Commit dcdf340

Browse files
feature: Malicious packages scanner [TAROT-3600] (#175)
* openssf malicious packages integration * updated test to match new live CVE * revised malicious package detection to prebuild an index nightly so as to accelerate scanning. * fixed build - tool wasn't scanning for package.json -- added test for package-lock.json also * merged main, added Dockerfile * resolved codacy warnings * fixed codacy cyclo issue * fixed AI nonsense * fixed CICD -- necessary file wasn't being copied * fixed another CICD issue * bugfix in tool.go to live with nil PURLs and fixed absent line number reporting in openssf scanner * stopped copying unnecessary files * fixed test data * test fixes * ignored codacy config * review comments tackled * fixed stupid ai shit - npm ref in gradle file * fixed missing vuln * Delete .codacy/cli.sh * Delete .codacy/codacy.yaml * clean: Assorted cleanup after rebase * clean: Improve build process for OpenSSF malicious packages index * clean: Simplify and correct malicious packages scanner implementation * clean: Ensure proper dependency injection for testable code * clean: Address codacy comments * tests: Add unit tests and fix faulty implementations * ci: Serialize steps to avoid problems when saving to workspace * tests: Fix integration tests * clean: Log when failing to open file when building index * clean: Address AI review comments * feat: Support the `last_affected` field in range events --------- Co-authored-by: André Meira <[email protected]>
1 parent c408754 commit dcdf340

File tree

23 files changed

+1203
-24
lines changed

23 files changed

+1203
-24
lines changed

.circleci/config.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ references:
1313
mkdir cache
1414
./trivy --cache-dir ./cache image --download-db-only
1515
16+
build_openssf_malicious_package_index: &build_openssf_malicious_package_index
17+
persist_to_workspace: true
18+
cmd: |
19+
mkdir openssf-malicious-packages
20+
curl -sfL https://api.github.com/repos/ossf/malicious-packages/tarball/main | tar -xz --strip-components=1 -C openssf-malicious-packages
21+
python3 scripts/build_openssf_index.py
22+
1623
build_and_publish_docker: &build_and_publish_docker
1724
persist_to_workspace: true
1825
cmd: |
@@ -36,11 +43,16 @@ workflows:
3643
name: install_trivy_and_download_dbs
3744
requires:
3845
- generate_and_test
46+
- codacy/shell:
47+
<<: *build_openssf_malicious_package_index
48+
name: build_openssf_malicious_package_index
49+
requires:
50+
- install_trivy_and_download_dbs
3951
- codacy/shell:
4052
<<: *build_and_publish_docker
4153
name: publish_docker_local
4254
requires:
43-
- install_trivy_and_download_dbs
55+
- build_openssf_malicious_package_index
4456
- codacy_plugins_test/run:
4557
name: plugins_test
4658
run_multiple_tests: true
@@ -84,11 +96,16 @@ workflows:
8496
name: install_trivy_and_download_dbs
8597
requires:
8698
- generate_and_test
99+
- codacy/shell:
100+
<<: *build_openssf_malicious_package_index
101+
name: build_openssf_malicious_package_index
102+
requires:
103+
- install_trivy_and_download_dbs
87104
- codacy/shell:
88105
<<: *build_and_publish_docker
89106
name: publish_docker_local
90107
requires:
91-
- install_trivy_and_download_dbs
108+
- build_openssf_malicious_package_index
92109
- codacy/publish_docker:
93110
name: publish_dockerhub
94111
context: CodacyDocker

.gitignore

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ project
1111
target
1212
bin
1313
cache
14+
openssf-malicious-packages
1415
*.gen.go
1516
.codacyrc
1617
trivy
1718

1819

19-
#Ignore vscode AI rules
20+
# Ignore vscode AI rules
2021
.github/copilot-instructions.md
2122

22-
#Ignore cursor AI rules
23-
.cursor/rules/codacy.mdc
23+
# Ignore cursor AI rules
24+
.cursor/rules/codacy.mdc
25+
26+
# Ignore codacy stuff
27+
.codacy/cli.sh
28+
.codacy/codacy.yaml
29+
30+
# Ignore patterns.json
31+
docs/patterns.json

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.25-alpine as builder
1+
FROM golang:1.25-alpine AS builder
22

33
ARG TRIVY_VERSION=dev
44
ENV TRIVY_VERSION=$TRIVY_VERSION
@@ -31,5 +31,6 @@ RUN adduser -u 2004 -D docker
3131
COPY --from=builder --chown=docker:docker /src/bin /dist/bin
3232
COPY --from=builder --chown=docker:docker /src/docs /docs
3333
COPY --chown=docker:docker cache/ /dist/cache/codacy-trivy
34+
COPY --chown=docker:docker openssf-malicious-packages/openssf-malicious-packages-index.json.gz /dist/cache/codacy-trivy/openssf-malicious-packages-index.json.gz
3435

3536
CMD [ "/dist/bin/codacy-trivy" ]

cmd/tool/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import (
55

66
codacy "github.com/codacy/codacy-engine-golang-seed/v6"
77
"github.com/codacy/codacy-trivy/internal/tool"
8+
"github.com/sirupsen/logrus"
89
)
910

1011
func main() {
11-
codacyTrivy := tool.New()
12-
retCode := codacy.StartTool(&codacyTrivy)
12+
codacyTrivy, err := tool.New(tool.MaliciousPackagesIndexPath)
13+
if err != nil {
14+
logrus.Errorf("Failed to create tool execution: %s", err.Error())
15+
os.Exit(-1)
16+
}
17+
18+
retCode := codacy.StartTool(codacyTrivy)
1319

1420
os.Exit(retCode)
1521
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Malicious packages detection
2+
Detects malicious packages identified in the OpenSSF Malicious Packages database, including typosquatting attacks, dependency confusion, and packages with malicious payloads.

docs/multiple-tests/all-patterns/patterns.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<module name="vulnerability_high" />
66
<module name="vulnerability_medium" />
77
<module name="vulnerability_minor" />
8+
<module name="malicious_packages" />
89
</module>

docs/multiple-tests/all-patterns/results.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@
4040
severity="warning"
4141
/>
4242
</file>
43-
</checkstyle>
43+
<file name="javascript/package-lock.json">
44+
<error
45+
source="malicious_packages"
46+
line="11"
47+
message="Malicious code in sdge-it-tdg-dynamicloadprofiles (npm) - [email protected]"
48+
severity="error"
49+
/>
50+
</file>
51+
</checkstyle>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
org.apache.logging.log4j:log4j-core:2.17.0
22
org.apache.dolphinscheduler:dolphinscheduler-task-api:3.2.1
33
org.apache.seatunnel:seatunnel:1.0.0
4-
org.apache.cxf:cxf-rt-transports-http:4.0.0
4+
org.apache.cxf:cxf-rt-transports-http:4.0.0
5+
npm:commitlint-pm2-proxima-dotenv-safe:1.0.0

docs/multiple-tests/all-patterns/src/javascript/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module name="root">
3+
<module name="malicious_packages" />
4+
</module>

0 commit comments

Comments
 (0)