Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle key generation when key is not present in .env #6839

Merged
merged 2 commits into from Nov 10, 2022

Conversation

paulbalandan
Copy link
Member

Description
Fixes #6838

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@totoprayogo1916
Copy link
Contributor

A new problem arises if the encryption.key is already filled and then marked with a hash.
The new key cannot be made active.

# encryption.key = hex2bin:ac14ecef198655f6f465e6bbd0715f2b0eb107c7efb9663d75e7df7574f9757c

@paulbalandan
Copy link
Member Author

key:generate relies on env() to get the replaceable key. If the key is commented out, env() will return ''.

$currentKey = env('encryption.key', '');

@totoprayogo1916
Copy link
Contributor

totoprayogo1916 commented Nov 10, 2022

What I mean is,
encryption.key that has been filled in and marked with the hash

when run spark key:generate,
The .env file does not make the encryption.key active.
And the encryption.key still remains with the hash mark.

@paulbalandan
Copy link
Member Author

Okay. I got what you mean. This is because preg_replace() did not find the old key in the file because it thinks it is an empty string.

@paulbalandan
Copy link
Member Author

@totoprayogo1916 Kindly check new code

Copy link
Contributor

@totoprayogo1916 totoprayogo1916 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works

@samsonasik samsonasik merged commit e86ef99 into codeigniter4:develop Nov 10, 2022
@samsonasik
Copy link
Member

Thank you @paulbalandan

@paulbalandan paulbalandan deleted the fix-key-generate branch November 10, 2022 06:21
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: spark key:generate doesn't generate encryption.key if no template
5 participants