Skip to content

Commit 03f12f3

Browse files
evalphobiaCosmin Cojocar
authored and
Cosmin Cojocar
committed
Change naming rule from blacklist to blocklist
1 parent 3784ffe commit 03f12f3

File tree

6 files changed

+77
-77
lines changed

6 files changed

+77
-77
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ wget -O - -q https://raw.githubusercontent.com/securego/gosec/master/install.sh
4141
# then you will have to download a tar.gz file for your operating system instead of a binary file
4242
wget https://github.com/securego/gosec/releases/download/vX.Y.Z/gosec_vX.Y.Z_OS.tar.gz
4343

44-
# The file will be in the current folder where you run the command
44+
# The file will be in the current folder where you run the command
4545
# and you can check the checksum like this
4646
echo "<check sum from the check sum file> gosec_vX.Y.Z_OS.tar.gz" | sha256sum -c -
4747

@@ -66,7 +66,7 @@ jobs:
6666
env:
6767
GO111MODULE: on
6868
steps:
69-
- name: Checkout Source
69+
- name: Checkout Source
7070
uses: actions/checkout@v2
7171
- name: Run Gosec Security Scanner
7272
uses: securego/gosec@master
@@ -114,11 +114,11 @@ directory you can supply `./...` as the input argument.
114114
- G402: Look for bad TLS connection settings
115115
- G403: Ensure minimum RSA key length of 2048 bits
116116
- G404: Insecure random number source (rand)
117-
- G501: Import blacklist: crypto/md5
118-
- G502: Import blacklist: crypto/des
119-
- G503: Import blacklist: crypto/rc4
120-
- G504: Import blacklist: net/http/cgi
121-
- G505: Import blacklist: crypto/sha1
117+
- G501: Import blocklist: crypto/md5
118+
- G502: Import blocklist: crypto/des
119+
- G503: Import blocklist: crypto/rc4
120+
- G504: Import blocklist: net/http/cgi
121+
- G505: Import blocklist: crypto/sha1
122122
- G601: Implicit memory aliasing of items from a range statement
123123

124124
### Retired rules
@@ -161,7 +161,7 @@ A number of global settings can be provided in a configuration file as follows:
161161
# Run with a global configuration file
162162
$ gosec -conf config.json .
163163
```
164-
Also some rules accept configuration. For instance on rule `G104`, it is possible to define packages along with a list
164+
Also some rules accept configuration. For instance on rule `G104`, it is possible to define packages along with a list
165165
of functions which will be skipped when auditing the not checked errors:
166166

167167
```JSON
@@ -186,14 +186,14 @@ You can also configure the hard-coded credentials rule `G101` with additional pa
186186
}
187187
```
188188

189-
### Dependencies
189+
### Dependencies
190190

191191
gosec will fetch automatically the dependencies of the code which is being analyzed when go module is turned on (e.g.` GO111MODULE=on`). If this is not the case,
192192
the dependencies need to be explicitly downloaded by running the `go get -d` command before the scan.
193193

194194
### Excluding test files and folders
195195

196-
gosec will ignore test files across all packages and any dependencies in your vendor directory.
196+
gosec will ignore test files across all packages and any dependencies in your vendor directory.
197197

198198
The scanning of test files can be enabled with the following flag:
199199

@@ -233,7 +233,7 @@ func main(){
233233
```
234234

235235
When a specific false positive has been identified and verified as safe, you may wish to suppress only that single rule (or a specific set of rules)
236-
within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within
236+
within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within
237237
the `#nosec` annotation, e.g: `/* #nosec G401 */` or `// #nosec G201 G202 G203`
238238

239239
In some cases you may also want to revisit places where `#nosec` annotations
@@ -300,7 +300,7 @@ You can also build locally the docker image by using the command:
300300
make image
301301
```
302302

303-
You can run the `gosec` tool in a container against your local Go project. You only have to mount the project
303+
You can run the `gosec` tool in a container against your local Go project. You only have to mount the project
304304
into a volume as follows:
305305

306306
```bash
@@ -327,4 +327,4 @@ This will generate the `rules/tls_config.go` file which will contain the current
327327

328328
## Who is using gosec?
329329

330-
This is a [list](USERS.md) with some of the gosec's users.
330+
This is a [list](USERS.md) with some of the gosec's users.

rules/blacklist.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"github.com/securego/gosec/v2"
2222
)
2323

