Skip to content

Commit 2d7cddd

Browse files
committed
Permissive JSON PRC params
Reworking how the JSON RPC params are being handled. They are not more permissive, but the request params are still strongly enforced.
1 parent 450b7c5 commit 2d7cddd

1 file changed

Lines changed: 6 additions & 26 deletions

File tree

lib/chatops/controller.rb

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,23 @@ def setup_params!
5555
params[key] = value
5656
end
5757

58-
permitted_params = %i[
59-
action
60-
chatop
61-
controller
62-
mention_slug
63-
method
64-
room_id
65-
user
66-
]
67-
68-
chatop_name = if params[:chatop].present?
69-
params[:chatop].to_sym
70-
elsif params[:action].present?
71-
params[:action].to_sym
72-
else
73-
nil
74-
end
58+
@jsonrpc_params = params.delete(:params) if params.has_key? :params
7559

76-
if chatop = self.class.chatops[chatop_name]
77-
permitted_params << { params: chatop[:params] }
78-
end
60+
self.params = params.permit(:action, :chatop, :controller, :id, :mention_slug, :method, :room_id, :user)
61+
end
7962

80-
self.params = params.permit(*permitted_params)
63+
def jsonrpc_params
64+
@jsonrpc_params ||= ActionController::Parameters.new
8165
end
8266

8367
def json_body
8468
hash = {}
8569
if request.content_type =~ %r/\Aapplication\/json\Z/i
86-
hash = GitHub::JSON.parse(request.raw_post) || {}
70+
hash = ActiveSupport::JSON.decode(request.raw_post) || {}
8771
end
8872
hash.with_indifferent_access
8973
end
9074

91-
def jsonrpc_params
92-
params["params"] || {}
93-
end
94-
9575
# `options` supports any of the optional fields documented
9676
# in the [protocol](../../docs/protocol-description.md).
9777
def jsonrpc_success(message, options: {})

0 commit comments

Comments
 (0)