You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this change, the tweaked example shows how an attacker can make the code read from an unsafe path by adding `..` to their path.
Signed-off-by: Dan Kenigsberg <danken@redhat.com>
Trying to open a file provided as an input in a variable. The content of this variable might be controlled by an attacker who could change it to hold unauthorised file paths from the system. In this way, it is possible to exfiltrate confidential information or such.
7
7
8
8
## Example problematic code:
9
-
9
+
This code lets an attacker read a `/private/path`
10
10
```
11
11
package main
12
12
@@ -17,7 +17,10 @@ import (
17
17
)
18
18
19
19
func main() {
20
-
repoFile := "path_of_file"
20
+
repoFile := "/safe/path/../../private/path"
21
+
if !strings.HasPrefix(repoFile, "/safe/path/") {
22
+
panic(fmt.Errorf("Unsafe input"))
23
+
}
21
24
byContext, err := ioutil.ReadFile(repoFile)
22
25
if err != nil {
23
26
panic(err)
@@ -34,7 +37,7 @@ func main() {
34
37
```
35
38
36
39
## The right way
37
-
40
+
This code panics if `/safe/path` was removed by an attacker
0 commit comments