diff --git a/internal/api/server.go b/internal/api/server.go index dfe1ac4..84618c0 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -451,6 +451,14 @@ func (a *apiServer) handleRaw(w http.ResponseWriter, r *http.Request) { http.Error(w, "not found", 404) return } + // #221: an attachment paste has no text content; raw view must serve the + // file itself, not empty text. Redirect to the /f/ serving route, which + // applies the same sniffed-mime + disposition safety rules. + if att, err := a.store.GetAttachmentForPaste(row.ID); err == nil && att != nil { + a.store.IncrementViews(row.ID, "", 0) // raw views always count (#49/#95) + http.Redirect(w, r, "/f/"+att.ID+"/"+att.Filename, http.StatusFound) + return + } // #34: content_type is attacker-controlled via the create API. Serving it // verbatim let a paste be stored with text/html (or image/svg+xml) and // render as active content on this origin when fetched from /raw — diff --git a/internal/web/static/app.css b/internal/web/static/app.css index c96034b..b2fc912 100644 --- a/internal/web/static/app.css +++ b/internal/web/static/app.css @@ -818,7 +818,15 @@ button[type="submit"]:focus-visible, } .attachment-chip:hover { border-color: var(--accent); } .attachment-chip .attachment-size { color: var(--muted-fg); font-size: 19px; } -.attachment-preview img { max-width: 480px; max-height: 360px; border-radius: var(--radius); border: 1px solid var(--border); } +/* #221: image pastes scale to fit the viewer box (no text box below), and + the link pill sits above the image without drifting out of place. */ +.attachment-bar.is-image { align-items: flex-start; } +.attachment-bar.is-image .attachment-chip { max-width: 100%; } +.attachment-preview { max-width: 100%; } +.attachment-preview img { + display: block; max-width: 100%; max-height: 70vh; width: auto; height: auto; + object-fit: contain; border-radius: var(--radius); border: 1px solid var(--border); +} /* #139: CSP-safe replacements for inline style attributes (style-src 'self') */ .hidden { display: none; } diff --git a/internal/web/templates/paste.html b/internal/web/templates/paste.html index b907ded..45a6980 100644 --- a/internal/web/templates/paste.html +++ b/internal/web/templates/paste.html @@ -38,20 +38,22 @@ {{end}} {{if .Attachment}}