Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

fix(image): Correctly handle query parameters in image URL validation#1288

Open
devsymo wants to merge 1 commit intoharvester:masterfrom
devsymo:fix/url-validation-query-params
Open

fix(image): Correctly handle query parameters in image URL validation#1288
devsymo wants to merge 1 commit intoharvester:masterfrom
devsymo:fix/url-validation-query-params

Conversation

@devsymo
Copy link
Copy Markdown

@devsymo devsymo commented Oct 21, 2025

Summary

The imageUrl validator currently fails to correctly extract the file extension when the image URL contains query parameters or fragments (e.g., 'image.qcow2?token=abc').

This change introduces a dedicated function, getFilenameFromUrl, which uses the native URL object for robust parsing. This ensures the file suffix validation is always performed on the actual filename, ignoring any trailing parameters.

PR Checklist

  • Is this a multi-tenancy feature/bug?
    • Yes, the relevant RBAC changes are at:
    • No
  • Do we need to backport changes to the old Rancher UI, such as RKE1?
    • Yes, the relevant PR is at:
    • No (This is a Harvester Dashboard specific component)
  • Are backend engineers aware of UI changes?
    • Yes, the backend owner is:
    • No (This is a purely front-end validation logic change)

Related Issue #
5186

Occurred changes and/or fixed issues

Fixes an issue where image validation failed for URLs that contained query parameters (?) or fragments (#). The previous logic incorrectly included these trailing characters when attempting to determine the file extension, resulting in an invalid format error for a valid URL.

Technical notes summary

A new private utility function, getFilenameFromUrl(url), was introduced. This function robustly parses the URL to ensure only the filename part of the path is used for validation.

It attempts to use the native URL object for standard-compliant parsing.

If parsing fails (e.g., if the input is a relative path), it falls back to manual string splitting to remove any query parameters (?) or fragments (#) before extracting the filename.

The main imageUrl validator now uses this new utility function before extracting the file suffix.

Areas or cases that should be tested

Browser Used for Local Testing: [Your Browser, e.g., Chrome/Firefox/Edge]

Image Creation via URL: Test creating a new VM Image using a direct URL.

Case 1 (Success): Use a clean URL (e.g., http://example.com/image.qcow2).

Case 2 (Success - Fixed Case): Use a URL with a query parameter (e.g., http://example.com/image.qcow2?token=abc). This should succeed with no validation error.

Case 3 (Success - Fixed Case): Use a URL with a fragment (e.g., http://example.com/image.raw#latest). This should succeed with no validation error.

Validation Failure: Use a URL with an invalid extension and a query parameter (e.g., http://example.com/image.txt?param=1). This should fail and display the correct format validation error.

Areas which could experience regressions

Any image creation/upload modal that uses the imageUrl validation function.

Other areas of image file validation (though the change is isolated to URL parsing).

Screenshot/Video

The imageUrl validator currently fails to correctly extract the file extension when the image URL contains query parameters or fragments (e.g., 'image.qcow2?token=abc').

This change introduces a dedicated function, `getFilenameFromUrl`, which uses the native URL object for robust parsing. This ensures the file suffix validation is always performed on the actual filename, ignoring any trailing parameters.

Signed-off-by: devsymo <devsymo@hotmail.com>
@devsymo devsymo force-pushed the fix/url-validation-query-params branch from b380cae to 7ce9462 Compare October 21, 2025 02:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant