sylvainjule / kirby-locator

A simple map & geolocation field, built on top of open-source services and Mapbox. Kirby 3 and 4.
97 stars 14 forks source link

[panel] mapbox doesn't load when using a token with url restrictions #46

Closed rasteiner closed 2 years ago

rasteiner commented 2 years ago

Hello Sylvain :)

In the panel, Mapbox tiles can't be loaded when using a "non public" token. This is because the Kirby panel (since 3.4) blocks the referrer header (here).

I don't know if this should be an issue with Locator, the Kirby panel or Leaflet.

Locator could circumvent this issue by overriding the meta tag, with something like:

document.querySelector("meta[name=referrer]").content = "origin";

Kirby could solve this by using a less strict referrer policy. Something like "origin" or "no-referrer-when-downgrade"...

Leaflet could solve this by adding a referrer policy to their tiles. Actually they did this a few days ago, but considering their last "release" was in september 2020, I don't know how long it will take to get this option in a stable version...

I will crosspost an issue also on Kirby, and then link here.

sebastiangreger commented 2 years ago

Hi! I just added a bit of context/history about that strict referrer policy of the Kirby panel in a comment on that issue in the Kirby core repo.

I'm not able to try this out right now and this is based on a really quick glance at the plugin's code, but I think this might actually be possible to resolve by changing line https://github.com/sylvainjule/kirby-locator/blob/73553ece28d6c92e6075a240917de8c1cb5a368a/src/field/Locator.vue#L38 to <div class="k-locator-container" referrerpolicy="strict-origin-when-cross-origin"> or whatever is the strictest policy that Mapbox accepts for verification.

An element-specific referrerpolicy overrides the page-wide policy for this element and all its children, hence it should (?!) also be inherited by any image elements of the map? My apologies in advance if I'm overlooking something obvious – we did this for an iframe over at the kirby-embed plugin (Github issue) but I haven't actually ever tried this for JS-generated elements.

rasteiner commented 2 years ago

I didn't know that referrerpolicy is inherited by child elements, actually I thought that it would be only valid on img / a / iframe / script / etc... elements. I'll try this out and let you know :)

rasteiner commented 2 years ago

Are you sure it worked for the other plugin? According to my tests done now, it doesn't really seem to be inherited, at least not in Chrome and MDN only says

You can specify the referrerpolicy attribute on \, \, \, \