Remove ?token= deletion-token path (#143)
CI / test (pull_request) Successful in 35s
CI / docker (pull_request) Skipped

The deletion token was accepted via the ?token= query parameter on both
DELETE /api/pastes/{id} and /redeem, and round-tripped through the paste
URL after creation. URL-carried bearer secrets leak into reverse-proxy
access logs and browser history.

- API: deletion tokens are now accepted only via the Authorization header
  (Bearer/Token/bare); query params are ignored on both endpoints
- Web create flow: token moves to the browser via a short-lived tok_<id>
  HttpOnly cookie instead of the redirect URL; the paste view reads it
  from the cookie, never from ?token=
- Web view: the delete button calls redeem() which takes the token from
  sessionStorage and sends it as an Authorization header
- Tests: correct token in query must be rejected (403/400); header path
  still deletes/redeems; extraction unit cases updated

Fixes #143
This commit is contained in:
fen
2026-09-10 08:24:05 -05:00
parent 33ccfd373a
commit 27763cd1ba
7 changed files with 81 additions and 29 deletions
+5 -3
View File
@@ -53,8 +53,9 @@ func TestDeletionTokenRedeem(t *testing.T) {
t.Fatal("no deletion token in create response")
}
// wrong token
req = httptest.NewRequest("DELETE", "/api/pastes/"+created.ID+"/redeem?token=wrong", nil)
// wrong token (#143: token goes in the Authorization header, not the URL)
req = httptest.NewRequest("DELETE", "/api/pastes/"+created.ID+"/redeem", nil)
req.Header.Set("Authorization", "Bearer wrong")
rec = httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != 403 {
@@ -62,7 +63,8 @@ func TestDeletionTokenRedeem(t *testing.T) {
}
// right token: hard delete
req = httptest.NewRequest("DELETE", "/api/pastes/"+created.ID+"/redeem?token="+created.DeletionToken, nil)
req = httptest.NewRequest("DELETE", "/api/pastes/"+created.ID+"/redeem", nil)
req.Header.Set("Authorization", "Bearer "+created.DeletionToken)
rec = httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != 200 {