[
https://issues.apache.org/jira/browse/THRIFT-6146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dmytro Shteflyuk resolved THRIFT-6146.
--------------------------------------
Fix Version/s: 0.25.0
Resolution: Fixed
> Ruby processor should validate request message types
> ----------------------------------------------------
>
> Key: THRIFT-6146
> URL: https://issues.apache.org/jira/browse/THRIFT-6146
> Project: Thrift
> Issue Type: Bug
> Components: Ruby - Library
> Reporter: Dmytro Shteflyuk
> Assignee: Dmytro Shteflyuk
> Priority: Major
> Fix For: 0.25.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> h3. Problem
> The Ruby base processor dispatches an incoming message based on its function
> name without first validating the message-envelope type. As a result,
> envelopes marked as {{REPLY}} or {{EXCEPTION}} can be routed to a generated
> server method as though they were requests.
> The Ruby multiplexed processor already limits request dispatch to {{CALL}}
> and {{ONEWAY}}, but the base processor does not apply the same validation.
> h3. Client impact
> A malformed or misrouted envelope can reach generated argument parsing and
> invoke a server handler instead of being reported as an invalid request
> message type. The response envelope may also be absent or inconsistent
> because the processor believes normal method dispatch succeeded.
> h3. Reproduction
> Run the following from {{lib/rb}}:
> {code:ruby}
> require "thrift"
> processor_class = Class.new do
> include Thrift::Processor
> attr_reader :dispatched_seqid
> def process_work(seqid, _iprot, _oprot)
> @dispatched_seqid = seqid
> true
> end
> end
> input = Thrift::MemoryBufferTransport.new
> writer = Thrift::BinaryProtocol.new(input)
> writer.write_message_begin("work", Thrift::MessageTypes::REPLY, 11)
> writer.write_struct_begin("work_result")
> writer.write_field_stop
> writer.write_struct_end
> writer.write_message_end
> output = Thrift::MemoryBufferTransport.new
> processor = processor_class.new(Object.new)
> result = processor.process(
> Thrift::BinaryProtocol.new(input),
> Thrift::BinaryProtocol.new(output)
> )
> puts "result=#{result} dispatched_seqid=#{processor.dispatched_seqid}
> response_bytes=#{output.available}"
> {code}
> Testing on master commit {{c2def39207a73394420088da9b4b105571dd9036}}
> produces:
> {code}
> result=true dispatched_seqid=11 response_bytes=0
> {code}
> The {{REPLY}} envelope is dispatched to {{process_work}}, and no error
> response is written.
> h3. Expected behavior
> The base processor should dispatch only {{CALL}} and {{ONEWAY}} envelopes.
> Other message types should not invoke a generated handler. They should be
> consumed and reported using an {{ApplicationException}} with type
> {{INVALID_MESSAGE_TYPE}}, while preserving the message name and sequence ID
> in the error response.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)