A platform for community discussion. Free, open, simple.
FIX: `stream_suggestion` leaks post existence and returns false success for unauthorized posts (#37858)
Samc1d2ef8bc73c
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rbindex 02a62a1c829..66012a1c69e 100644--- a/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb+++ b/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb@@ -200,6 +200,7 @@ module DiscourseAipost = Post.includes(:topic).find_by(id: post_id)raise Discourse::InvalidParameters.new(:post_id) unless post+ guardian.ensure_can_see!(post)Jobs.enqueue(:stream_post_helper,diff --git a/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rbindex 5e7e7dc89cf..33e9e483213 100644--- a/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb@@ -16,6 +16,27 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController doSiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]end+ it "returns 403 when user cannot see the post" do+ sign_in(user)++ group = Fabricate(:group)+ private_category = Fabricate(:private_category, group: group)+ topic = Fabricate(:topic, category: private_category)+ private_post = Fabricate(:post, topic: topic)++ post "/discourse-ai/ai-helper/stream_suggestion.json",+ params: {+ text: "hello wrld",+ location: "post",+ client_id: "1234",+ post_id: private_post.id,+ custom_prompt: "Translate to Spanish",+ mode: DiscourseAi::AiHelper::Assistant::CUSTOM_PROMPT,+ }++ expect(response.status).to eq(403)+ end+it "is able to stream suggestions to helper" dosign_in(user)