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

MySQL: sanitize identifiers #197

Merged
merged 4 commits into from
Oct 3, 2024
Merged

MySQL: sanitize identifiers #197

merged 4 commits into from
Oct 3, 2024

Conversation

vitalyisaev2
Copy link
Member

No description provided.

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.50%. Comparing base (9bf8848) to head (77ce451).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #197   +/-   ##
=======================================
  Coverage   64.50%   64.50%           
=======================================
  Files         104      104           
  Lines        5665     5666    +1     
=======================================
+ Hits         3654     3655    +1     
  Misses       1693     1693           
  Partials      318      318           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -72,7 +75,7 @@ func (sqlFormatter) GetPlaceholder(_ int) string {
}

func (sqlFormatter) SanitiseIdentifier(ident string) string {
return ident
Copy link
Collaborator

@uzhastik uzhastik Oct 3, 2024

Choose a reason for hiding this comment

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

Есть ли гарантия, что в имени нет перевода строки? Или мы не боимся его? А бекслеш боимся?

Copy link
Member Author

@vitalyisaev2 vitalyisaev2 Oct 3, 2024

Choose a reason for hiding this comment

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

Есть ли гарантия, что в имени нет перевода строки?

Нет, гарантий нет. Это пользовательский ввод. Если YQL не валидирует и не отфильтровывает его как-либо, то это дойдёт до коннектора.

А бекслеш боимся?

Это сложный вопрос. Я руководствовался вот этой функцией - здесь написано, что практически любой символ в MySQL может использоваться для идентификатора поля. Поэтому берётся идентификатор и оборачивается просто в бектики. Я лишь добавил экранирование самих бектиков.

Copy link
Member Author

@vitalyisaev2 vitalyisaev2 Oct 3, 2024

Choose a reason for hiding this comment

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

Также там приводится пример функции для проверки валидности идентификаторов. Можно портировать её на Go. Но не уверен, насколько это правильно, ведь для других клиентов мы не занимаемся такой глубокой валидацией ввода, даже сибы на ревью PG/CH не предлагали этого делать. Мне кажется, база должна сама это отсечь.

Copy link
Collaborator

Choose a reason for hiding this comment

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

стремная часть. хорошо бы однажды ее перепроверить

@vitalyisaev2 vitalyisaev2 merged commit 839259a into main Oct 3, 2024
4 checks passed
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.

2 participants