ghsa-mf3v-f2qq-pf9g
Vulnerability from github
Published
2022-03-14 22:30
Modified
2022-03-15 21:48
Summary
Insufficient Session Expiration in Sylius
Details

Impact

The reset password token was not set to null after the password was changed. This is causing behaviour in which the same token can be used several times, so it can result in a leak of the existing token and an unauthorised password change.

Patches

The issue is fixed in versions: 1.10.11, 1.11.2 and above

Workarounds

You have to overwrite your Sylius\Bundle\ApiBundle\CommandHandler\ResetPasswordHandler class using this code:

```php <?php declare(strict_types=1);

namespace App\CommandHandler\Account;

use Sylius\Bundle\ApiBundle\Command\Account\ResetPassword; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Resource\Metadata\MetadataInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; use Sylius\Component\User\Security\PasswordUpdaterInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert;

final class ResetPasswordHandler implements MessageHandlerInterface { private UserRepositoryInterface $userRepository; private MetadataInterface $metadata; private PasswordUpdaterInterface $passwordUpdater;

public function __construct(
    UserRepositoryInterface $userRepository,
    MetadataInterface $metadata,
    PasswordUpdaterInterface $passwordUpdater
) {
    $this->userRepository = $userRepository;
    $this->metadata = $metadata;
    $this->passwordUpdater = $passwordUpdater;
}

public function __invoke(ResetPassword $command): void
{
    /** @var ShopUserInterface|null $user */
    $user = $this->userRepository->findOneBy(['passwordResetToken' => $command->resetPasswordToken]);

    Assert::notNull($user, 'No user found with reset token: ' . $command->resetPasswordToken);

    $resetting = $this->metadata->getParameter('resetting');
    $lifetime = new \DateInterval($resetting['token']['ttl']);

    if (!$user->isPasswordRequestNonExpired($lifetime)) {
        throw new \InvalidArgumentException('Password reset token has expired');
    }

    if ($command->resetPasswordToken !== $user->getPasswordResetToken()) {
        throw new \InvalidArgumentException('Password reset token does not match.');
    }

    $user->setPlainPassword($command->newPassword);

    $this->passwordUpdater->updatePassword($user);
    $user->setPasswordResetToken(null);
}

} ``` And register it in container:

```yaml

App\CommandHandler\Account\ResetPasswordHandler: arguments: - '@sylius.repository.shop_user' - !service class: Sylius\Component\Resource\Metadata\MetadataInterface factory: [ '@sylius.resource_registry', 'get' ] arguments: - 'sylius.shop_user' - '@sylius.security.password_updater' tags: - { name: messenger.message_handler, bus: sylius.command_bus } - { name: messenger.message_handler, bus: sylius_default.bus }

```

For more information

If you have any questions or comments about this advisory: * Open an issue in Sylius issues * Email us at security@sylius.com

Show details on source website


{
  "affected": [
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "sylius/sylius"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "1.10.0"
            },
            {
              "fixed": "1.10.11"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "sylius/sylius"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "1.11.0"
            },
            {
              "fixed": "1.11.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2022-24743"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-613"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2022-03-14T22:30:46Z",
    "nvd_published_at": "2022-03-14T21:15:00Z",
    "severity": "HIGH"
  },
  "details": "### Impact\nThe reset password token was not set to null after the password was changed. This is causing behaviour in which the same token can be used several times, so it can result in a leak of the existing token and an unauthorised password change.\n\n### Patches\nThe issue is fixed in versions: 1.10.11, 1.11.2 and above\n\n### Workarounds\nYou have to overwrite your `Sylius\\Bundle\\ApiBundle\\CommandHandler\\ResetPasswordHandler` class using this code:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nnamespace App\\CommandHandler\\Account;\n\nuse Sylius\\Bundle\\ApiBundle\\Command\\Account\\ResetPassword;\nuse Sylius\\Component\\Core\\Model\\ShopUserInterface;\nuse Sylius\\Component\\Resource\\Metadata\\MetadataInterface;\nuse Sylius\\Component\\User\\Repository\\UserRepositoryInterface;\nuse Sylius\\Component\\User\\Security\\PasswordUpdaterInterface;\nuse Symfony\\Component\\Messenger\\Handler\\MessageHandlerInterface;\nuse Webmozart\\Assert\\Assert;\n\nfinal class ResetPasswordHandler implements MessageHandlerInterface\n{\n    private UserRepositoryInterface $userRepository;\n    private MetadataInterface $metadata;\n    private PasswordUpdaterInterface $passwordUpdater;\n\n    public function __construct(\n        UserRepositoryInterface $userRepository,\n        MetadataInterface $metadata,\n        PasswordUpdaterInterface $passwordUpdater\n    ) {\n        $this-\u003euserRepository = $userRepository;\n        $this-\u003emetadata = $metadata;\n        $this-\u003epasswordUpdater = $passwordUpdater;\n    }\n\n    public function __invoke(ResetPassword $command): void\n    {\n        /** @var ShopUserInterface|null $user */\n        $user = $this-\u003euserRepository-\u003efindOneBy([\u0027passwordResetToken\u0027 =\u003e $command-\u003eresetPasswordToken]);\n\n        Assert::notNull($user, \u0027No user found with reset token: \u0027 . $command-\u003eresetPasswordToken);\n\n        $resetting = $this-\u003emetadata-\u003egetParameter(\u0027resetting\u0027);\n        $lifetime = new \\DateInterval($resetting[\u0027token\u0027][\u0027ttl\u0027]);\n\n        if (!$user-\u003eisPasswordRequestNonExpired($lifetime)) {\n            throw new \\InvalidArgumentException(\u0027Password reset token has expired\u0027);\n        }\n\n        if ($command-\u003eresetPasswordToken !== $user-\u003egetPasswordResetToken()) {\n            throw new \\InvalidArgumentException(\u0027Password reset token does not match.\u0027);\n        }\n\n        $user-\u003esetPlainPassword($command-\u003enewPassword);\n\n        $this-\u003epasswordUpdater-\u003eupdatePassword($user);\n        $user-\u003esetPasswordResetToken(null);\n    }\n}\n```\nAnd register it in container:\n\n```yaml\n\nApp\\CommandHandler\\Account\\ResetPasswordHandler:\n    arguments:\n        - \u0027@sylius.repository.shop_user\u0027\n        - !service\n              class: Sylius\\Component\\Resource\\Metadata\\MetadataInterface\n              factory: [ \u0027@sylius.resource_registry\u0027, \u0027get\u0027 ]\n              arguments:\n                    - \u0027sylius.shop_user\u0027\n                    - \u0027@sylius.security.password_updater\u0027\n    tags:\n        - { name: messenger.message_handler, bus: sylius.command_bus }\n        - { name: messenger.message_handler, bus: sylius_default.bus }\n         \n```\n\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues)\n* Email us at [security@sylius.com](mailto:security@sylius.com)\n",
  "id": "GHSA-mf3v-f2qq-pf9g",
  "modified": "2022-03-15T21:48:34Z",
  "published": "2022-03-14T22:30:46Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/Sylius/security/advisories/GHSA-mf3v-f2qq-pf9g"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2022-24743"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/Sylius/Sylius"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/Sylius/releases/tag/v1.10.11"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/Sylius/releases/tag/v1.11.2"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Insufficient Session Expiration in Sylius"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
  • Confirmed: The vulnerability is confirmed from an analyst perspective.
  • Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
  • Patched: This vulnerability was successfully patched by the user reporting the sighting.
  • Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
  • Not confirmed: The user expresses doubt about the veracity of the vulnerability.
  • Not patched: This vulnerability was not successfully patched by the user reporting the sighting.


Loading…