Reject malformed multipart burn_after_reads with 400
CI / test (pull_request) Successful in 21s
CI / docker (pull_request) Skipped

handleCreatePasteMultipart silently dropped non-numeric
burn_after_reads values (err == nil guard), so burn_after_reads=abc
created a 201 paste with NO burn budget. Now returns 400 with the
error+code shape ({'code':'burn_invalid'}) matching the JSON path,
where an invalid value fails unmarshal into the int field. An empty
value stays 'unset' like the JSON path's omitempty. Verified live:
burn_after_reads=abc -> 400 burn_invalid; =2 -> 201.
This commit is contained in:
fen committed 2026-10-16 16:52:29 -05:00
1 parent b4c23a09bf
commit 135e0d2dc7
1 file changed
+11 -2
+11 -2
View File
@@ -186,9 +186,18 @@ func (a *apiServer) handleCreatePasteMultipart(w http.ResponseWriter, r *http.Re
case "burn_after_read":
p.BurnAfterRead = v == "true" || v == "1" || v == "on"
case "burn_after_reads":
if n, err := strconv.Atoi(v); err == nil {
p.BurnAfterReads = &n
if v == "" { // absent value: unset, like the JSON path's omitempty
continue
}
n, err := strconv.Atoi(v)
if err != nil {
// malformed burn_after_reads is a 400, not a silently-dropped
// budget: same 400-with-code shape the JSON path uses for
// invalid values (which fail unmarshal into the int field).
writeErrCode(w, 400, "burn_invalid", "burn_after_reads must be a positive number")
return
}
p.BurnAfterReads = &n
}
}