teambtcmap / btcmap.org

Free and open source bitcoin map web application
https://btcmap.org
GNU Affero General Public License v3.0
41 stars 10 forks source link

Update iFrame guidance re location premissions #28

Closed dadofsambonzuki closed 1 year ago

dadofsambonzuki commented 1 year ago

Update Embedding Guidance when known to prevent cross-site geolocation errors.

PeterRounce commented 1 year ago

I have got this working on a test site and the Bolt Card website.

It seems to need allow="geolocation" in the iframe link as a minimum.

Additionally, I added the http header permissions-policy: geolocation=* and some Javascript to get the location on the referring page.

<script>
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(() => {})
  }
</script>

Once it was working, it seems to be ok to remove the http header and Javascript.

I'm not that certain of the mechanisms at work here so would like someone else to have a look as well please.

secondl1ght commented 1 year ago

Thanks for doing the research on this @PeterRounce! I will do some more testing and then update the README with the solution.

secondl1ght commented 1 year ago

I have updated the README with the instructions that I think are the most accurate - @PeterRounce do you mind trying this on your site and confirming that it works please?

PeterRounce commented 1 year ago

I've updated the http header from permissions-policy: * to permissions-policy: geolocation=https://btcmap.org on the Bolt Card website and it has the error back
image

I note that the temporary test site has no http header but uses the JS to get location and still works.

I didn't want to put a request for location to the user on loading the Bolt Card website because it's not clear to them why I am asking for that permission at that point.

secondl1ght commented 1 year ago

@PeterRounce can you try adding it in the exact same format as readme? It should be: Permissions-Policy: geolocation=("https://btcmap.org")

PeterRounce commented 1 year ago

I have updated it in AWS Cloudfront as below. The header name is lower cased by Cloudfront and should not make a difference. cf-hdr

We get the same error as before.

PeterRounce commented 1 year ago

trials show that this works
Permissions-Policy: geolocation=(self "https://www.btcmap.org")