Skip to content

Slackdiff: Make Slack file upload respect a configured HTTP proxy#3587

Merged
robertcheramy merged 2 commits intoytti:masterfrom
cybercom-finland:3534-fix-slack-proxy
Aug 1, 2025
Merged

Slackdiff: Make Slack file upload respect a configured HTTP proxy#3587
robertcheramy merged 2 commits intoytti:masterfrom
cybercom-finland:3534-fix-slack-proxy

Conversation

@varesa
Copy link
Contributor

@varesa varesa commented Jul 24, 2025

Pre-Request Checklist

  • Passes rubocop code analysis (try rubocop --auto-correct)
  • Tests added or adapted (try rake test)
    • slackdiff has no existing tests at the moment, and the fact that the hook heavily leans on other infrastructure (slack, a HTTP proxy) I don't think my skills as someone touching Ruby for the second time in their life are quite up to the task of figuring out the required mocks/scaffolding.
  • Changes are reflected in the documentation
  • User-visible changes appended to CHANGELOG.md

Description

The new slack file upload API introduced by commit b92e620 to replace the deprecated API which was not available to new users (see issue #3189) introduced a new HTTP call that was not using the provided proxy configuration and broke environments where a proxy was necessary.

This commit fixes the regression reported in the issue #3534 by using the same proxy setting for the new HTTP POST request to https://files.slack.com/

Closes issue #3534

A minor related change:

I was unable to figure out why the slack app I created in a sandbox workspace did not show up in the list of apps I could invite into a channel, so in order to actually get the bot to post anything to the channel, I made the bot attempt to automatically join the channel if an upload fails due to the bot not being in the channel. I can split that into a separate PR, but since it is a minor change, I hope this will be good enough.

Testing

Three scenarios have been tested with a dummy device, a git output and a sandbox slack organization:

No proxy

No regresssions are visible when testing without a proxy in the config:

2025-07-24 16:45:10.297957 I [5870:200] Oxidized::Worker -- Configuration updated for /test
2025-07-24 16:45:10.298056 I [5870:200] SlackDiff -- Connecting to slack
2025-07-24 16:45:10.580717 I [5870:200] SlackDiff -- Connected
2025-07-24 16:45:10.582302 I [5870:200] SlackDiff -- Posting diff as snippet to C09756V8TGA
2025-07-24 16:45:11.777906 I [5870:200] SlackDiff -- Finished

With a proxy

Before the change it could be seen from proxy logs that three HTTP requests were made through the proxy:

2025-07-24 15:53:18.045 7f5203e006c0 Request: slack.com:443/
2025-07-24 15:53:18.427 7f5203e006c0 Request: slack.com:443/
2025-07-24 15:53:19.198 7f5203e006c0 Request: slack.com:443/

After the change four requests are seen:

2025-07-24 16:07:38.059 7f5203e006c0 Request: slack.com:443/
2025-07-24 16:07:38.437 7f52034006c0 Request: slack.com:443/
2025-07-24 16:07:38.887 7f52034006c0 Request: files.slack.com:443/
2025-07-24 16:07:39.347 7f52034006c0 Request: slack.com:443/

And the request succeeds:

2025-07-24 16:47:51.341099 I [6454:200] Oxidized::Worker -- Configuration updated for /test
2025-07-24 16:47:51.341194 I [6454:200] SlackDiff -- Connecting to slack
2025-07-24 16:47:51.781547 I [6454:200] SlackDiff -- Connected
2025-07-24 16:47:51.783480 I [6454:200] SlackDiff -- Posting diff as snippet to C09756V8TGA
2025-07-24 16:47:53.388813 I [6454:200] SlackDiff -- Finished

Bot not in channel

If the bot is not in the channel, the bot will attempt to join the channel and retry the request:

2025-07-24 16:49:01.960397 I [6649:200] Oxidized::Worker -- Configuration updated for /test
2025-07-24 16:49:01.960506 I [6649:200] SlackDiff -- Connecting to slack
2025-07-24 16:49:02.503192 I [6649:200] SlackDiff -- Connected
2025-07-24 16:49:02.505366 I [6649:200] SlackDiff -- Posting diff as snippet to C09756VJHBL
2025-07-24 16:49:03.849792 I [6649:200] SlackDiff -- Not in specified channel, attempting to join
2025-07-24 16:49:05.076074 I [6649:200] SlackDiff -- Finished

Causing 2 extra requests:

2025-07-24 16:49:02.038 7f52034006c0 Request: slack.com:443/
2025-07-24 16:49:02.591 7f52034006c0 Request: slack.com:443/
2025-07-24 16:49:02.950 7f5203e006c0 Request: files.slack.com:443/
2025-07-24 16:49:03.426 7f5203e006c0 Request: slack.com:443/
2025-07-24 16:49:03.912 7f5203e006c0 Request: slack.com:443/
2025-07-24 16:49:04.381 7f5203e006c0 Request: slack.com:443/

@varesa varesa force-pushed the 3534-fix-slack-proxy branch from 0414d0e to 9166799 Compare July 24, 2025 13:52
@varesa
Copy link
Contributor Author

varesa commented Jul 24, 2025

Fixed a bad rebase(?)

Specifying a channel where the bot/app is not a member would cause
a Slack::Web::Api::Errors::NotInChannel error when attempting to
post the file.

In case the bot token has been granted the channels:join oauth scope
and the target channel is joinable, making the bot join automatically
will make usage easier.
The new slack file upload API introduced by commit
b92e620 to replace
the deprecated API which was not available to new
users (see issue ytti#3189) introduced a new HTTP call
that was not using the provided proxy configuration
and broke environments where a proxy was necessary.

This commit fixes the regression reported in the
issue ytti#3534 by using the same proxy setting for the
new HTTP POST request to https://files.slack.com
@varesa varesa force-pushed the 3534-fix-slack-proxy branch from 9166799 to 4a99c2a Compare July 24, 2025 14:03
@robertcheramy robertcheramy merged commit 4a99c2a into ytti:master Aug 1, 2025
7 checks passed
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

Successfully merging this pull request may close these issues.

3 participants