Bug #7861 Column level security inconsistent with db/table level security
Submitted: 13 Jan 2005 6:19 Modified: 3 May 2006 7:12
Reporter: Arjen Lentz Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Security: Privileges Severity:S3 (Non-critical)
Version:any OS:Any (any)
Assigned to: Assigned Account CPU Architecture:Any

[13 Jan 2005 6:19] Arjen Lentz
Description:
If a user is only granted access on particular columns of a table, a SELECT * query actually tells the user that they don't have access to the other specific columns. In other words, it gives information about what the user does not have access to.

This is inconsistent. Example on the db level: a user does not have access to the foo database, it will see "access denied" regardless of whether the foo db exists or not. That is correct: no info, even on the existence, if the user no access!
The same applies to tables.

And it should work the same way for columns.

How to repeat:
(load "world" db)
GRANT SELECT (continent) ON world.country TO coluser@localhost;

SELECT * FROM country;
Error: select command denied to user 'coluser'@'localhost' for column 'Code' in table 'country'
(I don't have access any columns other than "Continent", but now the server tells me that a column "Code" exists - too much info!)

SHOW CREATE TABLE country;
CREATE TABLE `country` (
  `Code` char(3) NOT NULL default '',
  `Name` char(52) NOT NULL default '',
  `Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
  `Region` char(26) NOT NULL default '',
  `SurfaceArea` float(10,2) NOT NULL default '0.00',
  `IndepYear` smallint(6) default NULL,
  `Population` int(11) NOT NULL default '0',
  `LifeExpectancy` float(3,1) default NULL,
  `GNP` float(10,2) default NULL,
  `GNPOld` float(10,2) default NULL,
  `LocalName` char(45) NOT NULL default '',
  `GovernmentForm` char(45) NOT NULL default '',
  `HeadOfState` char(60) default NULL,
  `Capital` int(11) default NULL,
  `Code2` char(2) NOT NULL default '',
  PRIMARY KEY  (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

(eep! I only have access to the one column, yet I can see the structure of the entire table!)

Suggested fix:
a) Make error msgs consistent/safe
b) And don't allow SHOW CREATE TABLE unless user has access to the whole table.
[24 Jan 2008 20:57] Sergei Golubchik
bug#27145 will fix the SHOW CREATE TABLE part
[11 Nov 2017 20:51] Federico Razzoli
Now that the SHOW CREATE TABLE part is fixed, the inconsistency is remarkable. If I look at SHOW CREATE, I only see columns that I can access; but if I run a SELECT * I will get an error.

Still, the bug is 12 years old. Is there any plan to fix it completely?