Skip to content

Commit

Permalink
rules/sdk: allow packages with */crypto/* to import unsafe
Browse files Browse the repository at this point in the history
Cryptographic packages require crypto/rand and other seemingly
unsafe packages. This change removes those false positives by
checking that segments of the package's path contain "crypto" and if
so allow these "unsafe" packages.

Fixes #63
  • Loading branch information
odeke-em committed Oct 22, 2022
1 parent 2153c26 commit 05a47ad
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rules/sdk/blocklist.go
Expand Up @@ -16,6 +16,7 @@ package sdk

import (
"go/ast"
"path/filepath"
"strings"

"github.com/cosmos/gosec/v2"
Expand Down Expand Up @@ -48,6 +49,17 @@ func forbiddenFromBlockedImports(ctx *gosec.Context) bool {
// data for randomizing data.
return false
default:
pkgPath, err := gosec.GetPkgAbsPath(pkg)
if err != nil {
return true
}

splits := strings.Split(pkgPath, string(filepath.Separator))
for _, split := range splits {
if split == "crypto" {
return false
}
}
// Everything else is forbidden from unsafe imports.
return true
}
Expand Down

0 comments on commit 05a47ad

Please sign in to comment.