Skip to content

Commit e21b4d4

Browse files
authoredDec 17, 2024··
Rule documentation updates (#1272)
1 parent 92de0ee commit e21b4d4

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed
 

‎README.md

+2-23
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,9 @@ A number of global settings can be provided in a configuration file as follows:
211211
$ gosec -conf config.json .
212212
```
213213

214-
Also some rules accept configuration. For instance on rule `G104`, it is possible to define packages along with a list
215-
of functions which will be skipped when auditing the not checked errors:
214+
#### Rule Configuration
216215

217-
```JSON
218-
{
219-
"G104": {
220-
"ioutil": ["WriteFile"]
221-
}
222-
}
223-
```
224-
225-
You can also configure the hard-coded credentials rule `G101` with additional patterns, or adjust the entropy threshold:
226-
227-
```JSON
228-
{
229-
"G101": {
230-
"pattern": "(?i)passwd|pass|password|pwd|secret|private_key|token",
231-
"ignore_entropy": false,
232-
"entropy_threshold": "80.0",
233-
"per_char_threshold": "3.0",
234-
"truncate": "32"
235-
}
236-
}
237-
```
216+
Some rules accept configuration flags as well; these flags are documented in [RULES.md](https://github.com/securego/gosec/blob/master/RULES.md).
238217

239218
#### Go version
240219

‎RULES.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Rule Documentation
2+
3+
## Rules accepting parameters
4+
5+
As [README.md](https://github.com/securego/gosec/blob/master/README.md) mentions, some rules can be configured by adding parameters to the gosec JSON config. Per rule configs are encoded as top level objects in the gosec config, with the rule ID (`Gxxx`) as the key.
6+
7+
Currently, the following rules accept parameters. This list is manually maintained; if you notice an omission please add it!
8+
9+
### G101
10+
11+
The hard-coded credentials rule `G101` can be configured with additional patterns, and the entropy threshold can be adjusted:
12+
13+
```JSON
14+
{
15+
"G101": {
16+
"pattern": "(?i)passwd|pass|password|pwd|secret|private_key|token",
17+
"ignore_entropy": false,
18+
"entropy_threshold": "80.0",
19+
"per_char_threshold": "3.0",
20+
"truncate": "32"
21+
}
22+
}
23+
```
24+
25+
### G104
26+
27+
The unchecked error value rule `G104` can be configured with additional functions that should be permitted to be called without checking errors.
28+
29+
```JSON
30+
{
31+
"G104": {
32+
"ioutil": ["WriteFile"]
33+
}
34+
}
35+
```
36+
37+
### G111
38+
39+
The HTTP Directory serving rule `G111` can be configured with a different regex for detecting potentially overly permissive servers. Note that this *replaces* the default pattern of `http\.Dir\("\/"\)|http\.Dir\('\/'\)`.
40+
41+
```JSON
42+
{
43+
"G111": {
44+
"pattern": "http\\.Dir\\(\"\\\/\"\\)|http\\.Dir\\('\\\/'\\)"
45+
}
46+
}
47+
48+
```
49+
50+
### G301, G302, G306, G307
51+
52+
The various file and directory permission checking rules can be configured with a different maximum allowable file permission.
53+
54+
```JSON
55+
{
56+
"G301":"0o600",
57+
"G302":"0o600",
58+
"G306":"0o750",
59+
"G307":"0o750"
60+
}
61+
```

0 commit comments

Comments
 (0)
Please sign in to comment.