Skip to content

Commit 7df4e4a

Browse files
committed
security fix, anon should not be treated as though they can create anything
1 parent e5fbdde commit 7df4e4a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

app/models/category.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@ class Category < ActiveRecord::Base
5050
}
5151

5252
scope :topic_create_allowed, ->(guardian) {
53-
scoped_to_permissions(guardian, [:full])
53+
if guardian.anonymous?
54+
where("1=0")
55+
else
56+
scoped_to_permissions(guardian, [:full])
57+
end
5458
}
5559

5660
scope :post_create_allowed, ->(guardian) {
57-
scoped_to_permissions(guardian, [:create_post, :full])
61+
if guardian.anonymous?
62+
where("1=0")
63+
else
64+
scoped_to_permissions(guardian, [:create_post, :full])
65+
end
5866
}
5967
delegate :post_template, to: 'self.class'
6068

spec/models/category_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
can_post_category.save
6868

6969
Category.post_create_allowed(guardian).count.should == 3
70-
end
7170

72-
end
71+
# anonymous has permission to create no topics
72+
guardian = Guardian.new(nil)
73+
Category.post_create_allowed(guardian).count.should == 0
7374

74-
describe "post_create_allowed" do
75+
end
7576

7677
end
7778

0 commit comments

Comments
 (0)