Skip to content

config:set --lock-env twofactorauth/general/force_providers writes an array to env.php and breaks bin/magento and the Admin #441

Backlog

Description

@DavidLambauer

Preconditions and environment

  • Mage-OS 4.0.0 with Magento_TwoFactorAuth enabled (the default)

Steps to reproduce

  1. bin/magento config:set --lock-env twofactorauth/general/force_providers google
  2. Run any other command, for example bin/magento security:tfa:google:set-secret admin <secret> or bin/magento cache:flush, and open the Admin.

Expected result

app/etc/env.php contains 'force_providers' => 'google', the same string that config:set without --lock-env stores in core_config_data, and admin users log in with Google Authenticator.

Actual result

app/etc/env.php contains 'force_providers' => ['google']. After that, every bin/magento command fails with:

Type Error occurred when creating object: Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity, explode(): Argument #2 ($string) must be of type string, array given

and the Admin returns HTTP 500. Removing the entry from env.php isn't enough: the array is still in the config cache, and bin/magento cache:flush can't run, so the cache storage (Valkey here) has to be flushed directly.

Cause: Magento\TwoFactorAuth\Model\Config\Backend\ForceProviders::beforeSave() turns the value into an array of provider codes. When the value is saved to the database, Magento\Config\Model\ResourceModel\Config\Data::_beforeSave() joins arrays into a string again, but --lock-env (and --lock-config) writes the backend model's value to the file unchanged.

Additional information

  • Workaround: run the command without --lock-env. That stores google in the database, and the login with Google Authenticator works.
  • Suggested fix: have ForceProviders::beforeSave() keep a comma-separated string, or join array values before the lock processor writes them.
  • Package: mage-os/module-two-factor-auth
  • Found while testing the installation guide on a running store (Fix the security pages, the reviewed pages, and remove duplicate pages devdocs#108).

Triage and priority

  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions