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.
Context
We are deploying Cryptpad in production behind our reverse proxy that is just... a reverse proxy.
It can not serve files or have complex headers logic, so we use the standalone node.js process to serve our files and compute our headers.
From the CSP headers perspective, the main change with the development environment is that the sandbox URL is different from the domain URL.
Bug
Currently, there are multiple errors when generating the headers, all due to the fact that the sandbox URL is different from the domain one:
sandbox !== domain
is always false as we have prepended a white space in front of thedomain
variable two lines before but not (yet) in front of thesandbox
URL. This is a benign error as we can expect the user has either not set the sandbox URL OR that they defined it to a different value./^https:/.test(domain)
is always false as we have prepended a space at the beginning of thedomain
variable. This is our critical bug, as we are falling back in thehttp
case, but there is nohttp://
entry, so we are simply outputting thedomain
entry without any modification, which means in the end we are simply duplicating the https entry and we lack thewss
entry, which make thecheckup
script fails.My patch
It seems that mutating the
domain
variable to prepend a space breaks the least astonishment property from the developer perspective. Indeed, the following bugs are due to the fact code has been written with the assumption that this space does not exist. As a consequence, I have removed this space from thedomain
andsandbox
variables and manually added spaces where needed.I have simplified the websocket rewrite of the URL for the
connect-src
entry. It works for us in production (https://pad.deuxfleurs.fr), it should be a bit more secured, and easier to maintain.I have fixed a comment that seemed outdated (there was no wildcard for plain text websockets, and now, there is no websocket wildcard at all).