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:*,*,https://localhost:*,*,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
  • 4
    Luke, in general can I suggest you condense your questions into the specific information needed to help you. It is impossible to parse all of the content you are writing. Treat this as a question and answer forum, not a blog.
    – Shawn Tabrizi
    Apr 2, 2022 at 6:49
  • Shawn i've condensed the question now Apr 2, 2022 at 21:08
  • 2
    This would be incorrect 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 is wss://, i.e. behind nginx with a cert.
    – Jaco
    Apr 4, 2022 at 13:12
  • 1
    If I use --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 remove wss://<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 error Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS. Apr 5, 2022 at 18:30
  • 1
    @Purple_Turtle hey, have you found a solution for this --rpc-cors problem? Because I tried a long time ago to use this flag and it wasn't working when I specified the domains
    – rirotho
    Sep 12, 2023 at 18:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.