Sanitize file names taken from server metadata (closes #9) #78

Merged
clawbot merged 1 commits from issue-9-sanitize-filenames into next2 2026-09-23 02:04:32 +02:00
Collaborator

Implements #9.

File titles and album names come from server data that quak does not trust. Before this change a title such as ../../.ssh/authorized_keys could name a path outside the chosen directory. Now src/filename.ts is the one place that makes such names safe. It is used by quak get and quak get-thumb without --out, by downloadFile and downloadThumbnail without outPath, and by the backup and metadata backup trees. Separators, control characters and NUL become _. A leading run of dots becomes _, and a Windows device name gets a _ prefix. An empty title falls back to file-<id>.

The extension used in the originals cache may contain only letters and digits. Anything else becomes .bin.

A path the user gives (--out, outPath) is still used exactly as given. A comment in the code states this.

decryptFile now turns a missing or non-string title into "". It throws a clear error when the metadata is not a JSON object; before, that case failed with a TypeError.

Things to know:

  • Judgement call: all callers now share the backup's existing character set. For quak get, a title containing :*?"<>| now becomes a file name with _ in place of those characters. Titles without them come out exactly as before.
  • Rule suppressed: no-control-regex, on the one regular expression that matches control characters.
  • The download tests change the working directory into a temporary directory. With no outPath, the file is written to the working directory, and it must not land in the repo.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/quak/issues/9. File titles and album names come from server data that quak does not trust. Before this change a title such as `../../.ssh/authorized_keys` could name a path outside the chosen directory. Now `src/filename.ts` is the one place that makes such names safe. It is used by `quak get` and `quak get-thumb` without `--out`, by `downloadFile` and `downloadThumbnail` without `outPath`, and by the backup and metadata backup trees. Separators, control characters and NUL become `_`. A leading run of dots becomes `_`, and a Windows device name gets a `_` prefix. An empty title falls back to `file-<id>`. The extension used in the originals cache may contain only letters and digits. Anything else becomes `.bin`. A path the user gives (`--out`, `outPath`) is still used exactly as given. A comment in the code states this. `decryptFile` now turns a missing or non-string title into `""`. It throws a clear error when the metadata is not a JSON object; before, that case failed with a `TypeError`. Things to know: - Judgement call: all callers now share the backup's existing character set. For `quak get`, a title containing `:*?"<>|` now becomes a file name with `_` in place of those characters. Titles without them come out exactly as before. - Rule suppressed: `no-control-regex`, on the one regular expression that matches control characters. - The download tests change the working directory into a temporary directory. With no `outPath`, the file is written to the working directory, and it must not land in the repo. Model: opus-5-5
clawbot added the needs-review label 2026-09-23 01:42:09 +02:00
clawbot self-assigned this 2026-09-23 01:42:09 +02:00
clawbot added 1 commit 2026-09-23 01:42:09 +02:00
A file title or album name decrypted from server data could name a path
outside the chosen directory (`../../.ssh/authorized_keys`). One module,
src/filename.ts, now makes such names safe for `quak get`/`get-thumb`
without `--out`, downloadFile/downloadThumbnail without outPath, and the
backup and metadata backup trees. Originals-cache extensions are limited to
letters and digits. A user-supplied path is still used as is. decryptFile
reads a missing or non-string title as "" and rejects metadata that is not
a JSON object.

Model: opus-5-5
Author
Collaborator

PASS on 047f63c rebased onto next2 fe952d3.

Model: opus-5-5

PASS on `047f63c` rebased onto `next2` `fe952d3`. Model: opus-5-5
clawbot merged commit 3871d6228e into next2 2026-09-23 02:04:32 +02:00
clawbot deleted branch issue-9-sanitize-filenames 2026-09-23 02:04:32 +02:00
Sign in to join this conversation.