pingcap / pingcap/tidb

The permission check of `DROP STATS` command is missing

Open
#62,429 2 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

The permission check of `DROP STATS` command is missing. A user without any privileges can also execute the command on unauthorized tables.

It can be reproduced on docker image `pingcap/tidb:nightly`.

### 1. Minimal reproduce step (Required)

1. Create an empty user with root:
```sql
-- login as user 'root'
-- create a table for test
CREATE DATABASE test;
CREATE TABLE test.tbl (x INT);

-- create an empty user
CREATE USER foo;
SHOW GRANTS FOR foo;
/*
+---------------------------------+
| Grants for foo@% |
+---------------------------------+
| GRANT USAGE ON *.* TO 'foo'@'%' |
+---------------------------------+
*/
```

2. Log in as the user foo and execute (**Note that foo does not have any privileges**):
```sql
-- login as user 'foo'
DROP STATS test.tbl;
-- Query OK, 0 rows affected (0.02 sec)
```

### 2. What did you expect to see? (Required)

Since the user 'foo' does not have any privilege, he should not be able to execute the `DROP STATS` command on unauthorized tables.

### 3. What did you see instead (Required)

The command succeed unexpectedly.

### 4. What is your TiDB version? (Required)

```
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.2-20250707-57b0825
Edition: Community
Git Commit Hash: 57b0825102d3dce7679856df8f39e1c8641285d7
Git Branch: heads/refs/tags/v8.5.2-20250707-57b0825
UTC Build Time: 2025-07-07 09:12:09
GoVersion: go1.23.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the unauthorized DROP STATS execution using the SQL steps in the issue, then trace the command's permission-check entry point and existing authorization tests. Done means users without privileges are rejected on unauthorized tables and a regression test covers this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
authorization, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.