Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/server/ws/attachment-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('isValidAttachmentPath', () => {

it('rejects paths that match the prefix as a substring but are not inside it', () => {
// e.g. /tmp/copilot-uploads-evil/file.txt should not match /tmp/copilot-uploads/
expect(isValidAttachmentPath(UPLOAD_PREFIX + '-evil/file.txt')).toBe(false);
expect(isValidAttachmentPath(join(UPLOAD_PREFIX + '-evil', 'file.txt'))).toBe(false);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/ws/attachments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'node:path';
import { resolve, sep } from 'node:path';
import { logSecurity } from '../security-log.js';
import { UPLOAD_DIR_PREFIX } from './constants.js';

Expand All @@ -12,7 +12,7 @@ export type SdkAttachment =
/** Validate that an attachment path is an absolute path inside the upload directory (prevents arbitrary file reads). */
export function isValidAttachmentPath(filePath: string): boolean {
const resolved = resolve(filePath);
return resolved.startsWith(UPLOAD_DIR_PREFIX + '/');
return resolved.startsWith(UPLOAD_DIR_PREFIX + sep);
}

/** Map client-sent attachments to the SDK format, validating paths and filtering invalid entries. */
Expand Down
Loading