mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
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:
@@ -94,8 +94,9 @@ namespace SharpbinV3.Server.Controllers
|
||||
public async Task<IActionResult> 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<IActionResult> 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)
|
||||
|
||||
Reference in New Issue
Block a user