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 database quoting problem in collector 'info_schema.tables' #908

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

oblitorum
Copy link
Contributor

In collector/info_schema_tables.go, the SQL it uses to retrieves the table meta data is

SELECT
	TABLE_SCHEMA,
	...
FROM information_schema.tables
WHERE TABLE_SCHEMA = '%s'

Which could cause a problem if the schema contains the single quote character ' (It's indeed a vaild character in database/table name), we should use the placeholder ? and pass the schema as an argument to db.QueryContext(...) to avoid this kind of problem. Also to avoid the SQL injection problem as user can pass anything to --collect.info_schema.tables.databases in reality (accidentally or on purpose).

Copy link
Contributor

@cristiangreco cristiangreco left a comment

Choose a reason for hiding this comment

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

Thanks! I've just encountered something similar myself.

@SuperQ SuperQ merged commit a802109 into prometheus:main Feb 14, 2025
13 checks passed
@oblitorum oblitorum deleted the fix-database-quote branch February 14, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants