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 the SQL Injection #330

Merged
merged 1 commit into from
Apr 25, 2023
Merged

Fix the SQL Injection #330

merged 1 commit into from
Apr 25, 2023

Conversation

haoel
Copy link
Contributor

@haoel haoel commented Apr 25, 2023

The MySQL/PostgreSQL data checking could have the SQL injection problem, this PR tries to fix it by adding the quotes in SQL and escaping the quotes in configuration.

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (682462a) 99.67% compared to head (450f0f0) 99.68%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #330    +/-   ##
========================================
  Coverage   99.67%   99.68%            
========================================
  Files          82       83     +1     
  Lines        5503     5643   +140     
========================================
+ Hits         5485     5625   +140     
  Misses         12       12            
  Partials        6        6            
Impacted Files Coverage Δ
conf/conf.go 96.73% <ø> (ø)
channel/channel.go 100.00% <100.00%> (ø)
global/global.go 100.00% <100.00%> (ø)
global/probe.go 100.00% <100.00%> (ø)
probe/base/base.go 100.00% <100.00%> (ø)
probe/client/mysql/mysql.go 100.00% <100.00%> (ø)
probe/client/postgres/postgres.go 100.00% <100.00%> (ø)
probe/data.go 100.00% <100.00%> (ø)
probe/notification_strategy.go 100.00% <100.00%> (ø)
probe/result.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +316 to +332
func EscapeQuote(str string) string {
type Escape struct {
From string
To string
}
escape := []Escape{
{From: "`", To: ""}, // remove the backtick
{From: `\`, To: `\\`},
{From: `'`, To: `\'`},
{From: `"`, To: `\"`},
}

for _, e := range escape {
str = strings.ReplaceAll(str, e.From, e.To)
}
return str
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

as a cornor case, abc\'def will be escaped to abc\\\'def, is this a correct result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's correct. The sql injection always needs a quote to close the previous statement. So escape the quote is key work to prevent injection.

@haoel haoel added this pull request to the merge queue Apr 25, 2023
Merged via the queue into megaease:main with commit caaf586 Apr 25, 2023
@oxeye-daniel
Copy link

Hi @haoel, great to see the issue is addressed. Could you open a Github security advisory for the SQL injection vulnerability we found?

@localvar
Copy link
Collaborator

@oxeye-daniel , thanks for the reminder, we have open a github security advisory at: GHSA-4c32-w6c7-77x4

please help review and let us know if anything is incorrect, as this is the first time we open such an advisory, thanks.

@oxeye-daniel
Copy link

Hi @localvar thanks a lot! No problem, you can go ahead and add me as editor for the advisory so I can suggest changes

@localvar
Copy link
Collaborator

@oxeye-daniel , added

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.

None yet

5 participants