Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .2ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ ignore-result:
- af16d5223104c029475f82cd780fd57115ed1e2f # value used for testing
- 91bc1fc92b04c56c5f746d50df5759e39b956146 # value used for testing
- 4d4af54fd6e3e1209094e5838f339b6c95636f79 # value used for testing
- fabcbd067a3bbf3cd5951d03ed4f17918241316a # value used for testing
- fabcbd067a3bbf3cd5951d03ed4f17918241316a # value used for testing
- cd186f025418cb008f61dcf881b62926be892f71 # value used for testing
- 3a2c9e23253b0e5b8a83deaea772d93396e4f350 # value used for testing
- 754506f714ffc10628e6fe6dd05affa486d78234 # value used for testing
- eebd28cd68ee73b9a1f68b85453575498c12c5b8 # value used for testing
- 14f5cf9d2716f2cec7daf95ab86e1a4feaf7ba41 # value used for testing
2 changes: 1 addition & 1 deletion .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
git diff --exit-code

- name: Go Linter
run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint run -v -E gofmt --timeout=5m --out-format github-actions
run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.1.5 golangci-lint run --timeout=5m

- name: Go Test
run: go test -v ./...
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# and "Missing User Instruction" since 2ms container is stopped after scan

# Builder image
FROM cgr.dev/chainguard/go@sha256:7f9e74e1af376a6d238077d8df037a25001997581630bc121c8aecfa5c8da8b3 AS builder
FROM checkmarx/go:1.24.4-r0-ae7309142bb6bd@sha256:ae7309142bb6bd82e0272c3624ec53c0c68d855f6b63e985c5caaff5c1705644 AS builder

WORKDIR /app

Expand All @@ -17,10 +17,10 @@ RUN go mod download
# COPY the source code as the last step
COPY . .

RUN GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o /app/2ms .
RUN GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w" -a -o /app/2ms .

# Runtime image
FROM cgr.dev/chainguard/git@sha256:fb9f28194b4dda3ea74c68d731238d1f32023849bca04c5652638e8e199fb956
FROM checkmarx/git:2.49.0-r2-d7ebbe7c56dc47@sha256:d7ebbe7c56dc478c08aba611c35b30689090d28605d83130ce4d1e15a84f0389

WORKDIR /app

Expand Down
13 changes: 7 additions & 6 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ func GetRulesCommand(engineConfig *EngineConfig) *cobra.Command {

tab := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)

