Skip to content

feat: let the Contact Us form carry screenshots and recordings - #3563

Open
jelveh wants to merge 1 commit into
mainfrom
feat/contact-us-attachments
Open

feat: let the Contact Us form carry screenshots and recordings#3563
jelveh wants to merge 1 commit into
mainfrom
feat/contact-us-attachments

Conversation

@jelveh

@jelveh jelveh commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What

The Contact Us form now takes up to 5 images or videos alongside the message. They're delivered as attachments on the support email.

Why

From a user report:

I think the "Contact Us" form should allow attachments, especially since it was also created for reporting bugs. This would be useful for including images and videos for bugs that aren't so obvious and that require multiple steps to reproduce.

That's the case exactly: the form doubles as our bug-report channel, and a visual glitch or a five-step repro is far cheaper to show than to describe.

Security

Everything below is enforced server-side, on the decoded bytes. The client-side checks in helpers/contact_attachments.js exist only to fail fast before a 40 MB upload; they're not a control.

Type. Sniffed from magic numbers and matched against an allow-list: PNG, JPEG, GIF, WebP, MP4, QuickTime, WebM. A caller-declared MIME is never read, so it can't be used to smuggle anything past the list. Two deliberate exclusions:

  • SVG — script-capable, and support tooling renders what it's handed.
  • Non-video ISO-container brands that share MP4's ftyp box: HEIC, M4A , JPEG 2000. The brand decides, not the box.

File name. Reduced to a display label; the extension is re-derived from the sniffed type, so PNG bytes named payload.html arrive as payload.png and nothing can ever come out .exe. Stripped: path components, C0/C1 controls (a CR/LF in a name would break out of Content-Disposition), bidi overrides (report<RLO>gnp.exereportgnp.png), quoting characters, leading dots.

Size. 10 MB per file, 15 MB per submission, 5 files. Counted on decoded bytes — the encoded length is capped before decoding, so an oversized payload costs a length check rather than a 10 MB allocation. The total sits well under the 25 MB ceiling most mail providers enforce, since the outgoing mail base64s these again.

Encoding. Strict base64, reusing the round-tripping decoder that already guards app icons. Buffer.from(s, 'base64') silently drops characters it doesn't recognise, so <png>" onerror=alert(1) decodes without complaint; the round-trip is what rejects it.

