Skip to content

Commit 2ba1652

Browse files
committed
Add a bit of safeguard against malicious attacks
1 parent f7a5eab commit 2ba1652

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

killbrowser.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"log"
4+
"errors"
55
"net/http"
66

77
"github.com/gin-gonic/gin"
@@ -17,25 +17,31 @@ func killBrowserHandler(c *gin.Context) {
1717

1818
c.BindJSON(&data)
1919

20-
command, err := findBrowser(data.Process)
20+
if data.Process != "chrome" && data.Process != "chrom" {
21+
c.JSON(http.StatusBadRequest, errors.New("You can't kill the process"+data.Process))
22+
return
23+
}
2124

22-
log.Println(command)
25+
command, err := findBrowser(data.Process)
2326

2427
if err != nil {
2528
c.JSON(http.StatusInternalServerError, err.Error())
29+
return
2630
}
2731

2832
if data.Action == "kill" || data.Action == "restart" {
2933
_, err := killBrowser(data.Process)
3034
if err != nil {
3135
c.JSON(http.StatusInternalServerError, err.Error())
36+
return
3237
}
3338
}
3439

3540
if data.Action == "restart" {
3641
_, err := startBrowser(command, data.URL)
3742
if err != nil {
3843
c.JSON(http.StatusInternalServerError, err.Error())
44+
return
3945
}
4046
}
4147

0 commit comments

Comments
 (0)