Sanitize server-controlled filenames used as output paths #9
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
downloadFile(src/download/index.ts:71) falls back tofile.metadata.titleas the outputpath when no
outPathis given, anddownloadThumbnail(:84) uses it with athumb_prefix.
file.metadata.titleis decrypted from server-supplied metadata; it is fullyattacker-controlled if the account is compromised or the server is hostile, and quak's entire
premise is that the server is not trusted with plaintext.
A title of
../../.ssh/authorized_keyswrites outside the intended directory.bin/quak.tspasses
opts.outstraight through, which isundefinedunless--outwas given, soquak get <id>in a shell hits this path directly.src/backup.tshas asanitizePathhelper for the backup tree, but the download layer doesnot use it and
sanitizePathitself is not applied to path separators in a way that has beentested against traversal payloads.
src/model/decrypt.ts:100compounds this: the decrypted metadata JSON is parsed as implicitanyand every field is read unchecked, so a non-stringtitlepropagates as-is.Definition of done
sanitized so it can only ever name a file in the intended directory: no path separators, no
..components, no absolute paths, no leading dots, no NUL bytes, no reserved device names.outPathis honoured verbatim — the caller is trusted, the serveris not. This distinction is documented in a code comment.
from the file ID.
decryptFilevalidates the shape of the decrypted metadata JSON rather than trusting it:a non-string
title, or a missing one, produces a well-defined result instead ofpropagating an arbitrary value.
src/backup.tsrather than duplicated.../traversal, absolute path,embedded separators, NUL byte, empty title, non-string title, and a normal title passing
through unchanged.
make checkgreen.TODO.mdupdated in the same commit.