fmt.Fprintln(tab, "Name\tDescription\tTags\tValidity Check")
fmt.Fprintln(tab, "----\t----\t----\t----")
fmt.Fprintln(tab, "Name\tDescription\tTags\tValidity Check") //nolint:errcheck
fmt.Fprintln(tab, "----\t----\t----\t----") //nolint:errcheck
for _, rule := range *rules {
fmt.Fprintf(
fmt.Fprintf( //nolint:errcheck
tab,
"%s\t%s\t%s\t%s\n",
rule.Rule.RuleID,
Expand Down Expand Up @@ -352,7 +352,8 @@ func getStartAndEndLines(ctx context.Context, pluginName string, gitInfo *plugin
var startLine, endLine int
var err error

if pluginName == "filesystem" {
switch pluginName {
case "filesystem":
totalLines, totalOK := ctx.Value(totalLinesKey).(int)
chunkLines, chunkOK := ctx.Value(linesInChunkKey).(int)

Expand All @@ -363,12 +364,12 @@ func getStartAndEndLines(ctx context.Context, pluginName string, gitInfo *plugin

startLine = value.StartLine + offset
endLine = value.EndLine + offset
} else if pluginName == "git" {
case "git":
startLine, endLine, err = plugins.GetGitStartAndEndLine(gitInfo, value.StartLine, value.EndLine)
if err != nil {
return 0, 0, err
}
} else {
default:
startLine = value.StartLine
endLine = value.EndLine
}
Expand Down
2 changes: 1 addition & 1 deletion engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func writeTempFile(t *testing.T, dir string, size int, content []byte) string {

f, err := os.CreateTemp(dir, "testfile-*.tmp")
require.NoError(t, err, "create temp file")
defer f.Close()
defer f.Close() //nolint:errcheck

var data []byte
if content != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/checkmarx/2ms/v3

go 1.23.6
go 1.24.4

require (
github.com/bwmarrin/discordgo v0.27.1
Expand Down
2 changes: 0 additions & 2 deletions lib/reporting/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ func TestWriteReportInNonExistingDir(t *testing.T) {
if err != nil {
t.Error(err)
}

os.RemoveAll(filepath.Join(tempDir, "test_temp_dir"))
}

func TestGetOutputSarif(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ subcommand:
var configFileName string
if tc.config != nil {
configFileName = writeTempFile(t, tc.config, tc.configFormat)
defer os.Remove(configFileName)
defer os.Remove(configFileName) //nolint:errcheck

tc.args = append(tc.args, "--"+configFlagName, configFileName)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func HttpRequest(method string, url string, authorization IAuthorizationHeader,
return nil, response, fmt.Errorf("unable to send http request %w", err)
}

defer response.Body.Close()
defer response.Body.Close() //nolint:errcheck

if response.StatusCode < 200 || response.StatusCode >= 300 {
if retry.MaxRetries > 0 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (p *GitPlugin) DefineCommand(items chan ISourceItem, errors chan error) (*c
Args: cobra.MatchAll(cobra.ExactArgs(1), validGitRepoArgs),
Run: func(cmd *cobra.Command, args []string) {
log.Info().Msg("Git plugin started")
p.scanGit(args[0], p.buildScanOptions(), p.Channels.Items, p.Channels.Errors)
p.scanGit(args[0], p.buildScanOptions(), p.Items, p.Errors)
p.WaitGroup.Wait()
close(items)
},
Expand Down
13 changes: 7 additions & 6 deletions plugins/paligo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (p *PaligoPlugin) DefineCommand(items chan ISourceItem, errors chan error)
Run: func(cmd *cobra.Command, args []string) {
// Waits for MarkFlagsOneRequired https://github.com/spf13/cobra/pull/1952
if p.auth == "" && (p.username == "" || p.token == "") {
p.Channels.Errors <- fmt.Errorf("exactly one of the flags in the group %v must be set; none were set", []string{paligoAuthFlag, paligoUsernameFlag, paligoTokenFlag})
p.Errors <- fmt.Errorf("exactly one of the flags in the group %v must be set; none were set", []string{paligoAuthFlag, paligoUsernameFlag, paligoTokenFlag})
return
}
log.Info().Msg("Paligo plugin started")
Expand Down Expand Up @@ -107,7 +107,7 @@ func (p *PaligoPlugin) getItems() {

foldersToProcess, err := p.getFirstProcessingFolders()
if err != nil {
p.Channels.Errors <- err
p.Errors <- err
return
}

Expand Down Expand Up @@ -156,14 +156,15 @@ func (p *PaligoPlugin) processFolders(foldersToProcess []PaligoItem) chan Paligo
folderInfo, err := p.paligoApi.showFolder(folder.ID)
if err != nil {
log.Error().Err(err).Msgf("error while getting %s '%s'", folder.Type, folder.Name)
p.Channels.Errors <- err
p.Errors <- err
continue
}

for _, child := range folderInfo.Children {
if child.Type == "component" {
switch child.Type {
case "component":
itemsChan <- child
} else if child.Type == "folder" {
case "folder":
foldersToProcess = append(foldersToProcess, child)
}
}
Expand All @@ -180,7 +181,7 @@ func (p *PaligoPlugin) handleComponent(paligoItem PaligoItem) {
document, err := p.paligoApi.showDocument(paligoItem.ID)
if err != nil {
log.Error().Err(err).Msgf("error while getting document '%s'", paligoItem.Name)
p.Channels.Errors <- fmt.Errorf("error while getting document '%s': %w", paligoItem.Name, err)
p.Errors <- fmt.Errorf("error while getting document '%s': %w", paligoItem.Name, err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (p *SlackPlugin) DefineCommand(items chan ISourceItem, errors chan error) (
Long: "Scan Slack team for sensitive information.",
Run: func(cmd *cobra.Command, args []string) {
p.getItems()
p.Channels.WaitGroup.Wait()
p.WaitGroup.Wait()
close(items)
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func lintFile(path string) error {
if err != nil {
return err
}
defer file.Close()
defer file.Close() //nolint:errcheck

scanner := bufio.NewScanner(file)
line := 1
Expand Down
Loading