Import Anubis v1.28.2

Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3).
Masyunis customizations are re-applied in the following commits.
This commit is contained in:
sol_bot Bot committed 2026-11-28 14:52:26 +03:00
1 parent eb3e46d8d0
commit e07de898cd
573 files changed
+35846 -6807

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
package lib
import (
"errors"
"io"
"log/slog"
"net/http"
)
func prepareChallengeForm(w http.ResponseWriter, r *http.Request) bool {
r.Body = http.MaxBytesReader(w, r.Body, 64<<10)
err := r.ParseForm()
if err == nil {
err = r.ParseMultipartForm(64 << 10)
}
// An empty body is not malformed. Some reverse proxies strip the body of
// auth subrequests (for example nginx' auth_request) while keeping the
// original Content-Type, and a chunked request whose body has not been
// buffered yet is indistinguishable from an empty one. Parsing an empty
// multipart body fails with an io.EOF-wrapped error instead of
// http.ErrNotMultipart, so tolerate it as well. Bodies that are actually
// malformed fail with a different error and are still rejected.
if err == nil || errors.Is(err, http.ErrNotMultipart) || errors.Is(err, io.EOF) {
return true
}
var limit *http.MaxBytesError
status := http.StatusBadRequest
if errors.As(err, &limit) {
status = http.StatusRequestEntityTooLarge
}
http.Error(w, http.StatusText(status), status)
return false
}
func cleanupChallengeForm(r *http.Request) {
if r.MultipartForm != nil {
if err := r.MultipartForm.RemoveAll(); err != nil {
slog.DebugContext(r.Context(), "can't remove multipart form files", "err", err)
}
}
}