-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path_gosec
213 lines (206 loc) · 9.27 KB
/
_gosec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#compdef gosec
# -----------------------------------------------------------------------------
# The BSD-3-Clause License
#
# Copyright (c) 2017, Koichi Shiraishi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of que nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# github.com/securego/gosec/v2/cmd/gosec
#
# -----------------------------------------------------------------------------
function _gosec() {
local context curcontext=$curcontext state line ret=1
declare -A opt_args
local -a rules
rules=(
"G101:Look for hardcoded credentials"
"G102:Bind to all interfaces"
"G103:Audit the use of unsafe block"
"G104:Audit errors not checked"
"G106:Audit the use of ssh.InsecureIgnoreHostKey function"
"G107:Url provided to HTTP request as taint input"
"G108:Profiling endpoint is automatically exposed"
"G109:Converting strconv.Atoi result to int32/int16"
"G110:Detect io.Copy instead of io.CopyN when decompression"
"G201:SQL query construction using format string"
"G202:SQL query construction using string concatenation"
"G203:Use of unescaped data in HTML templates"
"G204:Audit use of command execution"
"G301:Poor file permissions used when creating a directory"
"G302:Poor file permissions used when creation file or using chmod"
"G303:Creating tempfile using a predictable path"
"G304:File path provided as taint input"
"G305:File path traversal when extracting zip archive"
"G306:Poor file permissions used when writing to a file"
"G307:Unsafe defer call of a method returning an error"
"G401:Detect the usage of DES, RC4, MD5 or SHA1"
"G402:Look for bad TLS connection settings"
"G403:Ensure minimum RSA key length of 2048 bits"
"G404:Insecure random number source (rand)"
"G501:Import blocklist: crypto/md5"
"G502:Import blocklist: crypto/des"
"G503:Import blocklist: crypto/rc4"
"G504:Import blocklist: net/http/cgi"
"G505:Import blocklist: crypto/sha1"
"G601:Implicit memory aliasing in RangeStmt"
)
_arguments -C \
"-color[Prints the text format report with colorization when it goes in the stdout (default true)]" \
"-conf[Path to optional config file]:config file:_files" \
"-confidence[Filter out the issues with a lower confidence than the given value. (default \"low\")]:confidence value:(low medium high)" \
"-exclude[Comma separated list of rules IDs to exclude. (see rule list)]:exclude rules:{_alternative rules}" \
"-exclude-dir[Exclude folder from scan (can be specified multiple times)]:exclude directory:_directories" \
"-fmt[Set output format. (default \"text\")]:format:(json yaml csv junit-xml html sonarqube golint sarif text)" \
"-include[Comma separated list of rules IDs to include. (see rule list)]:include rules:{_alternative rules}" \
"-log[Log messages to file rather than stderr]:path:_files" \
"-no-fail[Do not fail the scanning, even if issues were found]" \
"-nosec[Ignores #nosec comments when set]" \
"-nosec-tag[Set an alternative string for #nosec. Some examples: #dontanalyze, #falsepositive]:nosec tags" \
"-out[Set output file for results]:output filepath:_files" \
"-quiet[Only show output when errors are found]" \
"-severity[Filter out the issues with a lower severity than the given value. (default \"low\")]:severity:(low medium high)" \
"-sort[Sort issues by severity (default true)]" \
"-stdout[Stdout the results as well as write it in the output file]" \
"-tags[Comma separated list of build tags]:build tags" \
"-tests[Scan tests files]" \
"-verbose[Overrides the output format when stdout the results while saving them in the output file.]:format:(json yaml csv junit-xml html sonarqube golint sarif text)" \
"-version[Print version and quit with exit code 0]" \
'*:file:_files' \
&& ret=0
return ret
}
_gosec "$*"
# -----------------------------------------------------------------------------
#
# gosec - Golang security checker
#
# gosec analyzes Go source code to look for common programming mistakes that
# can lead to security problems.
#
# VERSION: dev
# GIT TAG:
# BUILD DATE:
#
# USAGE:
#
# # Check a single package
# $ gosec $GOPATH/src/github.com/example/project
#
# # Check all packages under the current directory and save results in
# # json format.
# $ gosec -fmt=json -out=results.json ./...
#
# # Run a specific set of rules (by default all rules will be run):
# $ gosec -include=G101,G203,G401 ./...
#
# # Run all rules except the provided
# $ gosec -exclude=G101 $GOPATH/src/github.com/example/project/...
#
#
# OPTIONS:
#
# -color
# Prints the text format report with colorization when it goes in the stdout (default true)
# -conf string
# Path to optional config file
# -confidence string
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high (default "low")
# -exclude string
# Comma separated list of rules IDs to exclude. (see rule list)
# -exclude-dir value
# Exclude folder from scan (can be specified multiple times)
# -fmt string
# Set output format. Valid options are: json, yaml, csv, junit-xml, html, sonarqube, golint, sarif or text (default "text")
# -include string
# Comma separated list of rules IDs to include. (see rule list)
# -log string
# Log messages to file rather than stderr
# -no-fail
# Do not fail the scanning, even if issues were found
# -nosec
# Ignores #nosec comments when set
# -nosec-tag string
# Set an alternative string for #nosec. Some examples: #dontanalyze, #falsepositive
# -out string
# Set output file for results
# -quiet
# Only show output when errors are found
# -severity string
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high (default "low")
# -sort
# Sort issues by severity (default true)
# -stdout
# Stdout the results as well as write it in the output file
# -tags string
# Comma separated list of build tags
# -tests
# Scan tests files
# -verbose string
# Overrides the output format when stdout the results while saving them in the output file.
# Valid options are: json, yaml, csv, junit-xml, html, sonarqube, golint, sarif or text
# -version
# Print version and quit with exit code 0
#
#
# RULES:
#
# G101: Look for hardcoded credentials
# G102: Bind to all interfaces
# G103: Audit the use of unsafe block
# G104: Audit errors not checked
# G106: Audit the use of ssh.InsecureIgnoreHostKey function
# G107: Url provided to HTTP request as taint input
# G108: Profiling endpoint is automatically exposed
# G109: Converting strconv.Atoi result to int32/int16
# G110: Detect io.Copy instead of io.CopyN when decompression
# G201: SQL query construction using format string
# G202: SQL query construction using string concatenation
# G203: Use of unescaped data in HTML templates
# G204: Audit use of command execution
# G301: Poor file permissions used when creating a directory
# G302: Poor file permissions used when creation file or using chmod
# G303: Creating tempfile using a predictable path
# G304: File path provided as taint input
# G305: File path traversal when extracting zip archive
# G306: Poor file permissions used when writing to a file
# G307: Unsafe defer call of a method returning an error
# G401: Detect the usage of DES, RC4, MD5 or SHA1
# G402: Look for bad TLS connection settings
# G403: Ensure minimum RSA key length of 2048 bits
# G404: Insecure random number source (rand)
# G501: Import blocklist: crypto/md5
# G502: Import blocklist: crypto/des
# G503: Import blocklist: crypto/rc4
# G504: Import blocklist: net/http/cgi
# G505: Import blocklist: crypto/sha1
# G601: Implicit memory aliasing in RangeStmt
#
# -----------------------------------------------------------------------------
# vim:ft=zsh:et:sts=2:sw=2