Cors error with MetaMask
Closed this issue · 6 comments
Describe the bug
There seems to be a CORS error when http://localhost:3000
or http://127.0.0.1:3000
is added to MetaMask.
To Reproduce
Steps to reproduce the behavior:
- Run blutgang
- Try adding the designated endpoint to MetaMask
- Cry because CORS is taking away your joy from life.
Expected behavior
Expected to connect.
Specs:
- OS: Tried through an Envoy proxy in k8s, running on Ubuntu 22.04 and via local M1 Pro Mac.
- Kernel: latest for arm64
- Blutgang version: 0.2.0
Blutgang options:
used the example default config with +1 RPC
- DB mode: [HighThroughput]
- DB compression: [no]
- Cache capacity: [1000000000]
- MA length: [20]
- RPCs used: [llamanodes,merkle,geth]
Additional context
The issue is similar to when --http.corsdomain is not enabled in geth
.
Blutgang doesn't do CORS filtering. It seems that metamask is giving Infura type not known
errors in the console when you add it as a new network.
I'll need to dig deeper into whats making it unhappy when i get some free time as im currently at Devconnect
P.S: Frame wallet is more than happy to use blutgang, so its probably just metamask being weird
Thanks for the reply @makemake-kbo, take your time.
So far what I've gathered is that sending an OPTIONS
request will throw back a {"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Failed to deserialize the JSON body into the target type"}}
, however I can only poke Rust code with a stick, so wasn't really able to figure out a solution yet.
ok, ive seem to have narrowed it down to the JSON not being serialized properly. this might be a problem with either blutgang or a third party library. will have to investigate further
Edit: nvm, that doesnt seem to be it...
Edit 2: The issue seems to stem from the fact that metamask sends a request with an empty body, which blutgang doesnt know what to do with so it rejects and errors it. Heres how the request looks:
"Request"{
"method":"OPTIONS",
"uri":"/",
"version":HTTP/1.1,
"headers":{
"host":"127.0.0.1:3000",
"user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0",
"accept":"*/*",
"accept-language":"en-GB,en;q=0.5",
"accept-encoding":"gzip, deflate, br",
"access-control-request-method":"POST",
"access-control-request-headers":"content-type",
"origin":"moz-extension://8ecf6143-adcf-4e06-9787-d0895acaf7b5",
"dnt":"1",
"connection":"keep-alive",
"sec-fetch-dest":"empty",
"sec-fetch-mode":"cors",
"sec-fetch-site":"cross-site"
},
"body":"Body(Empty)"
}
Ill have to open an issue on the metamask repo to figure out what exactly its doing because this isnt making a lot of sense.
Edit 3: Issue opened MetaMask/metamask-extension#21803
ok, ive seem to have narrowed it down to the JSON not being serialized properly. this might be a problem with either blutgang or a third party library. will have to investigate further
Edit: nvm, that doesnt seem to be it...
Edit 2: The issue seems to stem from the fact that metamask sends a request with an empty body, which blutgang doesnt know what to do with so it rejects and errors it. Heres how the request looks:
"Request"{ "method":"OPTIONS", "uri":"/", "version":HTTP/1.1, "headers":{ "host":"127.0.0.1:3000", "user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0", "accept":"*/*", "accept-language":"en-GB,en;q=0.5", "accept-encoding":"gzip, deflate, br", "access-control-request-method":"POST", "access-control-request-headers":"content-type", "origin":"moz-extension://8ecf6143-adcf-4e06-9787-d0895acaf7b5", "dnt":"1", "connection":"keep-alive", "sec-fetch-dest":"empty", "sec-fetch-mode":"cors", "sec-fetch-site":"cross-site" }, "body":"Body(Empty)" }
Ill have to open an issue on the metamask repo to figure out what exactly its doing because this isnt making a lot of sense.
Edit 3: Issue opened MetaMask/metamask-extension#21803
Thank you for the update!
Ive been able to reproduce this locally on my mac, but others have been reporting that they could use blutgang with metamask.
Theres a good chance this is a macos only thing. Ill investigate when i get access to a non macos computer.
Should be fixed in https://github.com/rainshowerLabs/blutgang/tree/0.3.0. Leaving as open until it gets merged.