Skip to content

fix: bound attachment filenames - #62

Open
vycdev2 wants to merge 1 commit into
vycdev:mainfrom
vycdev2:fix/bound-attachment-filenames
Open

fix: bound attachment filenames#62
vycdev2 wants to merge 1 commit into
vycdev:mainfrom
vycdev2:fix/bound-attachment-filenames

Conversation

@vycdev2

@vycdev2 vycdev2 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cap downloaded attachment filenames at a filesystem-safe UTF-8 byte length
  • preserve useful name prefixes and extensions while adding a deterministic hash to avoid truncation collisions
  • reject directory paths before bounding the validated basename, preserving current download-size and symlink protections

Verification

  • npm test — passed: TypeScript build and all 111 tests
  • git diff --check main...HEAD — passed

Risk

  • Low: the change is isolated to local attachment path generation; short filenames remain unchanged, and regression coverage includes the reported normalization/truncation path.

This was generated by an AI agent (vycdev2). Please verify any changes before merging or applying.

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Found one path-safety blocker. The normal filename and traversal tests pass, but truncation can alter path normalization after the existing validation.

Comment thread src/storage/images.ts
) {
throw new Error("Attachment filename resolves outside the images directory");
}
const filePath = path.resolve(IMAGES_DIR, boundFilename(filename));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The resolved path is validated before boundFilename() changes it, so the final path can escape IMAGES_DIR. I reproduced this with "../" + "a".repeat(300) + "/../images/safe.png": the original path normalizes inside images, passes the check, then truncation removes the suffix that brought it back inside and fs.writeFileSync writes into the parent directory. Please validate the final bounded path (or bound only a validated basename) and add this normalization/truncation case as a regression test.

@vycdev2
vycdev2 force-pushed the fix/bound-attachment-filenames branch from f16855d to f4adf4f Compare August 11, 2026 07:12
@vycdev2

vycdev2 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the path-safety review by rebuilding the change on current main, rejecting directory paths before bounding the validated basename, preserving the existing download-size and symlink protections, and adding the reported normalization/truncation case as a regression test. npm test passes all 111 tests.

This was generated by an AI agent (vycdev2). Please verify any changes before merging or applying.

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.

2 participants