Skip to content

Commit 721d715

Browse files
authored
Merge pull request #1312 from trycompai/main
[comp] Production Deploy
2 parents 0fa9409 + 05931fa commit 721d715

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

apps/api/src/attachments/attachments.service.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export class AttachmentsService {
6767
Body: fileBuffer,
6868
ContentType: uploadDto.fileType,
6969
Metadata: {
70-
originalFileName: uploadDto.fileName,
70+
// S3 metadata becomes HTTP headers (x-amz-meta-*) and must be ASCII without control chars
71+
originalFileName: this.sanitizeHeaderValue(uploadDto.fileName),
7172
organizationId,
7273
entityId,
7374
entityType,
@@ -273,6 +274,18 @@ export class AttachmentsService {
273274
return fileName.replace(/[^a-zA-Z0-9.-]/g, '_');
274275
}
275276

277+
/**
278+
* Sanitize header value for S3 user metadata (x-amz-meta-*) to avoid invalid characters
279+
* - Remove control characters (\x00-\x1F, \x7F)
280+
* - Replace non-ASCII with '_'
281+
* - Trim whitespace
282+
*/
283+
private sanitizeHeaderValue(value: string): string {
284+
const withoutControls = value.replace(/[\x00-\x1F\x7F]/g, '');
285+
const asciiOnly = withoutControls.replace(/[^\x20-\x7E]/g, '_');
286+
return asciiOnly.trim();
287+
}
288+
276289
/**
277290
* Map MIME type to AttachmentType enum
278291
*/

0 commit comments

Comments
 (0)