Skip to content

Commit

Permalink
fix: base64 encode for metadata in headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos committed Jul 11, 2024
1 parent d0f0348 commit 01402bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 deletions.
65 changes: 16 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@aws-sdk/lib-storage": "3.515.0",
"@aws-sdk/s3-request-presigner": "3.421.0",
"@fastify/accepts": "^4.3.0",
"@fastify/multipart": "^7.6.0",
"@fastify/multipart": "^8.3.0",
"@fastify/rate-limit": "^7.6.0",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.7.0",
Expand Down
7 changes: 2 additions & 5 deletions src/storage/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,9 @@ export class Uploader {
const customMd = request.headers['x-metadata']

if (typeof customMd === 'string') {
if (userMetadata && Buffer.byteLength(customMd, 'utf8') > MAX_CUSTOM_METADATA_SIZE) {
throw ERRORS.EntityTooLarge(undefined, 'metadata')
}

try {
userMetadata = JSON.parse(customMd)
const json = Buffer.from(customMd, 'base64').toString('utf8')
userMetadata = JSON.parse(json)
} catch (e) {
// no-op
}
Expand Down

0 comments on commit 01402bd

Please sign in to comment.