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

Fix: Fixing all the issues related to assigning privileges to databases with '_' #17015

Merged
merged 1 commit into from
Jul 21, 2021

Conversation

iifawzi
Copy link
Contributor

@iifawzi iifawzi commented Jul 15, 2021

Signed-off-by: Fawzi E. Abdulfattah iifawzie@gmail.com

Description

This PR fixes all the bugs discussed at #17010 and the bug mentioned in #16994.

Fixes:

  • The grant/revoke queries will be escaped once - Previously, when single db is selected, no escaping at all, and when multiple db are selected got escaped twice -
  • All the UI that's responsible to show the databases names are unescaped for the user to see the actual names.
  • All the links to edit/revoke are fixed.
  • Multiple select list will only show the databases that aren't already granted privileges.

Screen Shot 2021-07-16 at 12 37 43 AM

Screen Shot 2021-07-16 at 12 37 06 AM

Screen Shot 2021-07-16 at 12 36 56 AM

Screen Shot 2021-07-16 at 12 47 11 AM

@williamdes williamdes self-assigned this Jul 16, 2021
@williamdes williamdes added this to the 5.1.2 milestone Jul 16, 2021
@williamdes williamdes added this to In progress in pull-requests via automation Jul 16, 2021
@williamdes williamdes moved this from In progress to Review in progress in pull-requests Jul 16, 2021
@williamdes
Copy link
Member

Hi @iifawzi
Your work is great, that said there is something wrong
Let me explain: you need to show the escaping if there is some, but not escape the escaping as we can see when granting permission

Currently you removed all escaping, this is not right because as you can see on my example a_% is a wildcard example. And using your PR it would prevent distinguishing between literal char and escaped

So you need to add back escaping on DB list, edit page. That said the queries look good !

I have a theory about why there is two \ used, maybe it is to escape the \ at the insert moment, that would explain the actual GUI

mysql.db

image

Show dbs before

image

Show dbs after

Sélection_2021071602:38:11001

@iifawzi
Copy link
Contributor Author

iifawzi commented Jul 16, 2021

I can see that in your mysql.db table, the a_% and a_hidden are not escaped, I think this's incorrect, and this's the actual bug at QA_5_1 #17010 (comment), right? if this screenshot is taken from using this PR implementation, there's something wrong then, but i'm not able to re-produce such a case, did you remove all the grants that were made before testing this PR?

a_% is a wildcard example. And using your PR it would prevent distinguishing between literal char and escaped

How can I encounter such an issue? what do you mean by distinguishing between literal char and escaped?

This PR implementation is suppose to have this:

  • a_hidden db, should be escaped in the query to be a\_hidden, added to the mysql.db table as the same as shown in the query a\_hidden, and shown in the GUIs as a_hidden
  • a_% db, should be escaped in the query to be a\_%, added to the mysql.db table as the same as shown in the query a\_%, and shown in the GUIs as a_%

are we ok with this? can you give me a case that might prevent this from happening or make a conflict with it in the GUI?

I'm asking because, if the queries look good, so it means the GUI looks good I think, because i'm just unescaping the name used in the query, and used it in the GUI, if the. GUI can be misleading in any case, so it means there will be something wrong in the queries I think. how can the query looks good, and the GUI have bugs?

It took too long I know, thank your for your patience, I just wanna be sure that I understood your points before adding back the escaping on DB list, edit page GUIs.

Thank you again.

@williamdes
Copy link
Member

I can see that in your mysql.db table, the a_% and a_hidden are not escaped, I think this's incorrect,

No, it's indended and is a wildcard example

How can I encounter such an issue? what do you mean by distinguishing between literal char and escaped?

You can grant a user the use of a_foo% using the box after the list of tables, If I am right it will mean a any char foo any string

I am not sure if this is more clear, but there is a case where _ means one char and \_ means literal _

@williamdes
Copy link
Member

So you only need to escape on database lists add to make _ chars escaped, but if the user enters _ in the box then keep it not escaped :)

@iifawzi
Copy link
Contributor Author

iifawzi commented Jul 16, 2021

You can grant a user the use of a_foo% using the box after the list of tables, If I am right it will mean a any char foo any string

Ohhh... I got it. Nice! I never thought that this's possible.

Signed-off-by: Fawzi E. Abdulfattah <iifawzie@gmail.com>
Copy link
Contributor Author

@iifawzi iifawzi left a comment

Choose a reason for hiding this comment

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

I've tested the mentioned cases in the PR's description and it worked, and the GUI now is working as expected, Hopefully :d.

@@ -514,8 +514,7 @@ public function getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname
return 'SELECT * FROM `mysql`.`db`'
. " WHERE `User` = '" . $this->dbi->escapeString($username) . "'"
. " AND `Host` = '" . $this->dbi->escapeString($hostname) . "'"
. " AND '" . $this->dbi->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
. ' LIKE `Db`;';
. " AND `Db` = '" . $this->dbi->escapeString($db) . "'";
Copy link
Contributor Author

@iifawzi iifawzi Jul 17, 2021

Choose a reason for hiding this comment

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

I've encountered another issue regarding the privileges table, if we have a privileges on a_% and a_hidden.
before, if we tried to edit the privileges on a_hidden, the privileges of a_% will be shown instead. (can be tested on https://demo.phpmyadmin.net/master/ ), I've fixed it by looking for an exact match instead of using LIKE, and removed the unescaping function, I've tested all the cases that crossed my mind they worked as expected, I hope that I'm not missing anything.

Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

This all looks very nice, I will test it !

pull-requests automation moved this from Review in progress to Reviewer approved Jul 20, 2021
Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

Awesome !
It fixes all bugs

@williamdes
Copy link
Member

williamdes commented Jul 20, 2021

Just found something ( #16477 is back)
image
Missing a tab
image

@iifawzi
Copy link
Contributor Author

iifawzi commented Jul 21, 2021

Hmm, I think based on #16477 (comment), the issue was due to considering the underscore as wildcard - the bug mentioned here #17010 (comment) -
since this commit fixed #17010 (comment), so #16477 is fixed too, here's an example granting a permissions on db with underscore bar_1_prod

image

The issue you've mentioned is regarding granting a permissions on a wildcard example like a_% or bar_1_prod, logically it shouldn't be allowed I think, we have no actual tables. I've also tested in https://demo.phpmyadmin.net/master/index.php and it have thrown an error table doesn't exist, which make sense I think.
image

the mess comes from that when #16481 is introduced, this bug #17010 (comment) wasn't fixed. which leaded to allowing the table tab to appear even for wildcards DBs a_% or bar_1_prod, which's is incorrect as per my understand, I might be missing something though

@williamdes
Copy link
Member

@sudo-robot deploy

@williamdes
Copy link
Member

Hmm, you are right. This was probably a bug, I could not replicate it on the deployed server.
And yes it makes sense that you can not add DBs to a wildcard privilege but that you can on a normal one.
Probably I made a mistake in my testing, I will let you know ;)

@iifawzi
Copy link
Contributor Author

iifawzi commented Jul 21, 2021

let me know if you've found anything that could be fixed, and thank you for following up with this, your guidance, and your fast replies @williamdes, You're encouraging me to keep contributing

@williamdes
Copy link
Member

let me know if you've found anything that could be fixed, and thank you for following up with this, your guidance, and your fast replies @williamdes, You're encouraging me to keep contributing

I am so happy to have so great and involved contributions ! ❤️

Conclusion: it works better when I use an escaped version 🤦🏻

image

williamdes added a commit that referenced this pull request Jul 21, 2021
Pull-request: #17015
Ref: #16994

Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes williamdes merged commit ad5aad6 into phpmyadmin:QA_5_1 Jul 21, 2021
pull-requests automation moved this from Reviewer approved to Done Jul 21, 2021
williamdes added a commit that referenced this pull request Jul 21, 2021
Signed-off-by: William Desportes <williamdes@wdes.fr>
williamdes added a commit that referenced this pull request Jul 21, 2021
Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes
Copy link
Member

✅ Tests fixed: 25c2cfe
✅ And one new test: 6d5c5e6

ℹ️ You can run tests with ./vendor/bin/phpunit --no-coverage --exclude-group=selenium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
pull-requests
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants