mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] return 400 Bad Request on more cases of malformed AS data (#2399)
This commit is contained in:
@ -20,6 +20,7 @@ package middleware
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-bytesize"
|
||||
@ -56,7 +57,10 @@ func Logger(logClientIP bool) gin.HandlerFunc {
|
||||
_ = c.Error(err)
|
||||
|
||||
// Dump a stacktrace to error log
|
||||
callers := errors.GetCallers(3, 10)
|
||||
pcs := make([]uintptr, 10)
|
||||
n := runtime.Callers(3, pcs)
|
||||
iter := runtime.CallersFrames(pcs[:n])
|
||||
callers := errors.Callers(gatherFrames(iter, n))
|
||||
log.WithContext(c.Request.Context()).
|
||||
WithField("stacktrace", callers).Error(err)
|
||||
}
|
||||
@ -80,8 +84,9 @@ func Logger(logClientIP bool) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// Create log entry with fields
|
||||
l := log.WithContext(c.Request.Context()).
|
||||
WithFields(fields...)
|
||||
l := log.New()
|
||||
l = l.WithContext(c.Request.Context())
|
||||
l = l.WithFields(fields...)
|
||||
|
||||
// Default is info
|
||||
lvl := level.INFO
|
||||
@ -119,3 +124,19 @@ func Logger(logClientIP bool) gin.HandlerFunc {
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// gatherFrames gathers runtime frames from a frame iterator.
|
||||
func gatherFrames(iter *runtime.Frames, n int) []runtime.Frame {
|
||||
if iter == nil {
|
||||
return nil
|
||||
}
|
||||
frames := make([]runtime.Frame, 0, n)
|
||||
for {
|
||||
f, ok := iter.Next()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
frames = append(frames, f)
|
||||
}
|
||||
return frames
|
||||
}
|
||||
|
Reference in New Issue
Block a user