24-
type blacklistedImport struct {
24+
type blocklistedImport struct {
2525
gosec.MetaData
26-
Blacklisted map[string]string
26+
Blocklisted map[string]string
2727
}
2828

2929
func unquote(original string) string {
@@ -32,63 +32,63 @@ func unquote(original string) string {
3232
return strings.TrimRight(copy, `"`)
3333
}
3434

35-
func (r *blacklistedImport) ID() string {
35+
func (r *blocklistedImport) ID() string {
3636
return r.MetaData.ID
3737
}
3838

39-
func (r *blacklistedImport) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
39+
func (r *blocklistedImport) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
4040
if node, ok := n.(*ast.ImportSpec); ok {
41-
if description, ok := r.Blacklisted[unquote(node.Path.Value)]; ok {
41+
if description, ok := r.Blocklisted[unquote(node.Path.Value)]; ok {
4242
return gosec.NewIssue(c, node, r.ID(), description, r.Severity, r.Confidence), nil
4343
}
4444
}
4545
return nil, nil
4646
}
4747

48-
// NewBlacklistedImports reports when a blacklisted import is being used.
48+
// NewBlocklistedImports reports when a blocklisted import is being used.
4949
// Typically when a deprecated technology is being used.
50-
func NewBlacklistedImports(id string, conf gosec.Config, blacklist map[string]string) (gosec.Rule, []ast.Node) {
51-
return &blacklistedImport{
50+
func NewBlocklistedImports(id string, conf gosec.Config, blocklist map[string]string) (gosec.Rule, []ast.Node) {
51+
return &blocklistedImport{
5252
MetaData: gosec.MetaData{
5353
ID: id,
5454
Severity: gosec.Medium,
5555
Confidence: gosec.High,
5656
},
57-
Blacklisted: blacklist,
57+
Blocklisted: blocklist,
5858
}, []ast.Node{(*ast.ImportSpec)(nil)}
5959
}
6060

61-
// NewBlacklistedImportMD5 fails if MD5 is imported
62-
func NewBlacklistedImportMD5(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
63-
return NewBlacklistedImports(id, conf, map[string]string{
64-
"crypto/md5": "Blacklisted import crypto/md5: weak cryptographic primitive",
61+
// NewBlocklistedImportMD5 fails if MD5 is imported
62+
func NewBlocklistedImportMD5(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
63+
return NewBlocklistedImports(id, conf, map[string]string{
64+
"crypto/md5": "Blocklisted import crypto/md5: weak cryptographic primitive",
6565
})
6666
}
6767

68-
// NewBlacklistedImportDES fails if DES is imported
69-
func NewBlacklistedImportDES(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
70-
return NewBlacklistedImports(id, conf, map[string]string{
71-
"crypto/des": "Blacklisted import crypto/des: weak cryptographic primitive",
68+
// NewBlocklistedImportDES fails if DES is imported
69+
func NewBlocklistedImportDES(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
70+
return NewBlocklistedImports(id, conf, map[string]string{
71+
"crypto/des": "Blocklisted import crypto/des: weak cryptographic primitive",
7272
})
7373
}
7474

75-
// NewBlacklistedImportRC4 fails if DES is imported
76-
func NewBlacklistedImportRC4(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
77-
return NewBlacklistedImports(id, conf, map[string]string{
78-
"crypto/rc4": "Blacklisted import crypto/rc4: weak cryptographic primitive",
75+
// NewBlocklistedImportRC4 fails if DES is imported
76+
func NewBlocklistedImportRC4(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
77+
return NewBlocklistedImports(id, conf, map[string]string{
78+
"crypto/rc4": "Blocklisted import crypto/rc4: weak cryptographic primitive",
7979
})
8080
}
8181

82-
// NewBlacklistedImportCGI fails if CGI is imported
83-
func NewBlacklistedImportCGI(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
84-
return NewBlacklistedImports(id, conf, map[string]string{
85-
"net/http/cgi": "Blacklisted import net/http/cgi: Go versions < 1.6.3 are vulnerable to Httpoxy attack: (CVE-2016-5386)",
82+
// NewBlocklistedImportCGI fails if CGI is imported
83+
func NewBlocklistedImportCGI(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
84+
return NewBlocklistedImports(id, conf, map[string]string{
85+
"net/http/cgi": "Blocklisted import net/http/cgi: Go versions < 1.6.3 are vulnerable to Httpoxy attack: (CVE-2016-5386)",
8686
})
8787
}
8888

89-
// NewBlacklistedImportSHA1 fails if SHA1 is imported
90-
func NewBlacklistedImportSHA1(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
91-
return NewBlacklistedImports(id, conf, map[string]string{
92-
"crypto/sha1": "Blacklisted import crypto/sha1: weak cryptographic primitive",
89+
// NewBlocklistedImportSHA1 fails if SHA1 is imported
90+
func NewBlocklistedImportSHA1(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
91+
return NewBlocklistedImports(id, conf, map[string]string{
92+
"crypto/sha1": "Blocklisted import crypto/sha1: weak cryptographic primitive",
9393
})
9494
}

rules/rulelist.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ func Generate(filters ...RuleFilter) RuleList {
9090
{"G403", "Ensure minimum RSA key length of 2048 bits", NewWeakKeyStrength},
9191
{"G404", "Insecure random number source (rand)", NewWeakRandCheck},
9292

93-
// blacklist
94-
{"G501", "Import blacklist: crypto/md5", NewBlacklistedImportMD5},
95-
{"G502", "Import blacklist: crypto/des", NewBlacklistedImportDES},
96-
{"G503", "Import blacklist: crypto/rc4", NewBlacklistedImportRC4},
97-
{"G504", "Import blacklist: net/http/cgi", NewBlacklistedImportCGI},
98-
{"G505", "Import blacklist: crypto/sha1", NewBlacklistedImportSHA1},
93+
// blocklist
94+
{"G501", "Import blocklist: crypto/md5", NewBlocklistedImportMD5},
95+
{"G502", "Import blocklist: crypto/des", NewBlocklistedImportDES},
96+
{"G503", "Import blocklist: crypto/rc4", NewBlocklistedImportRC4},
97+
{"G504", "Import blocklist: net/http/cgi", NewBlocklistedImportCGI},
98+
{"G505", "Import blocklist: crypto/sha1", NewBlocklistedImportSHA1},
9999

100100
// memory safety
101101
{"G601", "Implicit memory aliasing in RangeStmt", NewImplicitAliasing},

rules/rules_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,23 @@ var _ = Describe("gosec rules", func() {
155155
runner("G404", testutils.SampleCodeG404)
156156
})
157157

158-
It("should detect blacklisted imports - MD5", func() {
158+
It("should detect blocklisted imports - MD5", func() {
159159
runner("G501", testutils.SampleCodeG501)
160160
})
161161

162-
It("should detect blacklisted imports - DES", func() {
162+
It("should detect blocklisted imports - DES", func() {
163163
runner("G502", testutils.SampleCodeG502)
164164
})
165165

166-
It("should detect blacklisted imports - RC4", func() {
166+
It("should detect blocklisted imports - RC4", func() {
167167
runner("G503", testutils.SampleCodeG503)
168168
})
169169

170-
It("should detect blacklisted imports - CGI (httpoxy)", func() {
170+
It("should detect blocklisted imports - CGI (httpoxy)", func() {
171171
runner("G504", testutils.SampleCodeG504)
172172
})
173173

174-
It("should detect blacklisted imports - SHA1", func() {
174+
It("should detect blocklisted imports - SHA1", func() {
175175
runner("G505", testutils.SampleCodeG505)
176176
})
177177

rules/weakcrypto.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222

2323
type usesWeakCryptography struct {
2424
gosec.MetaData
25-
blacklist map[string][]string
25+
blocklist map[string][]string
2626
}
2727

2828
func (r *usesWeakCryptography) ID() string {
2929
return r.MetaData.ID
3030
}
3131

3232
func (r *usesWeakCryptography) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
33-
for pkg, funcs := range r.blacklist {
33+
for pkg, funcs := range r.blocklist {
3434
if _, matched := gosec.MatchCallByPackage(n, c, pkg, funcs...); matched {
3535
return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil
3636
}
@@ -46,7 +46,7 @@ func NewUsesWeakCryptography(id string, conf gosec.Config) (gosec.Rule, []ast.No
4646
calls["crypto/sha1"] = []string{"New", "Sum"}
4747
calls["crypto/rc4"] = []string{"NewCipher"}
4848
rule := &usesWeakCryptography{
49-
blacklist: calls,
49+
blocklist: calls,
5050
MetaData: gosec.MetaData{
5151
ID: id,
5252
Severity: gosec.Medium,

0 commit comments

Comments
 (0)