fix(backend:paste): check expiration before returning paste data or recording views; prevent paste authors from adding views to their own paste

This commit is contained in:
2026-03-08 14:45:32 -04:00
parent 49e73cde9c
commit ec0635dd3b
@@ -94,8 +94,9 @@ namespace SharpbinV3.Server.Controllers
public async Task<IActionResult> GetPasteByID(string id) public async Task<IActionResult> GetPasteByID(string id)
{ {
var paste = await _pasteService.Get(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" }); return NotFound(new { success = false, message = "Paste not found" });
var jwtUser = HttpContext.GetJwtUser(); var jwtUser = HttpContext.GetJwtUser();
int? reportCount = null; int? reportCount = null;
@@ -146,7 +147,7 @@ namespace SharpbinV3.Server.Controllers
public async Task<IActionResult> GetRawPasteByID(string id) public async Task<IActionResult> GetRawPasteByID(string id)
{ {
var paste = await _pasteService.Get(id); var paste = await _pasteService.Get(id);
if (paste == null) if (paste == null || (paste.ExpiresAt < DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() && paste.Visibility != 0))
return NotFound(); return NotFound();
if (paste.IsCompressed) if (paste.IsCompressed)
Response.Headers.Append("Content-Encoding", "gzip"); Response.Headers.Append("Content-Encoding", "gzip");
@@ -280,6 +281,11 @@ namespace SharpbinV3.Server.Controllers
) )
return Unauthorized(new { success = false, message = "Invalid API key." }); 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); var result = await _pasteService.RecordView(paste, HttpContext);
if (result.paste is null && !result.alreadyExists) if (result.paste is null && !result.alreadyExists)