VYPR
Low severityNVD Advisory· Published Jan 13, 2023· Updated Mar 10, 2025

Flarum is missing authorization in discussion replies

CVE-2023-22489

Description

Flarum is a discussion platform for websites. If the first post of a discussion is permanently deleted but the discussion stays visible, any actor who can view the discussion is able to create a new reply via the REST API, no matter the reply permission or lock status. This includes users that don't have a validated email. Guests cannot successfully create a reply because the API will fail with a 500 error when the user ID 0 is inserted into the database. This happens because when the first post of a discussion is permanently deleted, the first_post_id attribute of the discussion becomes null which causes access control to be skipped for all new replies. Flarum automatically makes discussions with zero comments invisible so an additional condition for this vulnerability is that the discussion must have at least one approved reply so that discussions.comment_count is still above zero after the post deletion. This can open the discussion to uncontrolled spam or just unintentional replies if users still had their tab open before the vulnerable discussion was locked and then post a reply when they shouldn't be able to. In combination with the email notification settings, this could also be used as a way to send unsolicited emails. Versions between v1.3.0 and v1.6.3 are impacted. The vulnerability has been fixed and published as flarum/core v1.6.3. All communities running Flarum should upgrade as soon as possible. There are no known workarounds.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
flarum/corePackagist
>= 1.3.0, < 1.6.31.6.3

Affected products

1

Patches

1
12f14112a0ec

Merge pull request from GHSA-hph3-hv3c-7725

https://github.com/flarum/frameworkSami MazouzJan 10, 2023via ghsa
4 files changed · +50 9
  • framework/core/src/Discussion/Command/StartDiscussionHandler.php+1 1 modified
    @@ -79,7 +79,7 @@ public function handle(StartDiscussion $command)
             // We will do this by running the PostReply command.
             try {
                 $post = $this->bus->dispatch(
    -                new PostReply($discussion->id, $actor, $data, $ipAddress)
    +                new PostReply($discussion->id, $actor, $data, $ipAddress, true)
                 );
             } catch (Exception $e) {
                 $discussion->delete();
    
  • framework/core/src/Post/Command/PostReplyHandler.php+1 1 modified
    @@ -74,7 +74,7 @@ public function handle(PostReply $command)
     
             // If this is the first post in the discussion, it's technically not a
             // "reply", so we won't check for that permission.
    -        if ($discussion->first_post_id !== null) {
    +        if (! $command->isFirstPost) {
                 $actor->assertCan('reply', $discussion);
             }
     
    
  • framework/core/src/Post/Command/PostReply.php+7 1 modified
    @@ -41,17 +41,23 @@ class PostReply
          */
         public $ipAddress;
     
    +    /**
    +     * @var bool
    +     */
    +    public $isFirstPost;
    +
         /**
          * @param int $discussionId The ID of the discussion to post the reply to.
          * @param User $actor The user who is performing the action.
          * @param array $data The attributes to assign to the new post.
          * @param string $ipAddress The IP address of the actor.
          */
    -    public function __construct($discussionId, User $actor, array $data, $ipAddress = null)
    +    public function __construct($discussionId, User $actor, array $data, $ipAddress = null, bool $isFirstPost = false)
         {
             $this->discussionId = $discussionId;
             $this->actor = $actor;
             $this->data = $data;
             $this->ipAddress = $ipAddress;
    +        $this->isFirstPost = $isFirstPost;
         }
     }
    
  • framework/core/tests/integration/api/posts/CreateTest.php+41 6 modified
    @@ -10,6 +10,7 @@
     namespace Flarum\Tests\integration\api\posts;
     
     use Carbon\Carbon;
    +use Flarum\Group\Group;
     use Flarum\Testing\integration\RetrievesAuthorizedUsers;
     use Flarum\Testing\integration\TestCase;
     
    @@ -26,36 +27,70 @@ protected function setUp(): void
     
             $this->prepareDatabase([
                 'discussions' => [
    -                ['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2],
    +                ['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1],
    +                // Discussion with deleted first post.
    +                ['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null],
    +            ],
    +            'posts' => [
    +                ['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::now()->subDay()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t></t>'],
                 ],
                 'users' => [
                     $this->normalUser(),
    -            ]
    +                ['id' => 3, 'username' => 'restricted', 'email' => 'restricted@machine.local', 'is_email_confirmed' => 1],
    +            ],
    +            'groups' => [
    +                ['id' => 40, 'name_singular' => 'tess', 'name_plural' => 'tess'],
    +            ],
    +            'group_user' => [
    +                ['group_id' => 40, 'user_id' => 3],
    +            ],
    +            'group_permission' => [
    +                ['group_id' => 40, 'permission' => 'discussion.reply'],
    +            ],
             ]);
         }
     
         /**
    +     * @dataProvider discussionRepliesPrvider
          * @test
          */
    -    public function can_create_reply()
    +    public function can_create_reply_if_allowed(int $actorId, int $discussionId, int $responseStatus)
         {
    +        // Reset permissions for normal users group.
    +        $this->database()
    +            ->table('group_permission')
    +            ->where('permission', 'discussion.reply')
    +            ->where('group_id', Group::MEMBER_ID)
    +            ->delete();
    +
             $response = $this->send(
                 $this->request('POST', '/api/posts', [
    -                'authenticatedAs' => 2,
    +                'authenticatedAs' => $actorId,
                     'json' => [
                         'data' => [
                             'attributes' => [
                                 'content' => 'reply with predetermined content for automated testing - too-obscure',
                             ],
                             'relationships' => [
    -                            'discussion' => ['data' => ['id' => 1]],
    +                            'discussion' => ['data' => ['id' => $discussionId]],
                             ],
                         ],
                     ],
                 ])
             );
     
    -        $this->assertEquals(201, $response->getStatusCode());
    +        $this->assertEquals($responseStatus, $response->getStatusCode());
    +    }
    +
    +    public function discussionRepliesPrvider(): array
    +    {
    +        return [
    +            // [$actorId, $discussionId, $responseStatus]
    +            'can_create_reply_with_ability' => [3, 1, 201],
    +            'cannot_create_reply_without_ability' => [2, 1, 403],
    +            'can_create_reply_with_ability_when_first_post_is_deleted' => [3, 2, 201],
    +            'cannot_create_reply_without_ability_when_first_post_is_deleted' => [2, 2, 403],
    +        ];
         }
     
         /**
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.