Rate. One request is now worth megabytes of parsing and outbound mail. The existing 10/15min per-user limit gains a 40/24h per-IP backstop (the per-user counter can't see a single machine cycling fresh accounts), concurrent: 2 per user, and a Content-Length gate that 413s an impossible body before anything decodes.

Storage. Payloads are not stored. They ride the email with Content-Disposition: attachment (no inline rendering). A new feedback.attachments column records {name, type, size} only — enough to keep an abusive submission attributable once the mail has been dealt with, without parking megabytes in the database.

Two things worth a maintainer's call:

  • allowFullAccessToken: true stays on this route, so an app holding a full-access token can submit attachments programmatically. That's pre-existing for the message field; I left it alone rather than risk breaking a first-party caller, and the allow-list plus caps bound what it can do. Happy to narrow it if you'd rather.
  • HEIC is rejected, which means iPhone photos are refused if Safari ever stops transcoding them to JPEG on upload. Worth revisiting if reports come in.

Notes on the diff

  • The strict base64 decoder and the image sniffer move out of util/appIcon.ts into a new util/mediaSniff.ts, which gains the video counterpart. appIcon.ts re-exports sniffImageMime so nothing downstream changes.
  • Migrations add a nullable attachments text column across all three engines (sqlite 0067, mysql 22, postgres 11); the sqlite schema-version constant in SqliteDatabaseClient.test.ts moves with it.

Testing

51 new unit tests (42 for the validator, 9 for the GUI helper) plus 8 controller cases covering the allow-list, the size and count caps, malformed entries, and each file-name attack.

Also driven end to end against a local dev backend, through the real desktop dialog:

  • Form renders; picker staging works; a dropped SVG and PDF are rejected with the right message while the usable files in the same drop are kept.
  • Count cap disables the Attach button; removing a chip re-enables it.
  • Drag-over highlights and prevents the browser navigating to the file.
  • Submit → 200 → correct feedback row.
  • Composed message captured off an SMTP sink: two image/png parts, Content-Disposition: attachment, sanitized filenames, and a body manifest so the recipient can tell a stripped attachment from one that never existed. A file name carrying \r\nBcc: victim@example.com"; x="y produced no Bcc header.

Full backend suite is green apart from 30 pre-existing failures that reproduce on a clean tree (node can't resolve puter.localhost on this machine).

Also fixed in passing

  • The form used to POST an empty message when Send was pressed with nothing typed.
  • Submit failures left the button disabled with no explanation; they now surface an error, which matters much more once a request can fail for being too large.

The form doubles as our bug-report channel, and the bugs worth reporting
are often the ones that need a picture: a visual glitch, or something that
takes five steps to reach. Up to 5 images or videos may now ride along
with the message, delivered as attachments on the support email.

Nothing the client says about a file is believed. The endpoint takes bare
base64 and re-derives all three of the things that matter from the decoded
bytes:

- Type, sniffed from magic numbers and matched against an allow-list of
  PNG/JPEG/GIF/WebP and MP4/QuickTime/WebM. A declared MIME is never read,
  so it cannot smuggle anything past the list. SVG is excluded on purpose
  (it carries script, and support tooling renders what it is sent), as are
  the non-video brands that share MP4's `ftyp` box -- HEIC, M4A, JPEG 2000.
- The file name, reduced to a display label with the extension taken from
  the sniffed type. PNG bytes named `payload.html` arrive as
  `payload.png`; a name can never carry the CR/LF that would break out of
  a Content-Disposition header, nor the bidi overrides that make
  `report<RLO>gnp.exe` render as `report.exe.mp4`.
- Size: 10 MB per file, 15 MB per submission, counted on decoded bytes.
  Encoded length is capped before decoding, so an oversized payload costs
  a length check rather than a 10 MB allocation. The total stays well
  under the 25 MB most providers enforce, since the outgoing mail base64s
  these again.

Base64 is decoded strictly, reusing the round-tripping decoder that
already guards app icons -- `Buffer.from(s, 'base64')` silently drops
characters it does not recognise, and the round-trip is what rejects
bytes smuggled after the payload. That decoder and the image sniffer move
from appIcon.ts to a new mediaSniff.ts, which gains the video counterpart.

One request is now worth megabytes of parsing and outbound mail, so the
existing per-user rate limit gains a per-IP backstop (which the per-user
counter cannot see through freshly minted accounts), a concurrency cap,
and a Content-Length gate that refuses an impossible body before anything
decodes it.

Payloads are not stored. They ride the email; the new
`feedback.attachments` column records names, types and sizes only, so an
abusive submission stays attributable once the mail has been dealt with.

Also fixes the form posting an empty message when Send was pressed with
nothing typed, and surfaces submit failures instead of leaving the button
disabled with no explanation.
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 93.62%
⬆️ +0.01%
22433 / 23961
🔵 Statements 91.97%
⬆️ +0.01%
24103 / 26207
🔵 Functions 89.52%
⬆️ +0.03%
3759 / 4199
🔵 Branches 80.66%
⬆️ +0.04%
16224 / 20114
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/backend/clients/database/SqliteDatabaseClient.ts 89.14%
🟰 ±0%
57.45%
🟰 ±0%
81.6%
🟰 ±0%
95.58%
🟰 ±0%
6, 9, 13, 16, 24-26, 32, 33, 34, 38-39, 44, 45, 46, 47, 48, 230-232, 480-483, 498
src/backend/controllers/system/SystemController.js 93.93%
⬆️ +1.21%
80.7%
⬆️ +4.11%
100%
🟰 ±0%
95.31%
⬆️ +0.98%
182, 289, 316, 343
src/backend/util/appIcon.ts 97.84%
⬆️ +1.02%
97.14%
⬆️ +0.65%
100%
🟰 ±0%
100%
⬆️ +0.93%
179, 279
src/backend/util/contactAttachments.ts 98.33% 95.34% 100% 98.14% 269
src/backend/util/mediaSniff.ts 91.48% 92.06% 100% 94.59% 76, 81, 167
Generated in workflow #721 for commit 82995c3 by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant