fix!: bug where it was possible to send text unauthenticated

This commit is contained in:
jabuxas 2024-11-02 01:34:52 -03:00
parent b73c06f1ab
commit 6c301cff0c
3 changed files with 6 additions and 10 deletions

View File

@ -100,12 +100,4 @@ func setupHandlers(mux *http.ServeMux, app *Application) {
mux.HandleFunc("/token", BasicAuth(app.createTokenHandler, app)) mux.HandleFunc("/token", BasicAuth(app.createTokenHandler, app))
mux.HandleFunc("/files/", app.fileHandler) mux.HandleFunc("/files/", app.fileHandler)
if app.authUpload == "yes" {
mux.HandleFunc("/upload", BasicAuth(app.uploadHandler, app))
slog.Warn("text uploading will be restricted")
} else {
mux.HandleFunc("/upload", app.uploadHandler)
slog.Warn("text uploading will NOT be restricted")
}
} }

View File

@ -137,7 +137,11 @@ func (app *Application) lastUploadedHandler(w http.ResponseWriter, r *http.Reque
func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) { func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
if contentType := r.Header.Get("Content-Type"); contentType == "application/x-www-form-urlencoded" { if contentType := r.Header.Get("Content-Type"); contentType == "application/x-www-form-urlencoded" {
app.formHandler(w, r) if app.authUpload == "yes" {
BasicAuth(app.formHandler, app)(w, r)
} else {
app.formHandler(w, r)
}
} else if strings.Split(contentType, ";")[0] == "multipart/form-data" { } else if strings.Split(contentType, ";")[0] == "multipart/form-data" {
app.curlHandler(w, r) app.curlHandler(w, r)
} else { } else {

View File

@ -20,7 +20,7 @@
</a> </a>
</div> </div>
<form action="/upload" method="POST"> <form action="/" method="POST">
<textarea name="content" placeholder="Enter your content here..."></textarea> <textarea name="content" placeholder="Enter your content here..."></textarea>
<br /> <br />
<button type="submit">upload</button> <button type="submit">upload</button>