From 0f9a57f62b94a698a475055978242c11aaac83ee Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Wed, 8 Sep 2021 22:22:47 -0500 Subject: [PATCH] Put a maximum length on post content --- src/website/threads_and_posts_helper.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/website/threads_and_posts_helper.go b/src/website/threads_and_posts_helper.go index 35120c5d..0d4ccf3f 100644 --- a/src/website/threads_and_posts_helper.go +++ b/src/website/threads_and_posts_helper.go @@ -8,6 +8,7 @@ import ( "time" "git.handmade.network/hmn/hmn/src/db" + "git.handmade.network/hmn/hmn/src/logging" "git.handmade.network/hmn/hmn/src/models" "git.handmade.network/hmn/hmn/src/oops" "git.handmade.network/hmn/hmn/src/parsing" @@ -348,7 +349,16 @@ func DeletePost( return false } +const maxPostContentLength = 200000 + func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedContent string, ipString string, editReason string, editorId *int) (versionId int) { + if len(unparsedContent) > maxPostContentLength { + logging.ExtractLogger(ctx).Warn(). + Str("preview", unparsedContent[:400]). + Msg("Somebody attempted to create an extremely long post. Content was truncated.") + unparsedContent = unparsedContent[:maxPostContentLength-1] + } + parsed := parsing.ParseMarkdown(unparsedContent, parsing.ForumRealMarkdown) ip := net.ParseIP(ipString)