Skip to content

Commit

Permalink
Merge pull request #34 from cerberauth/http-method-override
Browse files Browse the repository at this point in the history
Add HTTP method override challenge
  • Loading branch information
emmanuelgautier authored Oct 22, 2024
2 parents adc73b0 + 98a5927 commit fb6c6a2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion challenges/http-misconfigurations/serve/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ func RunServer(port string) {
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/http-method-override", func(w http.ResponseWriter, r *http.Request) {
validToken := "valid-token"
if r.Header.Get("Authorization") != "Bearer "+validToken {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}

w.Header().Set("Content-Type", "application/json")
if r.Method == http.MethodGet || r.Header.Get("X-HTTP-Method-Override") == http.MethodGet || r.URL.Query().Get("_method") == http.MethodGet {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "GET method"}`))
} else {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
}
})

http.HandleFunc("/headers/cors-wildcard", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down Expand Up @@ -64,7 +80,6 @@ func RunServer(port string) {
})

http.HandleFunc("/cookies/no-expiration", func(w http.ResponseWriter, r *http.Request) {
// set unsecure cookie
http.SetCookie(w, &http.Cookie{
Name: "unsecure",
Value: "unsecure",
Expand Down

0 comments on commit fb6c6a2

Please sign in to comment.