## Problem/Motivation

When Stage File Proxy attempts to fetch image style derivatives with query parameters (e.g., `?itok=...`), the `pathinfo()` function in `DownloadManager::fetchResponse()` incorrectly treats the query string as part of the file extension. This causes the module to request malformed URLs from the origin server, resulting in 404 errors.

**Example scenario:**
- Original request: `styles/medium/public/2024-01/liitu-uusi-asiakas-oikea-2.1.24.jpg?itok=WGoLZcyu`
- Expected fetch URL: `https://example.com/sites/default/files/2024-01/liitu-uusi-asiakas-oikea...`
- Actual fetch URL: `https://example.com/sites/default/files/2024-01/liitu-uusi-asiakas-oikea...` (missing `.24.jpg`)

The bug occurs because `pathinfo()` on line 126 of `src/DownloadManager.php` receives a path with query parameters, causing it to misidentify the file extension as `jpg?itok=WGoLZcyu` instead of `jpg`. This is particularly problematic for filenames containing dots (e.g., version numbers like `2.1.24`).

### Steps to reproduce

1. Enable Stage File Proxy module (version 3.1.6)
2. Configure origin server URL in settings.php
3. Upload an image with dots in the filename (e.g., `my-file-2.1.24.jpg`)
4. Request an image style derivative of this file (e.g., `/styles/medium/public/...`)
5. Observe the error in watchdog logs:

Stage File Proxy encountered an error when retrieving file https://example.com/sites/default/files/2024-01/my-file-2.1.24.
Client error: GET https://example.com/sites/default/files/2024-01/my-file-2.1?itok=... resulted in a 404 Not Found

## Proposed resolution

Strip query parameters from `$relative_path` before calling `pathinfo()` in the `fetchResponse()` method. The query parameters should be removed only for the purpose of path parsing, not from the actual request URL.

**Code change in `src/DownloadManager.php` (line 126):**

```php
// Before:
$path_info = pathinfo($relative_path);

// After:
// Strip query parameters before calling pathinfo() to avoid treating
// them as part of the file extension.
$path_without_query = preg_replace('/\?.*$/', '', $relative_path);
$path_info = pathinfo($path_without_query);

A patch implementing this fix is attached.

Comments

tormi created an issue. See original summary.

tormi’s picture

BTW, D.O issues really should start using markdown format.

tormi’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Fixes need to be in MRs please.

Possible to get any test coverage.

smustgrave’s picture

Version: 3.1.6 » 4.0.x-dev
smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

If still an issue please re-open.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.