Skip to content

Commit ac44707

Browse files
joemasilotticlaude
andcommitted
Force UTF-8 encoding on raw webhook bodies
request.raw_post returns ASCII-8BIT bytes. When the body contained non-ASCII characters (e.g. the · in the CLI setup example), persisting raw_payload blew up with Encoding::UndefinedConversionError on the SQLite bind. Affected every parser, not just CLI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ccef6b9 commit ac44707

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/controllers/webhooks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def create
1010
return head :not_found
1111
end
1212

13-
body = request.raw_post
13+
body = request.raw_post.dup.force_encoding(Encoding::UTF_8)
1414
unless source.parser.verify(request, body, source.signing_secret)
1515
Rails.logger.warn("rejected: invalid signature source=#{source.id} body_bytes=#{body.bytesize}")
1616
return head :unauthorized

test/controllers/webhooks_controller_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ def cal_signature(body, secret)
147147
assert_equal "main a1b2c3d", notification.body
148148
end
149149

150+
test "handles non-ASCII bytes in the request body" do
151+
source = sources(:cli)
152+
payload = { "title" => "deploy done", "body" => "main · a1b2c3d" }
153+
154+
post webhook_url(parser_type: "cli", token: source.token),
155+
params: payload.to_json,
156+
headers: { "Content-Type" => "application/json" }
157+
158+
assert_response :success
159+
notification = source.notifications.last
160+
assert_equal "main · a1b2c3d", notification.body
161+
assert_equal "main · a1b2c3d", JSON.parse(notification.raw_payload)["body"]
162+
end
163+
150164
test "creates a notification from a Hatchbox failed deploy script (form-encoded)" do
151165
source = sources(:hatchbox)
152166

0 commit comments

Comments
 (0)