From ec0635dd3b6401679e1a4a923302de5dcdbecda8 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sun, 8 Mar 2026 14:45:32 -0400 Subject: [PATCH] fix(backend:paste): check expiration before returning paste data or recording views; prevent paste authors from adding views to their own paste --- SharpbinV3.Server/Controllers/PasteController.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SharpbinV3.Server/Controllers/PasteController.cs b/SharpbinV3.Server/Controllers/PasteController.cs index 892a885..40f4b77 100644 --- a/SharpbinV3.Server/Controllers/PasteController.cs +++ b/SharpbinV3.Server/Controllers/PasteController.cs @@ -94,8 +94,9 @@ namespace SharpbinV3.Server.Controllers public async Task GetPasteByID(string id) { var paste = await _pasteService.Get(id); - if (paste == null) + if (paste == null || (paste.ExpiresAt < DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() && paste.Visibility != 0)) return NotFound(new { success = false, message = "Paste not found" }); + var jwtUser = HttpContext.GetJwtUser(); int? reportCount = null; @@ -146,7 +147,7 @@ namespace SharpbinV3.Server.Controllers public async Task GetRawPasteByID(string id) { var paste = await _pasteService.Get(id); - if (paste == null) + if (paste == null || (paste.ExpiresAt < DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() && paste.Visibility != 0)) return NotFound(); if (paste.IsCompressed) Response.Headers.Append("Content-Encoding", "gzip"); @@ -280,6 +281,11 @@ namespace SharpbinV3.Server.Controllers ) return Unauthorized(new { success = false, message = "Invalid API key." }); + if (paste.AuthorUUID != HttpContext.GetJwtUser()?.UUID) + return Ok(new { success = true, message = "View not recorded for author's own paste." }); + if (paste.ExpiresAt < DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() && paste.Visibility != 0) + return Ok(new { success = true, message = "View not recorded for expired paste." }); + var result = await _pasteService.RecordView(paste, HttpContext); if (result.paste is null && !result.alreadyExists)