-
Notifications
You must be signed in to change notification settings - Fork 0
/
A5.go
32 lines (28 loc) · 991 Bytes
/
A5.go
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
package main
import (
"flag"
"fmt"
"log"
"os"
)
/*
In this example, the application is using a default configuration file path, which is "config.json", if the attacker can put a malicious config.json file in the same folder as the application, the attacker could manipulate the application's behavior.
It's always recommended to use a non-default, random and secure file paths, validate the config files content, and use a robust process to keep track of all configurations and security settings.
*/
func main() {
var conf = flag.String("config", "config.json", "Configuration file")
flag.Parse()
file, err := os.Open(*conf)
if err != nil {
log.Fatalf("Failed to open config file: %v", err)
}
// Vulnerable code
defer file.Close()
decoder := json.NewDecoder(file)
var config Config
err = decoder.Decode(&config)
if err != nil {
log.Fatalf("Failed to parse config file: %v", err)
}
// rest of the code
}