Skip to content

Commit

Permalink
Make /data path configurable
Browse files Browse the repository at this point in the history
- Permit disable /data path to prevent DoS attack
- Fixes #17
  • Loading branch information
wiltonsr committed Dec 18, 2023
1 parent a7324d7 commit 1af2589
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Heath check.
| `port` | `WHOAMI_PORT_NUMBER` | Give me a port number. (default: `80`) |
| `name` | `WHOAMI_NAME` | Give me a name. |
| `verbose` | | Enable verbose logging. |
| `no-data` | | Disable data handler. |

## Examples

Expand Down
7 changes: 7 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ var (
port string
name string
verbose bool
no_data bool
)

func init() {
flag.BoolVar(&verbose, "verbose", false, "Enable verbose logging")
flag.BoolVar(&no_data, "no-data", false, "Disable data handler")
flag.StringVar(&cert, "cert", "", "give me a certificate")
flag.StringVar(&key, "key", "", "give me a key")
flag.StringVar(&ca, "cacert", "", "give me a CA chain, enforces mutual TLS")
Expand Down Expand Up @@ -166,6 +168,11 @@ func printBinary(s []byte) {
}

func dataHandler(w http.ResponseWriter, r *http.Request) {
if no_data {
_, _ = fmt.Fprintln(w, "dataHandler disabled!")
return
}

queryParams := r.URL.Query()

size, err := strconv.ParseInt(queryParams.Get("size"), 10, 64)
Expand Down

0 comments on commit 1af2589

Please sign in to comment.