-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsecure-dir-creation.yaml
45 lines (45 loc) · 1.51 KB
/
insecure-dir-creation.yaml
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
rules:
- id: insecure-dir-creation
message: A file or directory `$FI` with restrictive permissions was created
without checking if `$FI` already exists. Creating a file or directory without
checking if it exists first will not overwrite permission
languages: [go]
severity: WARNING
metadata:
cwe:
- "CWE-59: Improper Link Resolution Before File Access ('Link Following')"
- "CWE-281: Improper Preservation of Permissions"
category: security
subcategory:
- vuln
confidence: HIGH
impact: MEDIUM
likelihood: MEDIUM
technology:
- go
description: "Insecure handling of file and directory writes"
references:
- https://github.com/golang/go/issues/35711
patterns:
- pattern-either:
- pattern: ioutil.WriteFile($PATH, ..., $PERM)
- pattern: os.WriteFile($PATH, ..., $PERM)
- pattern: os.MkdirAll($PATH, $PERM)
- pattern: os.Mkdir($PATH, $PERM)
- pattern-not-inside: |
if ..., $ERR := os.Stat($PATH); os.IsNotExist($ERR) {
...
}
- pattern-not-inside: |
$FI, $ERR := os.Stat($PATH)
if $ERR != nil && os.IsNotExist(...) {
...
}
- pattern-not-inside: |
$FI, $ERR := os.Stat($PATH)
if $ERR != nil && os.IsNotExist(...) {
...
}
- metavariable-comparison:
comparison: int($PERM) < 0o600 or int($PERM) == 0o700
metavariable: $PERM