-
Notifications
You must be signed in to change notification settings - Fork 40
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
Installer should properly encode database usernames and passwords to prevent special characters from breaking the install #2904
Comments
Needs tests, but the code itself is ready for review. |
Thanks for the PR! I set up a test site with the code changes and was able to install Backdrop although I used three special characters (forward slash, semicolon, and hash sign) in the database password which would formerly have led to a failed installation. So, looks good to me, but we still need someone who can make a code review. |
…d password from the database URL.
…d password from the database URL.
Thanks @jlfranklin and @olafgrabienski! This looks great. Merged backdrop/backdrop#2034 in to 1.x and 1.8.x. |
I have experienced a problem with upgrading a site from 1.8.0 to 1.8.1, 1.8.2 and 1.9.0 because my database password contained a % character. This caused the system to crash with the error message |
Just a % character or was it a % followed by two [0-9a-f]? Obviously, we can't add an update hook to look for them, the (now) bad password would take the site offline before we could run. We could trap the exception early on in Bootstrap, and add an error message that point to a change record / FAQ entry about the URL encoding. |
For the record, the password I was using was |
I suppose the other option is to try the password both encoded and unencoded. |
Reopening this to investigate options. |
Hm, so it turns out that specifically the @Graham-72's password of course also met these conditions, resulting in a modified password. For solutions, here are some thoughts:
|
Here's an initial attempt at trying both passwords. It seems to solve the problem when using a password such as the one suggested by @Graham-72. I'm not satisfied with this yet though. It really needs some kind of warning in the status report that indicates your settings.php values should be updated. |
Not sure if this is the right issue but it seems maybe so -- reported in the forum recently:
|
I think it is the right issue. @quicksketch and @jlfranklin, friendly reminder: What is missing to fix the issue? |
What @quicksketch said in #2904 (comment) seems to be a technical direction. We just need a PR that implements it I guess. |
...there seems to be a PR available in backdrop/backdrop#2086, but @quicksketch said he's not very happy with it (although it seems to get the job done). Perhaps we should reconsider this and merge this working solution, along with a |
When a core committer rejects something, it means that the code is not suitable for core inclusion as it is, and should not be merged. Adding @todo's to fix later only ends up with a codebase full of todos. :) Perhaps we can find a compromise of something that will make the committer happy, but is also quick & easy to achieve? |
FWIW, I also have a problem with the PRs current approach - by wrapping the fallback in try/catch, it always lets the connection run into an exception initially - on every database connect for affected credentials. Hopefully there's a smarter way to catch the problem. |
I can't quite understand what this is stalled on. For me, having special characters in db passwords is an essential part of site security. |
@yorkshire-pudding I'd also love to see this fixed. There seem to be issues regarding the approach, see #2904 (comment) by @quicksketch and #2904 (comment) by @indigoxela. |
If I read everything correctly from past comments here and in #2231, then this seems to be happening when there's a special set/sequence of characters being used as username/password or db name (right?). That "problematic" sequence is Also, This seems challenging enough, yet possibly solvable relatively easily. I'd like to take a crack at it 🙂 |
Originally posted by @jlfranklin in #2231 (comment) I've done quite some testing on my local, and this is so true 😞 ...I've created a custom function backdrop_settings_parse_database_url($database_url) {
// Perform a very basic sanity check based on the expected format of the URL.
$is_valid_url = is_string($database_url) && preg_match('#^mysql:\/\/.+:.+@.+\/.+$#', $database_url);
// Attempt to parse the various URL parts using parse_url().
$database_parts = parse_url($database_url);
// If parse_url() returned an array, then use that.
if (is_array($database_parts)) {
// Remove leading slash from database name.
$database_parts['path'] = substr($database_parts['path'], 1);
}
// When parse_url() encounters certain "problematic" characters (such as /, #,
// and ;) in the username or password, it may return FALSE in some PHP
// versions. That doesn't mean that the URL provided is incorrect - we use
// custom parsing logic in that case.
elseif (is_bool($database_parts) && $is_valid_url) {
[custom logic using preg_match() goes here]
...
$database_parts = ...;
}
return $database_parts;
} Unfortunately, parse_url('mysql://test_user:p@s5/w#rd@localhost:3306/test_database'); Result:
See it in action: https://3v4l.org/j3Ygt
Right, so that was a good effort @jlfranklin, but even with the change that went in with backdrop/backdrop@1f7d2df where we now use No matter how much we want to avoid this and use native PHP functions as much as possible, I believe that the only solution here is to create our own function, which should live in I'm pretty close to a regex that gets the job done, and I have tested various potentially problematic passwords, but as it often is the case with regex's, there might be something that I might have missed. So I will provide that to everyone subscribed in this thread, and you please do your best to break it then 😉 ...provide feedback, and I will then tweak the regex to account for any of the reported edge cases. |
A couple of questions:
|
@klonos - I can't see the point of having to include the scheme/driver either. |
This may not be required if the simplified array in #2231 is introduced. |
I think this is now |
It's a different approach, actually. But IMO a more robust one. Instead of trying to fix the problems with urlencoding and decoding - which turned out to be quite tricky, provide a default db settings approach, which completely avoids encoding/decoding. |
@yorkshire-pudding I also see this issue here resolved by the mentioned PR which fixes issue #2231. Thanks for all your work there, btw! |
Resolved in a different way by backdrop/backdrop#4567 |
One of a few bugs off of #2231.
This issue addresses the immediate issue of
parse_url()
not handling special characters by encoding them.The text was updated successfully, but these errors were encountered: