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

Log only parameterized SQL statements without any values #5287

Closed
ssoroka opened this issue Apr 22, 2022 · 3 comments
Closed

Log only parameterized SQL statements without any values #5287

ssoroka opened this issue Apr 22, 2022 · 3 comments
Assignees
Labels

Comments

@ssoroka
Copy link

ssoroka commented Apr 22, 2022

I'm logging this as a bug because it's a security problem.

Description

This was mentioned in #4858, but that issue was closed.

When logging SQL, Gorm logs the full SQL which is generally considered a bad practice. eg

SELECT * FROM `users` WHERE email = "foo@example.com" ORDER BY `users`.`id` LIMIT 1

This causes problems by leaking sensitive fields into the logs, especially when doing inserts and updates. A parameterized version of the query that's always safe to log would be:

SELECT * FROM `users` WHERE email = ? ORDER BY `users`.`id` LIMIT 1

A custom logger here isn't enough, because it doesn't expose the parameterized sql, just the final result with values, and parsing the log line to filter it is both expensive and unrealistic

This would involve changing the Execute function in callbacks.go from

	if stmt.SQL.Len() > 0 {
		db.Logger.Trace(stmt.Context, curTime, func() (string, int64) {
			return db.Dialector.Explain(stmt.SQL.String(), stmt.Vars...), db.RowsAffected
		}, db.Error)
	}

to

	if stmt.SQL.Len() > 0 {
		db.Logger.Trace(stmt.Context, curTime, func() (string, int64) {
			return stmt.SQL.String(), db.RowsAffected
		}, db.Error)
	}
@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Apr 22, 2022
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@ssoroka
Copy link
Author

ssoroka commented May 24, 2022

not completed.

@dorsha
Copy link

dorsha commented Jul 26, 2022

I think this should remain open, this is a major security problem, since it exposed PII.. and there is no way to work with logs in production.

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

Successfully merging a pull request may close this issue.

3 participants