File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ package config
22
33import (
44 "fmt"
5- "github.com/spf13/viper"
65 "os"
76 "path/filepath"
87 "strings"
98 "time"
9+
10+ "github.com/spf13/viper"
1011)
1112
1213type Config struct {
@@ -46,7 +47,9 @@ func LoadConfig() (*Config, error) {
4647 setConfig ()
4748
4849 viper .SetEnvKeyReplacer (strings .NewReplacer (`.` , `_` ))
49- viper .BindEnv ("github.token" , "GITHUB_TOKEN" )
50+ if err := viper .BindEnv ("github.token" , "GITHUB_TOKEN" ); err != nil {
51+ return nil , fmt .Errorf ("failed to bind environment variable: %w" , err )
52+ }
5053 viper .AutomaticEnv ()
5154
5255 // Read the config file first
Original file line number Diff line number Diff line change 11package browser
22
33import (
4+ "errors"
5+ "net/url"
46 "os/exec"
57 "runtime"
68)
79
8- func OpenInBrowser (url string ) error {
10+ func OpenInBrowser (rawURL string ) error {
11+ // Validate the URL to prevent command injection
12+ parsedURL , err := url .Parse (rawURL )
13+ if err != nil || parsedURL .Scheme == "" || parsedURL .Host == "" {
14+ return errors .New ("invalid URL" )
15+ }
16+
917 var cmd string
1018 var args []string
1119
1220 switch runtime .GOOS {
1321 case "windows" :
1422 cmd = "cmd"
15- args = []string {"/c" , "start" }
23+ args = []string {"/c" , "start" , parsedURL . String () }
1624 case "darwin" :
1725 cmd = "open"
26+ args = []string {parsedURL .String ()}
1827 default : // "linux", "freebsd", "openbsd", "netbsd"
1928 cmd = "xdg-open"
29+ args = []string {parsedURL .String ()}
2030 }
21- args = append ( args , url )
22-
31+
32+ // #nosec G204 - URL is validated above and is safe to use
2333 return exec .Command (cmd , args ... ).Start ()
2434}
You can’t perform that action at this time.
0 commit comments