Support referrerPolicy option for transformRequest function when using fetch #12590
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi folks,
we recently had to change the referrer policy on our website to
same-origin
for security reasons. As a result, we are not able to use Mapbox anymore -- the change of policy caused some Mapbox APIs return 403 Forbidden, as the API requires Referer header to be set on requests in order to identify clients, which isn't allowed by our new policy. (see more at https://docs.mapbox.com/accounts/guides/tokens/#requirements-and-limitations)We cannot relax the referrer policy globally (e.g. to
strict-origin-when-cross-origin
), but we can relax it for the specific requests to Mapbox. The solution is to use referrerPolicy option on fetch.This PR adds support for overriding referrer policy by returning it from transformRequest callback function on Map.
Note that this feature only works in browsers that support Fetch API and Request interface.
Related issues:
#10309
#12568
I'd be happy to add some tests but it seems that the underlying testing environment (sinon) doesn't support fetch/Request and the tests use XMLHttpRequest, which doesn't support referrer policy overrides. I tested this manually in the sandbox and also on our website by modifying
mapbox-gl-js
source code in installed node_modules and it works as intended.Launch Checklist
mapbox-gl-js
changelog:<changelog>Support referrerPolicy option for transformRequest function when using fetch</changelog>