Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket authentication failures since 2023-09-19 #1230

Open
the-real-ed opened this issue Sep 27, 2023 · 1 comment
Open

Websocket authentication failures since 2023-09-19 #1230

the-real-ed opened this issue Sep 27, 2023 · 1 comment

Comments

@the-real-ed
Copy link

Hi,

I'm a matterircd user (Slack/Mattermost <-> IRC bridge), which utilises the slack-go library.

What happened

On September 19th (approximately 3AM UTC) I stopped receiving messages on my IRC client (IRC client <-> matterircd (uses slack-go) <-> Slack).

I investigated the logs and found the following errors (previously unseen):

websocket_managed_conn.go:62: RTM connection succeeded on try 27
websocket_managed_conn.go:387: Incoming Event: {"type":"error","error":{"msg":"invalid_auth","code":401,"source":"gatewayserver-syd-1"}}
websocket_managed_conn.go:477: RTM Error - received unmapped event "error": {"type":"error","error":{"msg":"invalid_auth","code":401,"source":"gatewayserver-syd-1"}}
websocket_managed_conn.go:219: killing connection signaled
websocket_managed_conn.go:181: Connecting to RTM

The lack of authentication leads to HTTP 429 (Too Many Requests) responses, which I was able to determine with custom code.

I updated the Token/Cookie to rule out obvious credential errors. This did not resolve the issues.

Expected behavior

The correct behaviour is for Slack messages to appear in my IRC client (via the matterircd IRC <-> Slack bridge).

Steps to reproduce

On investigating, I found other Slack<->IRC bridge users were also being affected, e.g.: insomniacslk/irc-slack#183 (also uses slack-go). The issue links to another Slack<->IRC bridge (written in Python) that hints at the solution: ltworf/localslackirc#426

reproducible code

As a proof-of-concept, I was able to hardcode a work-around which resolved the issue for me:

diff --git a/vendor/github.com/slack-go/slack/websocket_managed_conn.go b/vendor/github.com/slack-go/slack/websocket_managed_conn.go
index f107b2a..378cf91 100644
--- a/vendor/github.com/slack-go/slack/websocket_managed_conn.go
+++ b/vendor/github.com/slack-go/slack/websocket_managed_conn.go
@@ -222,6 +222,9 @@ func (rtm *RTM) startRTMAndDial(useRTMStart bool) (info *Info, _ *websocket.Conn
        // Only use HTTPS for connections to prevent MITM attacks on the connection.
        upgradeHeader := http.Header{}
        upgradeHeader.Add("Origin", "https://api.slack.com")
+       upgradeHeader.Add("user-agent", "test-agent")
+       upgradeHeader.Add("Authorization", "Bearer xoxc-<REDACTED>")
+       upgradeHeader.Add("Cookie", "d=xoxd-<REDACTED>;")
        dialer := websocket.DefaultDialer
        if rtm.dialer != nil {
                dialer = rtm.dialer

manifest.yaml

Versions

  • slack-go/slack: v0.12.2 (used in matterircd), v0.12.1 (used in irc-slack)

Apologies for not providing a full solution, but I am not familiar with Golang or websockets. If you're able to resolve this issue, I can raise another issue with project matterircd (and irc-slack) to update their dependencies/code.

Regards

@juztin
Copy link

juztin commented Sep 25, 2024

Also running into auth issues with the messages example

Created an app/token and used the above example with the newly created token and only ever get "invalid_auth".

UPDATE

Got this working... was just stuck on the very convoluted Slack instructions for such a simple task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants