Skip to content

Commit 0064826

Browse files
committed
Explicitly check for permitted parameters
This increases the security of chatops endpoins by only allowing permitted parameters to be passed. It goes further and validates the JSON RPC params are also explicitly named in the regular expression matchers as well.
1 parent 0478db9 commit 0064826

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

lib/chatops/controller.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def list
2727
end
2828

2929
def process(*args)
30+
setup_params
31+
3032
if params[:chatop].present?
3133
params[:action] = params[:chatop]
3234
args[0] = params[:action]
@@ -47,6 +49,33 @@ def execute_chatop
4749

4850
protected
4951

52+
def setup_params
53+
permitted_params = %i[
54+
action
55+
chatop
56+
controller
57+
mention_slug
58+
method
59+
room_id
60+
user
61+
]
62+
63+
chatop_name =
64+
if params[:chatop].present?
65+
params[:chatop].to_sym
66+
elsif params[:action].present?
67+
params[:action].to_sym
68+
else
69+
nil
70+
end
71+
72+
if chatop = self.class.chatops[chatop_name]
73+
permitted_params << { params: chatop[:params] }
74+
end
75+
76+
self.params = params.permit(*permitted_params)
77+
end
78+
5079
def jsonrpc_params
5180
params["params"] || {}
5281
end

0 commit comments

Comments
 (0)