I want to be able to connect a collator node using https://polkadot.js.org/apps that is based on the substrate-parachain-template using branch 'polkadot-v0.9.18' and is being run as a parachain in production, but I do not want to use --rpc-cors=all
. Instead I want to enable origin validation and manually add the default browser origins that are allowed. It mentions what values may be provided to --rpc-cors=
in the documentation here.
--rpc-cors <ORIGINS>
Specify browser Origins allowed to access the HTTP & WS RPC servers.
A comma-separated list of origins (protocol://domain or special `null` value). Value of
`all` will disable origin validation. Default is to allow localhost and
<https://polkadot.js.org> origins. When running in --dev mode the default is to allow
all origins.
In the Substrate implementation here, it shows the list of browser origins that it uses by default, which corresponds to the what it mentions above "Default is to allow localhost and https://polkadot.js.org origins.".
It previously connected successfully when using just --rpc-cors=all
. But why after I provide the options shown below instead does it give the following error in the browser console API-WS: disconnected from wss://<MY_PARACHAIN_DOMAIN>: 1006:: Abnormal Closure
and not output the warning Blocked connection to WebSockets server from untrusted origin: <REQUEST_ORIGIN>
(since it uses 'jsonrpc-ws-server' crate to verify whether each request origin header is in the list of allowed origins) in the collator logs when I then try to connect from the https://polkadot.js.org/apps/?rpc=wss://<MY_PARACHAIN_DOMAIN> endpoint?
./target/release/parachain-collator \
--alice \
--collator \
--force-authoring \
--chain rococo-local-parachain-2000-raw.json \
--port 40333 \
--ws-port 8844 \
--rpc-cors="http://localhost:*,http://127.0.0.1:*,https://localhost:*,https://127.0.0.1:*,https://polkadot.js.org" \
--unsafe-ws-external \
--unsafe-rpc-external \
--rpc-methods=Unsafe` \
-- \
--execution wasm \
--chain ./res/rococo-raw.json \
--port 30343 \
--ws-port 9977
wss://<MY_PARACHAIN_DOMAIN>
- the CORS list if for the browser you connect from, not websocket endpoint it runs on. For your disconnect, ensure it really iswss://
, i.e. behind nginx with a cert.--rpc-cors=all
it successfully connects from the browser when going to polkadot.js.org/apps/?rpc=wss://<MY_PARACHAIN_DOMAIN>, so I think having polkadot.js.org in the--rpc-cors
comma separated list of values covers that, but I still get the same error when I removewss://<MY_PARACHAIN_DOMAIN>
from that list. if I instead try to connect using just ws with polkadot.js.org/apps/?rpc=ws://<MY_PARACHAIN_DOMAIN>, I get browser errorFailed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.