CVE-2023-49098 (published 2024-01-12T21:15Z)

Discourse-reactions is a plugin that allows user to add their reactions to the post. Data about a user's reaction notifications could be exposed. This vulnerability was patched in commit 2c26939.

CVSS v3 base score: 3.5, LOW (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:L/I:N/A:N)

Weakness information:
cwe_id: CWE-284
cwe_name: Improper Access Control
description: The product does not restrict or incorrectly restricts access to a resource from an unauthorized actor.
extended_description: 
            Access control involves the use of several protection mechanisms such as:
            
               Authentication (proving the identity of an actor)
               Authorization (ensuring that a given actor can access a resource), and
               Accountability (tracking of activities that were performed)
            
            When any mechanism is not applied or otherwise fails, attackers can compromise the security of the product by gaining privileges, reading sensitive information, executing commands, evading detection, etc.
            There are two distinct behaviors that can introduce access control weaknesses:
               
                  Specification: incorrect privileges, permissions, ownership, etc. are explicitly specified for either the user or the resource (for example, setting a password file to be world-writable, or giving administrator capabilities to a guest user). This action could be performed by the program or the administrator.
                  Enforcement: the mechanism contains errors that prevent it from properly enforcing the specified access control requirements (e.g., allowing the user to specify their own privileges, or allowing a syntactically-incorrect ACL to produce insecure settings). This problem occurs within the program itself, in that it does not actually enforce the intended security policy that the administrator specifies.
               
         
		 

Fix information:
repo_url: https://github.com/discourse/discourse-reactions
commit_details: repo_url: https://github.com/discourse/discourse-reactions
author: Penar Musaraj
author_date: 2024-01-08 17:26:54-05:00
msg: SECURITY: restrict custom reaction access (#263)

Co-authored-by: David Battersby <info@davidbattersby.com>
repository: repo_url: https://github.com/discourse/discourse-reactions
repo_name: discourse/discourse-reactions
repo_language: Ruby
owner: discourse
file_changes: filename: custom_reactions_controller.rb
change_type: ModificationType.MODIFY
diff: @@ -45,7 +45,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationController
         include_inactive:
           current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts),
       )
-    raise Discourse::NotFound unless guardian.can_see_profile?(user)
+    raise Discourse::InvalidAccess unless guardian.can_see_notifications?(user)
 
     reaction_users =
       DiscourseReactions::ReactionUser
@@ -78,7 +78,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationController
         include_inactive:
           current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts),
       )
-    raise Discourse::NotFound unless guardian.can_see_profile?(user)
+    raise Discourse::InvalidAccess unless guardian.can_see_notifications?(user)
 
     posts = Post.joins(:topic).where(user_id: user.id)
     posts = guardian.filter_allowed_categories(posts)

programming_language: Ruby
filename: custom_reactions_controller_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -167,27 +167,27 @@ describe DiscourseReactions::CustomReactionsController do
       Fabricate(:reaction_user, reaction: secure_reaction, user: user_2, post: secure_post)
     end
 
-    it "returns reactions given by a user" do
-      sign_in(user_1)
+    it "returns reactions given by a user when current user is admin" do
+      sign_in(admin)
 
       get "/discourse-reactions/posts/reactions.json", params: { username: user_2.username }
-      parsed = response.parsed_body
+      expect(response.status).to eq(200)
 
-      expect(parsed[0]["user"]["id"]).to eq(user_2.id)
-      expect(parsed[0]["post_id"]).to eq(post_2.id)
-      expect(parsed[0]["post"]["user"]["id"]).to eq(user_1.id)
-      expect(parsed[0]["reaction"]["id"]).to eq(reaction_1.id)
+      parsed = response.parsed_body
+      expect(parsed[2]["user"]["id"]).to eq(user_2.id)
+      expect(parsed[2]["post_id"]).to eq(post_2.id)
+      expect(parsed[2]["post"]["user"]["id"]).to eq(user_1.id)
+      expect(parsed[2]["reaction"]["id"]).to eq(reaction_1.id)
     end
 
-    it "does not return reactions for private messages" do
+    it "does not return reactions for private messages of other users" do
       sign_in(user_1)
 
       get "/discourse-reactions/posts/reactions.json", params: { username: user_2.username }
-      parsed = response.parsed_body
-      expect(response.parsed_body.map { |reaction| reaction["post_id"] }).not_to include(
-        private_post.id,
-      )
+      expect(response.status).to eq(403)
+    end
 
+    it "returns reactions for private messages of current user" do
       sign_in(user_2)
 
       get "/discourse-reactions/posts/reactions.json", params: { username: user_2.username }
@@ -202,15 +202,11 @@ describe DiscourseReactions::CustomReactionsController do
       sign_in(user_1)
 
       get "/discourse-reactions/posts/reactions.json", params: { username: user_2.username }
-      parsed = response.parsed_body
-      expect(response.parsed_body.map { |reaction| reaction["post_id"] }).not_to include(
-        secure_post.id,
-      )
+      expect(response.status).to eq(403)
 
       secure_group.add(user_1)
       get "/discourse-reactions/posts/reactions.json", params: { username: user_2.username }
-      parsed = response.parsed_body
-      expect(response.parsed_body.map { |reaction| reaction["post_id"] }).to include(secure_post.id)
+      expect(response.status).to eq(403)
 
       sign_in(user_2)
 
@@ -281,8 +277,8 @@ describe DiscourseReactions::CustomReactionsController do
   end
 
   describe "#reactions_received" do
-    it "returns reactions received by a user" do
-      sign_in(user_2)
+    it "returns reactions received by a user when current user is admin" do
+      sign_in(admin)
 
       get "/discourse-reactions/posts/reactions-received.json",
           params: {
@@ -296,6 +292,17 @@ describe DiscourseReactions::CustomReactionsController do
       expect(parsed[0]["reaction"]["id"]).to eq(reaction_2.id)
     end
 
+    it "does not return reactions received by a user when current user is not an admin" do
+      sign_in(user_1)
+
+      get "/discourse-reactions/posts/reactions-received.json",
+          params: {
+            username: user_2.username,
+          }
+
+      expect(response.status).to eq(403)
+    end
+
     it "filters by acting username" do
       sign_in(user_1)
 

programming_language: Ruby