Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed May 19, 2024
1 parent e50810a commit 18f5382
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package main

import (
"log"

"github.com/coreruleset/albedo/cmd"
)

func main() {
cmd.Execute()
if err := cmd.Execute(); err != nil {
log.Fatal(err.Error())
}
}
31 changes: 25 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,20 @@ func handleReflect(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Failed to parse request body"))
_, err = w.Write([]byte("Failed to parse request body"))
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
log.Println("Failed to parse request body")
return
}
spec := &reflectionSpec{}
if err = json.Unmarshal(body, spec); err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Invalid JSON in request body"))
_, err = w.Write([]byte("Invalid JSON in request body"))
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
log.Println("Invalid JSON in request body")
return
}
Expand All @@ -117,7 +123,10 @@ func handleReflect(w http.ResponseWriter, r *http.Request) {

if spec.Status > 0 && spec.Status < 100 || spec.Status >= 600 {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Invalid status code: %d", spec.Status)))
_, err = w.Write([]byte(fmt.Sprintf("Invalid status code: %d", spec.Status)))
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
log.Printf("Invalid status code: %d", spec.Status)
return
}
Expand All @@ -131,7 +140,10 @@ func handleReflect(w http.ResponseWriter, r *http.Request) {
responseBody, err := decodeBody(spec)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
_, err = w.Write([]byte(err.Error()))
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
log.Println(err.Error())
return
}
Expand All @@ -145,7 +157,10 @@ func handleReflect(w http.ResponseWriter, r *http.Request) {
responseBody = responseBody[:min(len(responseBody), 200)] + "..."
}
log.Printf("Reflecting body '%s'", responseBody)
w.Write(responseBodyBytes)
_, err = w.Write(responseBodyBytes)

Check warning

Code scanning / CodeQL

Reflected cross-site scripting Medium

Cross-site scripting vulnerability due to
user-provided value
.
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
}

func handleCapabilities(w http.ResponseWriter, r *http.Request) {
Expand All @@ -169,7 +184,11 @@ func handleCapabilities(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Fatal("Failed to marshal capabilities")
}
w.Write(body)

_, err = w.Write(body)
if err != nil {
log.Printf("Failed to write response body: %s", err.Error())
}
}

func decodeBody(spec *reflectionSpec) (string, error) {
Expand Down

0 comments on commit 18f5382

Please sign in to comment.