Skip to content

Fix QGIS Server service URL calculation when X-Forwarded-Proto header has multiple values#64942

Open
jgrocha wants to merge 3 commits intoqgis:masterfrom
jgrocha:logheaders
Open

Fix QGIS Server service URL calculation when X-Forwarded-Proto header has multiple values#64942
jgrocha wants to merge 3 commits intoqgis:masterfrom
jgrocha:logheaders

Conversation

@jgrocha
Copy link
Copy Markdown
Member

@jgrocha jgrocha commented Feb 15, 2026

Description

This PR does 3 different (little) things. For each feature, there is only one piece of code changed. Comments are welcome regarding each feature.

There are 3 more formatting changes in this PR. They were produced by scripts/astyle.sh.

I was still using scripts/astyle.sh on files outside src/core. So sorry! I've updated the PR using clang-format for files under src/server.

1. Fix #64940

Support for protocol list in X-Forwarded-Proto header. Now it is possible to receive a X-Forwarded-Proto header like: X-Forwarded-Proto: https, https, HTTPS.

2. Read QGIS_SERVER_SERVICE_URL environment variable in every request

Only the QGIS_PROJECT_FILE file is read on every request. This variable can be set in a rewrite rule, for example, for every request. Other environment variables are read only when the server starts.

This PR also reads QGIS_SERVER_SERVICE_URL environment variable in every request, giving more flexibility to set it, when headers are not enough. This PR was motivated by this limitation: when the service URL is not being properly computed, we must provide a way to force it.

For example, with this PR we can define something like this on Apache (example with mod_rewrite):

RewriteRule ^/postgresql/(.*)/(.*)/(.*)/cgi-bin/qgis_mapserv.fcgi /cgi-bin/qgis_mapserv.fcgi [NC,PT,E=QGIS_SERVER_SERVICE_URL:https://%{HTTP_HOST}/postgresql/$1/$2/$3/cgi-bin/qgis_mapserv.fcgi,E=QGIS_PROJECT_FILE:postgresql:?service=$1&sslmode=disable&schema=$2&project=$3]

This rewrite rule defines two environment variables on every request:

  • QGIS_SERVER_SERVICE_URL
  • QGIS_PROJECT_FILE

For a request like this: https://osgeo.local/postgresql/5363_carttop1_coimbra_20250401/public/testewfs/cgi-bin/qgis_mapserv.fcgi, the variables will be defined as:

If we change the project being served, both QGIS_SERVER_SERVICE_URL and QGIS_PROJECT_FILE are set automatically.

3. Log headers

Before this PR, headers could be logged only on a debug version. On a quality/production environment, it is not easy to compile and run a debug version to check the atual headers received.

This PR removes the header logging on debug versions and make it happen on release versions, depending on QGIS_SERVER_LOG_LEVEL variable.

@github-actions github-actions bot added this to the 4.0.0 milestone Feb 15, 2026
@github-actions github-actions bot added the Server Related to QGIS server label Feb 15, 2026
@jgrocha jgrocha changed the title Fix QGIS Server service URL calculation when X-Forwarded-Proto headers has multiple values Fix QGIS Server service URL calculation when X-Forwarded-Proto header has multiple values Feb 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 16, 2026

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit a0f0681)

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This app is not notarized, run sudo xattr -d com.apple.quarantine /Applications/QGIS*.app to avoid the warning
(Built from commit a0f0681)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 4, 2026
@jgrocha jgrocha removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

While we hate to see this happen, this PR has been automatically closed because it has not had any activity in the last 21 days. If this pull request should be reconsidered, please follow the guidelines in the previous comment and reopen this pull request. Or, if you have any further questions, just ask! We love to help, and if there's anything the QGIS project can do to help push this PR forward please let us know how we can assist.

@github-actions github-actions bot closed this Mar 27, 2026
@jgrocha jgrocha reopened this Mar 27, 2026
@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Related to QGIS server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QGIS Server: unable to calculate service URL if X-Forwarded-Proto has more than one value

1 participant