Skip to content

Commit

Permalink
Merge dev into main
Browse files Browse the repository at this point in the history
Co-authored-by: Miles Moonlove <[email protected]>
  • Loading branch information
germanoeich and ssMMiles authored Mar 8, 2024
1 parent 9711f99 commit b9b3dfe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/bucketpath.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lib

import (
"encoding/base64"
"strings"
"time"
"unicode/utf8"
Expand Down Expand Up @@ -109,6 +110,11 @@ func GetOptimisticBucketPath(url string, method string) string {
return "/" + MajorGuilds + "/!/channels"
}
fallthrough
case MajorInteractions:
if numParts == 4 && parts[3] == "callback" {
return "/" + MajorInteractions + "/" + parts[1] + "/!/callback"
}
fallthrough
case MajorWebhooks:
fallthrough
default:
Expand Down Expand Up @@ -151,6 +157,34 @@ func GetOptimisticBucketPath(url string, method string) string {
break
}

// Strip webhook tokens, or extract interaction ID
if len(part) >= 64 {
// aW50ZXJhY3Rpb246 is base64 for "interaction:"
if !strings.HasPrefix(part, "aW50ZXJhY3Rpb246") {
bucket.WriteString("/!")
continue
}

var interactionId string

// fix padding
if i := len(part) % 4; i != 0 {
part += strings.Repeat("=", 4-i)
}

decodedPart, err := base64.StdEncoding.DecodeString(part)
if err != nil {
interactionId = "Unknown"
} else {
interactionId = strings.Split(string(decodedPart), ":")[1]
}

bucket.WriteByte('/')
bucket.WriteString(interactionId)
continue
}


// Strip webhook tokens and interaction tokens
if (currMajor == MajorWebhooks || currMajor == MajorInteractions) && len(part) >= 64 {
bucket.WriteString("/!")
Expand Down
2 changes: 2 additions & 0 deletions lib/bucketpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestPaths(t *testing.T) {
{"/api/v9/invites/dyno", "GET", "/invites/!"},
// Interactions major
{"/api/v9/interactions/203039963636301824/aW50ZXJhY3Rpb246ODg3NTU5MDA01AY4NTUxNDU0OnZwS3QycDhvREk2aVF3U1BqN2prcXBkRmNqNlp4VEhGRjZvSVlXSGh4WG4yb3l6Z3B6NTBPNVc3OHphV05OULLMOHBMa2RTZmVKd3lzVDA2b2h3OTUxaFJ4QlN0dkxXallPcmhnSHNJb0tSV0M5ZzY1NkN4VGRvemFOSHY4b05c/callback", "GET", "/interactions/203039963636301824/!/callback"},
// Interaction followup webhooks
{"/api/v10/webhooks/203039963636301824/aW50ZXJhY3Rpb246MTEwMzA0OTQyMDkzMDU2ODMyMjpOZUllWHdNU2J4RXBFMHVYRjBpU0pHMDdEb3BhM3ZlYklBODlMUmtlUXlRbzlpZzYyTnpLU0dqdWlyVlBvZnBSUlJHbUJHYlJ0N29MbE9KQUJVTFk4bTR4UzFtZEpEeXJyY0hBUERmTEhKVE9wRkNzU1FFWUkwTnlpWFY2WHdrRg/messages/@original", "POST", "/webhooks/203039963636301824/1103049420930568322/messages/@original"},
// No known major
{"/api/v9/invalid/203039963636301824", "GET", "/invalid/203039963636301824"},
{"/api/v9/invalid/203039963636301824/route/203039963636301824", "GET", "/invalid/203039963636301824/route/!"},
Expand Down

0 comments on commit b9b3dfe

Please sign in to comment.