question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify host for customer headers

See original GitHub issue

This issue is intended as a start of a discussion for adding support to limit the hosts to which custom headers are sent.

mapbox-gl-js map supports a transformRequest option which allows custom headers to be set. It is implemented as a function where you can implement logic to add headers for specific hosts using something like this:

transformRequest: (url, resourceType) => {
        if (resourceType === 'Tile' && url.match('example.com')) {
            return {
                url: url,
                headers: { 'Authorization': 'secret' }
            };
        }
    }

The common use case for transformRequest is to add custom authorisation headers for authenticated tile servers.

In react-native-mapbox-gl/maps you can also add custom headers, but they will be added to every mapbox tile request, not just to a specific host/source. This leaks security sensitive data to mapbox servers (which ignore the headers) and also potentially to other hosts that shouldn’t receive the headers.

I understand that a JS function passed to native code will not work, so the exact same approach as mapbox-gl-js doesn’t fit on the react-native-mapbox-gl model. But because the custom headers intended for specific hosts is such a common thing for anyone using a custom tile server, I propose we solve at least the problem of limiting headers to specific hosts.

I see several ways to solve this and there may be more.

  1. add hosts array to addCustomHeader
  2. add urlFilter regex to addCustomHeader
  3. Either 1 or 2 + customHeaders, but on VectorSource, ShapeSource, RasterSource and ImageSource.

I appreciate any feedback on the problem, the proposed solutions. I’m happy to contribute the solution in a PR if we can settle on an approach.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
dave-mosercommented, Jan 11, 2021

I am having the same issue. I need to sign the request to our map tile provider. I can do this with the react-map-gl component in a web page with the transformRequest option. Is there any similar functionality for react-native-mapbox-gl?

0reactions
stale[bot]commented, Apr 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Host - HTTP - MDN Web Docs
The Host request header specifies the host and port number of the server to which the request is being sent. If no port...
Read more >
What is HTTP "Host" header? - Stack Overflow
The Host Header tells the webserver which virtual host to use (if set up). You can even have the same virtual host using...
Read more >
Host Header - What is an HTTP Host Header injection?
The HTTP host header is a request header that specifies the domain that a client (browser) wants to access. This header is necessary...
Read more >
Configure multiple Web sites using Host Headers - Hivelocity
To configure Web sites by using the Host Header Names feature, follow these steps: 1. Click Start, point to Administrative Tools, and then...
Read more >
Specify host for customer headers · Issue #504 · rnmapbox/maps
This issue is intended as a start of a discussion for adding support to limit the hosts to which custom headers are sent....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found