Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

Shared Secret Registration - Invalid Request Signature #33

Closed mbelt closed 2 years ago

mbelt commented 2 years ago

Requests to v1 registration endpoint are being returned 403.

Error from Synapse: method='POST' uri='/_synapse/admin/v1/register' clientproto='HTTP/1.0' site='8008'> SynapseError: 403 - HMAC incorrect

skylord123 commented 2 years ago

Are you running a self-hosted server or using the public matrix server (matrix.org)? This does not work with servers you do not administrate.

What happens when you go to this url in your browser? <your_server>/_synapse/admin/v1/register (use the same domain that the client is using)

Do you have shared secret registration enabled in your Synapse configuration file?

mbelt commented 2 years ago

Self hosted matrix server, Synapse v1.43.0. Shared secret registration is enabled, tested working. The GET that node-red-contrib-matrix-chat makes to /v1/register is successful, but the subsequent POST is 403. (Invalid HMAC)

I was able to get the Registration Node working after removing "user_type": "bot" from the payload. This file is referenced in the help doc as source of truth for valid user_type, and I took away that valid options are None, "bot", and "support". The matrix registration api doc says otherwise, that valid options are "admin" and "notadmin".

Haven't dug any further on what works / doesn't work.

skylord123 commented 2 years ago

Yes you are right. The HMAC was being generated incorrectly. Looks like when I ported it from Python I missed the part that added the user_type.

I just fixed this and tested it with the bot user_type and it worked perfectly. I'll be deploying a new release today that will fix this.

Thanks for bringing this to my attention :)

EDIT: For future reference here is the Python version https://github.com/matrix-org/synapse/blob/66c4b774fdc72f2f6bef69b2ffd5632f95e27b63/synapse/_scripts/register_new_matrix_user.py#L57-L70

skylord123 commented 2 years ago

Just released 0.3.0 that fixes this. Give it another try and if the problem persists feel free to re-open the issue.