Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10: CSP WIP #14

Merged
merged 5 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ datasync/client_secret*.json
datasync/credentials.json
datasync/tokens/*
datasync/temp_*
desktop.ini
*/desktop.ini
3 changes: 3 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Header add Content-Security-Policy "default-src 'self' *.mapbox.com data: blob:; style-src 'self' *.mapbox.com 'unsafe-inline' https:; style-src-elem *.mapbox.com https: 'unsafe-inline'; script-src 'self' *.mapbox.com 'unsafe-inline' https: blob:;"

AddType application/json .geojson
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ A webmap of the history of the residents of Old Ballard, funded by the King Coun
Open a command line window, go to this folder, type `python -m SimpleHTTPServer 1883` (for Python 2) or `python -m http.server 1883` (for Python 3) or `python3 -m http.server 1883` (to explicitly select Python3 in an environment that also has Python 2 installed), and leave that session running.

Then the page should be available at http://localhost:1883/ (you can change the number in the python command to also change it in the localhost URL).

## Content Security Policy settings for a web server

Depending on individual server settings, this project may need some [CSP configuration](https://content-security-policy.com/) on its host. **Important: this behaviour may also be browser-specific** because the major browsers do not have consensus on which parts of the CSP spec they support, so it is essential to test a deployment in multiple browsers.

If the map does not appear, check the javascript console. If CSP is the issue, there will be one or more errors referencing `Content Security Policy`. In this case, try the following:

1. If the web server is Apache, directly copy the [.htaccess](.htaccess) file in this project to the same directory as [index.html](index.html). If it's a different server, apply the same CSP directives in that server's syntax.
2. That should dramatically reduce the number of errors. But there may still be complaints about a `blob:https:DOMAINNAME/RANDOMSTRING` worker file. In that instance, set the Content Security Policy `"worker-src 'self' blob:;"` *for the entire site*. This is necessary because Mapbox spawns workers which appear to be at the site's root directory, even if this map is hosted in a subdirectory.

## XML parsing errors in the Javascript Console

Firefox will sometimes put `XML Parsing Error: not well-formed` in the console about `places.geojson`, because without a `.json` file extension it doesn't recognise the file as being JSON. This error appears to be harmless--probably because the code in `onload.js` that parses that file explicitly uses `JSON.parse()` to do it--but looks alarming. It can be silenced by setting the MIME type for `.geojson` files to `application/json`. The included [.htaccess](.htaccess) file does this for Apache servers.
Binary file removed transcripts/desktop.ini
Binary file not shown.