[backend/federation] Reject notes with text length > 100k characters
This commit is contained in:
parent
61ba7b543e
commit
88a180666d
2 changed files with 8 additions and 2 deletions
|
@ -12,8 +12,8 @@ using HtmlParser = AngleSharp.Html.Parser.HtmlParser;
|
||||||
namespace Iceshrimp.Backend.Core.Helpers.LibMfm.Conversion;
|
namespace Iceshrimp.Backend.Core.Helpers.LibMfm.Conversion;
|
||||||
|
|
||||||
public static class MfmConverter {
|
public static class MfmConverter {
|
||||||
public static async Task<string> FromHtmlAsync(string? html) {
|
public static async Task<string?> FromHtmlAsync(string? html) {
|
||||||
if (html == null) return "";
|
if (html == null) return null;
|
||||||
|
|
||||||
// Ensure compatibility with AP servers that send both <br> as well as newlines
|
// Ensure compatibility with AP servers that send both <br> as well as newlines
|
||||||
var regex = new Regex(@"<br\s?\/?>\r?\n", RegexOptions.IgnoreCase);
|
var regex = new Regex(@"<br\s?\/?>\r?\n", RegexOptions.IgnoreCase);
|
||||||
|
|
|
@ -27,6 +27,9 @@ public class NoteService(
|
||||||
|
|
||||||
public async Task<Note> CreateNoteAsync(User user, Note.NoteVisibility visibility, string? text = null,
|
public async Task<Note> CreateNoteAsync(User user, Note.NoteVisibility visibility, string? text = null,
|
||||||
string? cw = null, Note? reply = null, Note? renote = null) {
|
string? cw = null, Note? reply = null, Note? renote = null) {
|
||||||
|
if (text is { Length: > 100000 })
|
||||||
|
throw GracefulException.UnprocessableEntity("Content cannot be longer than 100.000 characters");
|
||||||
|
|
||||||
var actor = await userRenderer.RenderAsync(user);
|
var actor = await userRenderer.RenderAsync(user);
|
||||||
|
|
||||||
var note = new Note {
|
var note = new Note {
|
||||||
|
@ -97,6 +100,9 @@ public class NoteService(
|
||||||
//TODO: parse to fields for specified visibility & mentions
|
//TODO: parse to fields for specified visibility & mentions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (dbNote.Text is { Length: > 100000 })
|
||||||
|
throw GracefulException.UnprocessableEntity("Content cannot be longer than 100.000 characters");
|
||||||
|
|
||||||
await db.Notes.AddAsync(dbNote);
|
await db.Notes.AddAsync(dbNote);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
logger.LogDebug("Note {id} created successfully", dbNote.Id);
|
logger.LogDebug("Note {id} created successfully", dbNote.Id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue