Flutterwave / PHP-v3

PHP Library for Flutterwave v3 APIs
MIT License
18 stars 17 forks source link

Fixed Flutterwave sdk: ENCRYPTION_KEY environment variable missing, after creating a custom environmental variable and bootstraping. #66

Open leonardosahon opened 5 months ago

leonardosahon commented 5 months ago

When a custom env variable is created, the bootstrap method was still trying to find the default env keys.

With this new addition, if a user has used the PackageConfig::setUp method already to set their custom env variables, bootstrap would not have assume self::$config is not set again.

Version: flutterwavedev/flutterwave-v3 : 1.0.6

Error Message

Screenshot 2024-02-01 at 7 46 42 PM

This has already been done from my code.

Screenshot 2024-02-01 at 7 47 10 PM
gitguardian[bot] commented 5 months ago

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [4465424](https://dashboard.gitguardian.com/incidents/4465424?occurrence=70910631) | Triggered | Generic High Entropy Secret | e8dfd50fa8c697d475b134aea101f2682519bb3b | assets/js/v3.js | [View secret](https://github.com/Flutterwave/PHP-v3/commit/e8dfd50fa8c697d475b134aea101f2682519bb3b#diff-b59dfd0994f02b9d9e172338ff2fddf61cfbb604be89eee9a56a90161dbea7efR1) |
🛠 Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secret safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate this secret](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/generic_high_entropy_secret#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

Abraham-Flutterwave commented 5 months ago

Hi @leonardosahon

if you are using composer, the implementation should work just fine.

use \Flutterwave\Flutterwave;

use \Flutterwave\Config\PackageConfig;

$myConfig = PackageConfig::setUp(
    'FLWSECK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
    'FLWPUBK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
    'FLWSECK_XXXXXXXXXXXXXXX',
    'staging'
); 

Flutterwave::bootstrap($myConfig);

Unless you are calling Flutterwave::bootstrap() again before or after it.

leonardosahon commented 5 months ago

Hi @leonardosahon

if you are using composer, the implementation should work just fine.

use \Flutterwave\Flutterwave;

use \Flutterwave\Config\PackageConfig;

$myConfig = PackageConfig::setUp(
    'FLWSECK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
    'FLWPUBK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
    'FLWSECK_XXXXXXXXXXXXXXX',
    'staging'
); 

Flutterwave::bootstrap($myConfig);

Unless you are calling Flutterwave::bootstrap() again before or after it.

These are my environmental variables:

FLUTTERWAVE_PUBLIC_KEY FLUTTERWAVE_SECRET_KEY FLUTTERWAVE_ENCRYPTION_KEY

If you check the screenshot, immediately after here:

Flutterwave::bootstrap(
      PackageConfig::setUp(
          $_ENV['FLUTTERWAVE_SECRET_KEY'],
          $_ENV['FLUTTERWAVE_PUBLIC_KEY'],
          $_ENV['FLUTTERWAVE_ENCRYPTION_KEY'],
          LayConfig::$ENV_IS_DEV ? "staging" : "production",
      )
  );

The next thing is new PaymentController, which calls Flutterwave::bootstrap() again, this time with an empty parameter, thereby rendering $config empty, meanwhile self::$config contains a value already.

This new call attempts to go back to the .env file, meanwhile, the values have been supplied through the PackageConfig::setUp already.