Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/getstream_ruby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_relative 'generated/chat_client'
require_relative 'generated/video_client'
require_relative 'extensions/moderation_extensions'
require_relative 'extensions/chat_extensions'
require_relative 'generated/feed'
require_relative 'generated/webhook'
require_relative 'generated/models/api_error'
Expand Down
22 changes: 22 additions & 0 deletions lib/getstream_ruby/extensions/chat_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module GetStream

module Generated

class ChatClient

# The generated name of the fork message map method changes from fork_message_i_ds to
# fork_message_ids in a later regeneration. Keep both names working on either side of it.
if method_defined?(:fork_message_i_ds) && !method_defined?(:fork_message_ids)
alias fork_message_ids fork_message_i_ds
elsif method_defined?(:fork_message_ids) && !method_defined?(:fork_message_i_ds)
# @deprecated Use {#fork_message_ids} instead.
alias fork_message_i_ds fork_message_ids
end

end

end

end
18 changes: 16 additions & 2 deletions lib/getstream_ruby/generated/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'base64'
require 'json'
require 'openssl'
require 'stringio'
require 'time'
require 'zlib'
require_relative 'models/activity_added_event'
Expand Down Expand Up @@ -234,6 +235,14 @@ def initialize(type:, created_at: nil, raw: {})
GZIP_MAGIC = "\x1F\x8B".b.freeze
private_constant :GZIP_MAGIC

class << self
# Caps the decompressed size of a gzip webhook body. gunzip_payload runs
# before the signature check, so without a cap an unsigned gzip bomb could
# exhaust memory. Raise it if your events are larger.
attr_accessor :max_payload_bytes
end
self.max_payload_bytes = 10 * 1024 * 1024

# Webhook event type constants
EVENT_TYPE_WILDCARD = '*'
EVENT_TYPE_APPEAL_ACCEPTED = 'appeal.accepted'
Expand Down Expand Up @@ -887,14 +896,19 @@ def self.verify_signature(body, signature, secret)
# @param body [String] raw body (binary-safe)
# @return [String] decompressed body, or the original body if not gzip-prefixed
# @raise [InvalidWebhookError] if body has the gzip magic prefix but
# isn't a valid gzip stream
# isn't a valid gzip stream, or decompresses to more than
# {max_payload_bytes}
def self.gunzip_payload(body)
raise InvalidWebhookError, "#{InvalidWebhookError::INVALID_JSON}: body must be a String" unless body.is_a?(String)

bytes = body.b
return bytes if bytes.bytesize < 2 || bytes.byteslice(0, 2) != GZIP_MAGIC

Zlib.gunzip(bytes)
limit = max_payload_bytes
out = Zlib::GzipReader.wrap(StringIO.new(bytes)) { |gz| gz.read(limit + 1) } || ''.b
raise InvalidWebhookError, "#{InvalidWebhookError::GZIP_FAILED}: payload exceeds #{limit} bytes" if out.bytesize > limit

out
rescue Zlib::Error => e
raise InvalidWebhookError, "#{InvalidWebhookError::GZIP_FAILED}: #{e.message}"
end
Expand Down
14 changes: 14 additions & 0 deletions spec/chat_extensions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GetStream::Generated::ChatClient do

it 'answers to fork_message_ids and fork_message_i_ds with the same method' do

names = %i[fork_message_ids fork_message_i_ds].map { |name| described_class.instance_method(name).original_name }
expect(names.uniq.size).to eq(1)

end

end
10 changes: 10 additions & 0 deletions spec/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,16 @@ def neg_dir(name)

end

it 'raises on gzip body over the size cap' do

skip 'fixtures not present' unless File.directory?(WEBHOOK_FIXTURE_ROOT)

body = File.binread(File.join(neg_dir('oversized_compression'), 'body.gz'))
err_class = StreamChat::Webhook::InvalidWebhookError
expect { StreamChat::Webhook.gunzip_payload(body) }.to raise_error(err_class, /payload exceeds/)

end

it 'raises on bad base64 (downstream parse failure)' do

# Per CHA-3071 wire format: decode_sqs_payload falls back to raw bytes
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"message.new","created_at":"2026-05-08T00:00:00Z"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fbfb957f04748ba32f10808cc88b47c62c1d795410e430857cbabb7c788d121a

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJ0eXBlIjoibWVzc2FnZS5uZXciLCJjcmVhdGVkX2F0IjoiMjAyNi0wNS0wOFQwMDowMDowMFoifQ==
Loading