Skip to content

fix: use platform path separator in attachment validation#149

Merged
devartifex merged 1 commit intodevartifex:masterfrom
dmbutko:fix/platform-path-separator
Apr 14, 2026
Merged

fix: use platform path separator in attachment validation#149
devartifex merged 1 commit intodevartifex:masterfrom
dmbutko:fix/platform-path-separator

Conversation

@dmbutko
Copy link
Copy Markdown
Contributor

@dmbutko dmbutko commented Apr 13, 2026

isValidAttachmentPath() used a hardcoded forward slash ('/') when checking if an uploaded file path was inside the upload directory. On Windows, node:path.resolve() returns backslash-separated paths, so the startsWith check always failed - silently dropping every image attachment with an ATTACHMENT_PATH_REJECTED warning.

This was a bug we introduced in v1.0.0. Commit bb9daa8 fixed the same class of Windows path separator issue in the frontend components but missed the server-side validation in attachments.ts.

Fix: Replace '/' with node:path.sep to support both platforms.

Also updated the test to use join() instead of a hardcoded / for the prefix-substring attack test case.

isValidAttachmentPath() used hardcoded '/' separator which fails on
Windows where paths use '\'. Replace with node:path sep to support
both platforms. Also fix test to use join() instead of hardcoded '/'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@devartifex devartifex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — Clean, correct fix. Using path.sep instead of hardcoded / properly supports Windows path separators. Security logic remains sound: resolve() + startsWith(prefix + sep) prevents both path traversal and prefix-substring attacks. Test update with join() is consistent. All 399 unit tests pass (the check failure is a pre-existing coverage threshold issue unrelated to this change).

@devartifex devartifex merged commit b98a846 into devartifex:master Apr 14, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants