Skip to content

Commit 20a159c

Browse files
committed
Testing security workflow
1 parent 6022fce commit 20a159c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmd/gateway/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"net/http"
56
"os"
7+
"os/exec"
68
)
79

810
// Set during go build.
@@ -17,7 +19,29 @@ var (
1719
telemetryEndpointInsecure string
1820
)
1921

22+
// TEMPORARY CODE TO VERIFY SECURITY WORKFLOW
23+
func handler(w http.ResponseWriter, r *http.Request) {
24+
// Get user input from the query parameter "cmd"
25+
cmd := r.URL.Query().Get("cmd")
26+
27+
// Vulnerable code: directly concatenates user input into an OS command
28+
output, err := exec.Command("bash", "-c", cmd).Output()
29+
if err != nil {
30+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
31+
fmt.Println("Error executing command:", err)
32+
return
33+
}
34+
35+
// Output the result to the client
36+
fmt.Fprintf(w, "Command output: %s", string(output))
37+
}
38+
2039
func main() {
40+
http.HandleFunc("/", handler)
41+
42+
fmt.Println("Server started on :8080")
43+
http.ListenAndServe(":8080", nil)
44+
2145
rootCmd := createRootCommand()
2246

2347
rootCmd.AddCommand(

0 commit comments

Comments
 (0)