Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Permit format on the comment endpoint so a plain comment logs no warning

Guido Boykeff26296718dc
diff --git a/app/controllers/api/v1/posts_controller.rb b/app/controllers/api/v1/posts_controller.rb
index b993bb1..6442239 100644
--- a/app/controllers/api/v1/posts_controller.rb
+++ b/app/controllers/api/v1/posts_controller.rb
@@ -58,15 +58,16 @@ module Api
render_error(error: 'validation_failed', errors: result.errors, status: :unprocessable_entity)
end
- # The format is read raw, not through permit: strong parameters drop a
- # list or an object, which would have written the comment as html. Given,
- # it goes to the rule as it came (null included); absent, it is html.
+ # The format goes to the rule raw, not through permit: strong parameters
+ # drop a list or an object, which would have written the comment as html.
+ # Given, it goes as it came (null included); absent, it is html. It is
+ # permitted all the same, so a plain comment logs no unpermitted parameter.
def comment_input
input = params.require(:post)
# A post that is no object (post=text) answers like a missing one.
raise ActionController::ParameterMissing, :post unless input.is_a?(ActionController::Parameters)
- permitted = input.permit(:body, :is_private, :visible_to_user_id)
+ permitted = input.permit(:body, :format, :is_private, :visible_to_user_id)
fields = { body: permitted[:body], is_private: permitted[:is_private],
visible_to_user_id: permitted[:visible_to_user_id] }
fields[:format] = input[:format] if input.key?(:format)
diff --git a/spec/requests/api/v1/post_comment_format_spec.rb b/spec/requests/api/v1/post_comment_format_spec.rb
index e6614ec..7cfff0b 100644
--- a/spec/requests/api/v1/post_comment_format_spec.rb
+++ b/spec/requests/api/v1/post_comment_format_spec.rb
@@ -102,6 +102,18 @@ RSpec.describe 'API V1 comment format', :ci_guard, type: :request do
comment(format: 'plain', body: 'x')
expect(body['data'].keys).to eq(%w[id ticket_id author body_html body_text is_private visible_to_user_id created_at updated_at])
end
+
+ # Otherwise every comment the client sends logs format as an unpermitted
+ # parameter; the rule reads the raw value either way.
+ it 'does not report format as an unpermitted parameter' do
+ unpermitted = []
+ collect = ->(*, payload) { unpermitted.concat(payload[:keys]) }
+ ActiveSupport::Notifications.subscribed(collect, 'unpermitted_parameters.action_controller') do
+ comment(format: 'plain', body: 'x')
+ end
+ expect(response).to have_http_status(:created)
+ expect(unpermitted).to be_empty
+ end
end
# Existing callers (gboyke/lalabase-mcp among them) send no format. Their