Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http headers challenge #32

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions challenges/http-cookies/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions challenges/http-cookies/serve/server.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

jwt-alg-none-bypass
http-misconfigurations
23 changes: 23 additions & 0 deletions challenges/http-misconfigurations/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.23 AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./

RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o /http-misconfigurations .

FROM gcr.io/distroless/static-debian11:nonroot AS runner

WORKDIR /

COPY --from=builder --chown=nonroot:nonroot /http-misconfigurations /usr/bin/http-misconfigurations

EXPOSE 8080

USER nonroot:nonroot

ENTRYPOINT ["http-misconfigurations"]
CMD ["serve"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"os"

"github.com/cerberauth/api-vulns-challenges/challenges/http-cookies/cmd/serve"
"github.com/cerberauth/api-vulns-challenges/challenges/http-misconfigurations/cmd/serve"

"github.com/spf13/cobra"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package serve
import (
"github.com/spf13/cobra"

"github.com/cerberauth/api-vulns-challenges/challenges/http-cookies/serve"
"github.com/cerberauth/api-vulns-challenges/challenges/http-misconfigurations/serve"
)

var (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cerberauth/api-vulns-challenges/challenges/http-cookies
module github.com/cerberauth/api-vulns-challenges/challenges/http-misconfigurations

go 1.20

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/cerberauth/api-vulns-challenges/challenges/http-cookies/cmd"
import "github.com/cerberauth/api-vulns-challenges/challenges/http-misconfigurations/cmd"

func main() {
cmd.Execute()
Expand Down
81 changes: 81 additions & 0 deletions challenges/http-misconfigurations/serve/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package serve

import (
"log"
"net/http"
"time"
)

func RunServer(port string) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

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", "*")
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/headers/csp-frame-ancestors", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Security-Policy", "frame-ancestors 'http://example.com'")
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/cookies/unsecure", func(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: "unsecure",
Value: "unsecure",
SameSite: http.SameSiteStrictMode,
Secure: false,
HttpOnly: true,
Expires: time.Now().Add(24 * time.Hour),
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/cookies/not-httponly", func(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: "unsecure",
Value: "unsecure",
SameSite: http.SameSiteStrictMode,
HttpOnly: false,
Secure: true,
Expires: time.Now().Add(24 * time.Hour),
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/cookies/samesite-none", func(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: "unsecure",
Value: "unsecure",
SameSite: http.SameSiteNoneMode,
HttpOnly: true,
Secure: true,
Expires: time.Now().Add(24 * time.Hour),
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

http.HandleFunc("/cookies/no-expiration", func(w http.ResponseWriter, r *http.Request) {
// set unsecure cookie
http.SetCookie(w, &http.Cookie{
Name: "unsecure",
Value: "unsecure",
SameSite: http.SameSiteStrictMode,
HttpOnly: true,
Secure: true,
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

log.Println("Server started at port", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}