Skip to content

Commit ab47cab

Browse files
Merge commit from fork
Co-authored-by: Jessica Jiang <[email protected]>
1 parent 5dde801 commit ab47cab

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Security
11+
12+
- `InteractionCallbackParse` no longer falls back to the URL query string for the
13+
`payload` field. A request's signature only covers its POST body, so the fallback
14+
let a validly-signed request be replayed with an attacker-controlled payload
15+
smuggled in via the query string.
16+
1017
### Fixed
1118

1219
- Prevent repeated escaping and data races when reusing a `MsgOptionText` option.

‎interactions.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ type BlockActionStates struct {
8282
//
8383
// See https://github.com/slack-go/slack/issues/660 for context.
8484
func InteractionCallbackParse(r *http.Request) (InteractionCallback, error) {
85-
payload := r.FormValue("payload")
85+
if err := r.ParseForm(); err != nil {
86+
return InteractionCallback{}, err
87+
}
88+
payload := r.PostForm.Get("payload")
8689
if len(payload) == 0 {
8790
return InteractionCallback{}, errors.New("payload is empty")
8891
}

‎interactions_test.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,18 @@ func TestInteractionCallback_Parser(t *testing.T) {
734734
assert.Equal(t, ic.BlockActionState.Values["other_block_id"]["other_action_id"].Type, ActionType(METPlainTextInput))
735735
assert.Equal(t, "test123", ic.BlockActionState.Values["other_block_id"]["other_action_id"].Value)
736736
}
737+
738+
// A signature check authenticates only the raw POST body. If the "payload"
739+
// field is missing from that body, parsing must not fall back to the query
740+
// string: a signed request for one event could otherwise be replayed with
741+
// an attacker-controlled "payload" smuggled in via the URL.
742+
// See https://github.com/slack-go/slack/blob/6065d7ddad41ae0fffe26e32a4a9259118df8ba4/interactions.go#L85.
743+
func TestInteractionCallback_Parser_IgnoresQueryStringPayload(t *testing.T) {
744+
req, err := http.NewRequest(http.MethodPost, "http://slack.example.org/interactions?payload=%7B%22type%22%3A%22view_submission%22%7D", strings.NewReader(""))
745+
require.NoError(t, err)
746+
747+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
748+
749+
_, err = InteractionCallbackParse(req)
750+
assert.EqualError(t, err, "payload is empty")
751+
}

0 commit comments

Comments
 (0)