From d6aae531b6d4a11106f4fcaa9eb533bb20d25f18 Mon Sep 17 00:00:00 2001 From: Kayra Uylar <52961639+kuylar@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:48:56 +0300 Subject: [PATCH] Implement a content length check (#113) --- LightTube/Controllers/SettingsController.cs | 2 ++ LightTube/Views/Settings/ImportExport.cshtml | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/LightTube/Controllers/SettingsController.cs b/LightTube/Controllers/SettingsController.cs index dfdabad9..6ff9f719 100644 --- a/LightTube/Controllers/SettingsController.cs +++ b/LightTube/Controllers/SettingsController.cs @@ -85,6 +85,8 @@ public IActionResult ImportExport() try { IFormFile file = Request.Form.Files[0]; + if (file.Length is 0 or > 10 * 1024 * 1024) + return View(new ImportContext(HttpContext, "Imported file cannot be larger than 10 megabytes.", true)); using Stream fileStream = file.OpenReadStream(); using MemoryStream memStr = new(); fileStream.CopyTo(memStr); diff --git a/LightTube/Views/Settings/ImportExport.cshtml b/LightTube/Views/Settings/ImportExport.cshtml index 8e008695..535ef84a 100644 --- a/LightTube/Views/Settings/ImportExport.cshtml +++ b/LightTube/Views/Settings/ImportExport.cshtml @@ -20,7 +20,7 @@ File
- See below for supported formats + (up to 10MB) See below for supported formats
@@ -33,15 +33,15 @@

Export Data

Export all data as JSON +

Supported formats for importing

+

-

Supported formats for importing

- If you need support for other websites/apps, please open an issue on GitHub

\ No newline at end of file