parse-community / parse-community/parse-server-s3-adapter

Bug: Double URL Encoding in Presigned URLs for Filenames with Special Characters

Open
#335 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
80
Forks
86
PR merge metrics
No merged PRs in 30d

Description

When using presigned URLs (presignedUrl: true), filenames containing special characters like brackets, spaces, or other URL-sensitive characters are being double-encoded, resulting in malformed URLs that cannot be accessed.

Bug Details

Affected Version: Current version
Component: getFileLocation() method in index.js
Severity: High - Breaks file access for filenames with special characters when using presigned URLs

Problem Description

The issue occurs in the getFileLocation() method where:

  1. Line 242: The filename is encoded using filename.split('/').map(encodeURIComponent).join('/')
  2. Line 247: This encoded filename is used to create the S3 key for presigned URL generation
  3. Line 255: AWS SDK's getSignedUrl() function internally encodes the key again, causing double encoding
Example

For a filename like doc[123].pdf:

  • Expected behavior: Should encode to doc%5B123%5D.pdf in the presigned URL
  • Actual behavior: Gets double-encoded to doc%255B123%255D.pdf
    • First encoding: [123]%5B123%5D
    • Second encoding by AWS SDK: %5B123%5D%255B123%255D

Root Cause

// Line 242: Pre-encodes the filename
const fileName = filename.split('/').map(encodeURIComponent).join('/');

// Line 247: Uses pre-encoded filename for S3 key
const fileKey = `${this._bucketPrefix}${fileName}`;

// Line 251: AWS SDK encodes the already-encoded key again
const params = { Bucket: this._bucket, Key: fileKey };
presignedUrl = await this.getFileSignedUrl(this._s3Client, command, options);

Impact

  • Presigned URLs become inaccessible for files with special characters
  • Affects any filename containing: [], (), spaces, and other URL-sensitive characters
  • Works fine for regular S3 URLs (non-presigned) because they don't go through AWS SDK's internal encoding

Steps to Reproduce

  1. Configure S3 adapter with presignedUrl: true
  2. Upload a file with special characters in the name (e.g., "test [file].pdf")
  3. Generate a presigned URL using getFileLocation()
  4. Attempt to access the URL - it will return 404/AccessDenied

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect index.js and start with getFileLocation() around lines 242-255, then trace how the S3 key is passed to presigned URL generation. Reproduce the case with a filename such as doc[123].pdf or test [file].pdf; done means the generated URL contains a single encoding and can access the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.