Changeset 18437 in josm for trunk/src/org


Ignore:
Timestamp:
2022-04-27T21:26:39+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #21935: Avoid leaking Authorization headers on redirects in HttpClient

This was found due to a change in where OSM stores GPX data files.
OSM now uses s3 buckets, and redirects using a signed URL. S3 does
not like multiple authentication methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r18409 r18437  
    189189                            " Can''t redirect. Aborting.", cr.getResponseCode()));
    190190                } else if (maxRedirects > 0) {
     191                    final URL oldUrl = url;
    191192                    url = new URL(url, redirectLocation);
    192193                    maxRedirects--;
    193194                    logRequest(tr("Download redirected to ''{0}''", redirectLocation));
     195                    // Fix JOSM #21935: Avoid leaking `Authorization` header on redirects.
     196                    if (!Objects.equals(oldUrl.getHost(), this.url.getHost()) && this.getRequestHeader("Authorization") != null) {
     197                        logRequest(tr("Download redirected to different host (''{0}'' -> ''{1}''), removing authorization headers",
     198                                oldUrl.getHost(), url.getHost()));
     199                        this.headers.remove("Authorization");
     200                    }
    194201                    response = connect();
    195202                    successfulConnection = true;
Note: See TracChangeset for help on using the changeset viewer.