-
Notifications
You must be signed in to change notification settings - Fork 51
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
Override hash_salt when empty vs not set. #73
Override hash_salt when empty vs not set. #73
Conversation
👍 Drupal ships with the hash_salt set to an empty string.
Which means drupal breaks on platform.sh if the code is relying on NULL in order to get the salt from platform sh. In the end, it seems platform.sh would want the code to grab the salt for any empty or non-truthy value it has been set to. This code change adds robustness. |
@adamzimmermann : In your suggested change, won't an existing If we know Drupal will for sure set |
Correct. ✅
Correct. ✅
You are correct. I mixed up the logic (I'm updating my commit now). 🙈 It should be:
We don't know that for sure. That is what is in the latest suggested code, but it is on the user to update their code and this is a file tracked in Git, not something included via Composer, so
This is definitely more clean, and I almost suggested this too, but then was concerned it might throw an error if The PHP docs aren't super conclusive. But from some quick googling, I think my concern is valid. |
9728a76
to
85933e1
Compare
Can I throw a curveball here? It seems to me that if a client is using platformsh, then why would they not want platformsh to clobber whatever hash they may or may not have set up? Is there any valid use-case where someone might need to have or manage their own salt? I think we can cut through a lot of ambiguity if this code simply does this: $settings['hash_salt'] = $platformsh->projectEntropy Boom. Done. Now, if there is a use case for wanting to let a user manage their own salt, then yes, we basically want to say "if you have a salt, and it is not empty, then we'll leave it alone but if you don't have a salt or you have an empty salt (default drupal install), we'll make sure you have one". ie $settings['hash_salt'] = (array_key_exists('hash_salt', $settings) && !empty($settings['hash_salt'])) ? $settings['hash_salt'] : $platformsh->projectEntropy; or, more readably (letting the defined and non-empty condition simply sail on by unmodified): if (!array_key_exists('hash_salt', $settings) || empty($settings['hash_salt'])) {
$settings['hash_salt'] = $platformsh->projectEntropy;
} But this is where things get really silly. Because, if we allow for an end user to manage their own salt, then it seems to me we should allow them to have an empty salt, if that's what they want, and how are we going to know whether the salt is empty because they they left it that way, or because they actually want it to be empty? So, in the end, I feel like platformsh should assume that a user wants their salt to be |
I don't think we can. We can only tell if it is empty, not why or how it was set to empty. @apotek my initial suggestion was going to be $settings['hash_salt'] = empty($settings['hash_salt']) ? $platformsh->projectEntropy : $settings['hash_salt']; which is essentially what you proposed, but changed it since I wasn't anticipating someone removing the value completely from settings.php. The above suggestion will at least catch situations where If this makes sense and is acceptable, either @adamzimmermann can update this PR or I can create a new PR with the above change. Either way we'll update the docs to reflect the change. |
PR updated! Thanks for the feedback and the thoughtful discussion. I think we landed in a good place. |
Thanks @adamzimmermann ! |
1 similar comment
Thanks @adamzimmermann ! |
I recently encountered an issue where my Platform environment was throwing an error 500 after updating to the latest suggested code from Drupal's
default.settings.php
in mysettings.php
file.The issue is from this line:
This causes the
settings.platformsh.php
hash salt logic to think a value is already set due to the way the??
operator works.I can see the case for why you don't want to override any value, even if that value is an empty string. However, if this was just an unwanted/unnoticed side-effect of how
??
works, then I think this fix would help others.