feat: replace TinyGo with standard Go for WebAssembly modules (#8496)

This commit is contained in:
Teppei Fukuda
2025-03-07 14:10:15 +04:00
committed by GitHub
parent fe09410ed4
commit 529957eac1
54 changed files with 337 additions and 521 deletions

View File

@@ -5,7 +5,7 @@ This module provides a more in-depth investigation of Spring4Shell detection.
## Set up
```
$ tinygo build -o spring4shell.wasm -scheduler=none -target=wasi --no-debug spring4shell.go
$ GOOS=wasip1 GOARCH=wasm go build -o spring4shell.wasm -buildmode=c-shared spring4shell.go
$ mkdir -p ~/.trivy/modules
$ cp spring4shell.wasm ~/.trivy/modules
```

View File

@@ -1,5 +1,5 @@
//go:generate tinygo build -o spring4shell.wasm -target=wasip1 --buildmode=c-shared spring4shell.go
//go:build tinygo.wasm
//go:generate go build -o spring4shell.wasm -buildmode=c-shared spring4shell.go
//go:build wasip1
package main
@@ -13,9 +13,11 @@ import (
"strconv"
"strings"
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/module/api"
"github.com/aquasecurity/trivy/pkg/module/serialize"
"github.com/aquasecurity/trivy/pkg/module/wasm"
"github.com/aquasecurity/trivy/pkg/types"
)
const (
@@ -29,6 +31,9 @@ var (
tomcatVersionRegex = regexp.MustCompile(`Apache Tomcat Version ([\d.]+)`)
)
// main is required for Go to compile the Wasm module
func main() {}
func init() {
wasm.RegisterModule(Spring4Shell{})
}
@@ -94,7 +99,7 @@ func (Spring4Shell) parseJavaRelease(f *os.File, filePath string) (*serialize.An
}
return &serialize.AnalysisResult{
CustomResources: []serialize.CustomResource{
CustomResources: []ftypes.CustomResource{
{
Type: TypeJavaMajor,
FilePath: filePath,
@@ -116,7 +121,7 @@ func (Spring4Shell) parseTomcatReleaseNotes(f *os.File, filePath string) (*seria
}
return &serialize.AnalysisResult{
CustomResources: []serialize.CustomResource{
CustomResources: []ftypes.CustomResource{
{
Type: TypeTomcatVersion,
FilePath: filePath,
@@ -221,7 +226,7 @@ func (Spring4Shell) PostScanSpec() serialize.PostScanSpec {
// }
//
// ]
func (Spring4Shell) PostScan(results serialize.Results) (serialize.Results, error) {
func (Spring4Shell) PostScan(results types.Results) (types.Results, error) {
var javaMajorVersion int
var tomcatVersion string
for _, result := range results {