Skip to content

Commit 05a47ad

Browse files
committed
rules/sdk: allow packages with */crypto/* to import unsafe
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
1 parent 2153c26 commit 05a47ad

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rules/sdk/blocklist.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package sdk
1616

1717
import (
1818
"go/ast"
19+
"path/filepath"
1920
"strings"
2021

2122
"github.com/cosmos/gosec/v2"
@@ -48,6 +49,17 @@ func forbiddenFromBlockedImports(ctx *gosec.Context) bool {
4849
// data for randomizing data.
4950
return false
5051
default:
52+
pkgPath, err := gosec.GetPkgAbsPath(pkg)
53+
if err != nil {
54+
return true
55+
}
56+
57+
splits := strings.Split(pkgPath, string(filepath.Separator))
58+
for _, split := range splits {
59+
if split == "crypto" {
60+
return false
61+
}
62+
}
5163
// Everything else is forbidden from unsafe imports.
5264
return true
5365
}

0 commit comments

Comments
 (0)