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

Sending more than ~99 lines to Slack fails with too_many_attachments #238

Closed
justinsteven opened this issue May 21, 2022 · 4 comments · Fixed by #241
Closed

Sending more than ~99 lines to Slack fails with too_many_attachments #238

justinsteven opened this issue May 21, 2022 · 4 comments · Fixed by #241

Comments

@justinsteven
Copy link
Contributor

What happens

When sending 99 lines to Slack, shoutrrr splits on newline and successfully sends it as 99 attachments

When sending 100 lines to Slack, shoutrrr splits on newline and attempts to send it as 100 attachments. This fails with the err "failed to send slack notification: webhook response: too_many_attachments"

Note that in some of my other testing, sending 100 lines succeeds but 101 lines fails. I have an off-by-one error somewhere.

What is expected

Sending any number of lines to Slack, provided it is within the character limit, succeeds.

Demo

Using the following harness:

package main

import (
    "fmt"
    "github.com/containrrr/shoutrrr"
    "io"
    "os"
)

func main() {
    if len(os.Args) < 2 {
        fmt.Printf("Usage: %s <url>\n", os.Args[0])
        os.Exit(1)
    }

    url := os.Args[1]

    bufB, err := io.ReadAll(os.Stdin)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    buf := string(bufB)

    err = shoutrrr.Send(url, buf)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

Sending 99 lines succeeds:

% yes | head -n99 | go run shoutrrr_harness.go $URL && echo success
success

While sending 100 lines fails:

% yes | head -n100 | go run shoutrrr_harness.go $URL && echo success
failed to send slack notification: webhook response: too_many_attachments
exit status 1

Note that sending 99 relatively long lines still succeeds, indicating this is a problem caused by line count not character count:

% yes AAAAAAAAAAAAAAAAAAAAAAAAAAA | head -n99 | go run shoutrrr_harness.go $URL && echo success
success
@piksel
Copy link
Member

piksel commented May 21, 2022

Thanks for testing these!

@piksel
Copy link
Member

piksel commented May 21, 2022

Also, you can use the shoutrrr CLI (go install github.com/containrrr/shoutrrr/shoutrrr@latest) to test it instead of the above harness. You would need to use xargs or a FIFO though, since it does not support reading message from stdin (should be supported in next release though).

@justinsteven
Copy link
Contributor Author

Thanks for that. Being able to feed via stdin was exactly the reason I shied from the CLI, good to hear it's coming soon!

@piksel
Copy link
Member

piksel commented May 21, 2022

@justinsteven ref #243

justinsteven added a commit to justinsteven/notify that referenced this issue May 22, 2022
Inclues fixes for:

* containrrr/shoutrrr#238
  * Sending more than ~99 lines to Slack fails with too_many_attachments
* containrrr/shoutrrr#240
  * Sending 2000, 4000 or 6000 characters to Discord panics
* containrrr/shoutrrr#244
  * Sending 1999, 3999 or 5999 characters to Discord panics
  * (Incomplete fix for the above)
ehsandeep added a commit to projectdiscovery/notify that referenced this issue May 30, 2022
* go.mod update to 1.17 and dependency synchronisation

* Docker file update to use go 1.18 and "go install" instead of "go get"

* Minor documentation updates

* GitHub action version updates

* goreleaser-action version fix

* Allow -bulk to work with stdin

* go mod update

* replaced helper function with lib

* Do chunked reading in -bulk mode

Reduces memory usage when input is big

Also includes the fix for #134 (makes testing easier)

* Move bulkSplitter to util.go

* Remove unused function

* Refactor bulkSplitter

Simplified looping. Also, we no longer truncate mid-line unless it's the first
line of a chunk (in such a case we have no option but to truncate). A truncated
line will be followed by an ellipsis. Otherwise we're splitting chunks at the
last possible newline without exceeding charLimit for that chunk.

* Bugfix: Always remove trailing newlines

* Bump shoutrrr for long message fixes

Inclues fixes for:

* containrrr/shoutrrr#238
  * Sending more than ~99 lines to Slack fails with too_many_attachments
* containrrr/shoutrrr#240
  * Sending 2000, 4000 or 6000 characters to Discord panics
* containrrr/shoutrrr#244
  * Sending 1999, 3999 or 5999 characters to Discord panics
  * (Incomplete fix for the above)

* minor changes

Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
Co-authored-by: forgedhallpass <13679401+forgedhallpass@users.noreply.github.com>
Co-authored-by: mzack <marco.rivoli.nvh@gmail.com>
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 a pull request may close this issue.

2 participants