Skip to content
Open
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
10 changes: 10 additions & 0 deletions .changeset/fix-csp-ws-http-scheme-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"nostream": patch
---

Fix the Content-Security-Policy `connect-src` directive for relays served over plain `ws://`.

The web app factory derived an HTTP(S) origin from the relay's WebSocket URL but mapped
`ws:` to the invalid scheme `':'`, which the WHATWG URL API silently ignores. As a result the
`connect-src` directive kept a `ws://…` entry instead of the intended `http://…` origin for
local/dev, Tor, or reverse-proxied setups. The `ws:` protocol now correctly maps to `http:`.
2 changes: 1 addition & 1 deletion src/factories/web-app-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createWebApp = (): Express => {

const relayUrl = new URL(settings.info.relay_url)
const webRelayUrl = new URL(relayUrl.toString())
webRelayUrl.protocol = relayUrl.protocol === 'wss:' ? 'https:' : ':'
webRelayUrl.protocol = relayUrl.protocol === 'wss:' ? 'https:' : 'http:'

const directives = {
'img-src': ["'self'", 'data:', 'https://cdn.zebedee.io/an/nostr/'],
Expand Down
Loading