You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
middleware.Log的默认defaultMaxLength太短,如果request body过长,在后续的ShouldBindJSON中会出现解析错误
More description
传入超过一定长度的复杂request body,并且使用middleware.Log,
在后续的ShouldBindJSON过程中会出现错误ShouldBindJSON error: {"error": "invalid character '.' looking for beginning of object key string", "request_id": "u2Nrwro8wr"}。
如果把defaultMaxLength修改变大,则不会报错。
问题的原因是:
// If there is sensitive information in the body, you can use WithIgnoreRoutes set the route to ignore logging
func getBodyData(buf *bytes.Buffer, maxLen int) []byte {
l := buf.Len()
if l == 0 {
return []byte("")
} else if l <= maxLen {
return buf.Bytes()[:l-1]
}
return append(buf.Bytes()[:maxLen], contentMark...)
}
Describe the bug
middleware.Log的默认defaultMaxLength太短,如果request body过长,在后续的
ShouldBindJSON
中会出现解析错误More description
传入超过一定长度的复杂request body,并且使用
middleware.Log
,在后续的
ShouldBindJSON
过程中会出现错误ShouldBindJSON error: {"error": "invalid character '.' looking for beginning of object key string", "request_id": "u2Nrwro8wr"}
。如果把defaultMaxLength修改变大,则不会报错。
问题的原因是:
如果
l <= maxLen
的情况,getBodyData中的append对原buf进行了修改,在后续
c.Request.Body = io.NopCloser(&buf)
会传入修改后的错误的request body。The text was updated successfully, but these errors were encountered: