You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
QGIS improperly encodes/decodes data source URLs, including URL parameter values, causing the original values to be altered and leading to data loss. Additionally, QgsDataSourceUri does not fully URL-encode the values when assembling the data source string leading to potential data loss.
When constructing a QgsDataSourceUri, parameter values are not fully URL-encoded. In this case only the =is encoded to %26. This can result in incorrect URL parameters being sent in the requests. For example:
Original URL added as WMS source: https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
Actual GetCapabilities Request Sent: https://127.0.0.1/&?&?/?non_standard_param=&?&?&?SERVICE=WMS&REQUEST=GetCapabilities
Expected behaviour
Original URL added as WMS source: https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
Resulting QgsDataSourceUri string (values are fully URL-encoded: dpiMode=7&featureCount=10&tilePixelRatio=0&url=https%3A%2F%2F127.0.0.1%2F%2526%253F%2526%253F%2F%3Fnon_standard_param%3D%2526%253F%2526%253F%2526%253F
Actual GetCapabilities Request Sent: https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F&SERVICE=WMS&REQUEST=GetCapabilities
Steps to reproduce the issue
open QGIS and the request debug console
add a WMS data source with the URL https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
in qgsnewhttpconnection.cpp (363) QUrl decodes some of the URL-encoded characters resulting in https://127.0.0.1/%26?%26?/ QUrl url( txtUrl->text().trimmed() );
in qgsnewhttpconnection.cpp (381) the QUrl query is set to non_standard_param=%26%3F%26%3F%26%3F url.setQuery( query );
in qgsowsconnection.cpp (87) the QgsDataSourceUri param "url" is set to the original url https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F resulting in the param value mUri.setParam( QStringLiteral( "url" ), url );
right click the new WMS data source and click refresh
in qgswmsdataitems.cpp (61) the QgsDataSourceUri is parsed. mUri has the value dpiMode=7&featureCount=10&tilePixelRatio=0&url=https://127.0.0.1/%26%3F%26%3F/?non_standard_param%3D%26%3F%26%3F%26%3F. The key-value separator "=" has been URL-encoded to %3D the other character left untouched making it impossible to retain the original URL. The "url" param of uri becomes https://127.0.0.1/&%3F&%3F/?non_standard_param=&%3F&%3F&%3F resulting in an empty value for non_standard_param. uri.setEncodedUri( mUri );
in qgswmsprovider.cpp (280) the whole thing is URL-decoded resulting in https://127.0.0.1/&?&?/?non_standard_param=&?&?&?
// some services provide a percent/url encoded (legend) uri string, always decode here
uri = QUrl::fromPercentEncoding( uri.toUtf8() );
the GetCapabilities request is made to https://127.0.0.1/&?&?/?non_standard_param=&?&?&?SERVICE=WMS&REQUEST=GetCapabilities
I would like to +1 this issue and provide some additional examples that could be incorporated into the tests, the titiler dynamic tile server accepts many optional parameters in query URLs to enable dynamic styling of COGs, for example:
returns the following RGB rendering of a elevation model scaled between 1600 and 2100 meters with the gist_earth colormap from matplotlib.
While it's trivial to do the same with QGIS's style manager, there are lots of other capabilities including custom algorithms and other parameters important for working with titiler that get striped from the tile request urls by QGIS.
The following GDAL WMS xml file can be loaded in QGIS, but the styling from the above url example get's stripped
For those interested in testing with this file, the source geotiff is fairly small with bounds in EPSG:3857 of 789324.756450882, 5766907.715332875, 790765.7771960256, 5768353.435890727 or in EPSG:4326 of 7.090624928537461, 45.91605844102821, 7.1035698381384185, 45.92509300025415
I'd like to help get #59144 merged, but it looks ready to me at first glance
What is the bug or the crash?
QGIS improperly encodes/decodes data source URLs, including URL parameter values, causing the original values to be altered and leading to data loss. Additionally, QgsDataSourceUri does not fully URL-encode the values when assembling the data source string leading to potential data loss.
When constructing a
QgsDataSourceUri
, parameter values are not fully URL-encoded. In this case only the=
is encoded to%26
. This can result in incorrect URL parameters being sent in the requests. For example:Original URL added as WMS source:
https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
Resulting QgsDataSourceUri string:
dpiMode=7&featureCount=10&tilePixelRatio=0&url=https://127.0.0.1/%26%3F%26%3F/?non_standard_param%3D%26%3F%26%3F%26%3F
Actual GetCapabilities Request Sent:
https://127.0.0.1/&?&?/?non_standard_param=&?&?&?SERVICE=WMS&REQUEST=GetCapabilities
Expected behaviour
Original URL added as WMS source:
https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
Resulting QgsDataSourceUri string (values are fully URL-encoded:
dpiMode=7&featureCount=10&tilePixelRatio=0&url=https%3A%2F%2F127.0.0.1%2F%2526%253F%2526%253F%2F%3Fnon_standard_param%3D%2526%253F%2526%253F%2526%253F
Actual GetCapabilities Request Sent:
https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F&SERVICE=WMS&REQUEST=GetCapabilities
Steps to reproduce the issue
https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
https://127.0.0.1/%26?%26?/
QUrl url( txtUrl->text().trimmed() );
non_standard_param=%26%3F%26%3F%26%3F
url.setQuery( query );
https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
resulting in the param valuemUri.setParam( QStringLiteral( "url" ), url );
dpiMode=7&featureCount=10&tilePixelRatio=0&url=https://127.0.0.1/%26%3F%26%3F/?non_standard_param%3D%26%3F%26%3F%26%3F
. The key-value separator "=" has been URL-encoded to %3D the other character left untouched making it impossible to retain the original URL. The "url" param of uri becomeshttps://127.0.0.1/&%3F&%3F/?non_standard_param=&%3F&%3F&%3F
resulting in an empty value fornon_standard_param
.uri.setEncodedUri( mUri );
https://127.0.0.1/&?&?/?non_standard_param=&?&?&?
https://127.0.0.1/&?&?/?non_standard_param=&?&?&?SERVICE=WMS&REQUEST=GetCapabilities
QNetworkRequest request( url );
Versions
QGIS 3.38.3 (probably all previous versions since QgsDataSourceUri was added and used for non database providers)
Master
Supported QGIS version
New profile
Additional context
Related Issues:
The text was updated successfully, but these errors were encountered: