Reject queries that contain restricted keywords in read-only mode

This commit is contained in:
Dan Sosedoff
2019-02-20 18:20:27 -06:00
parent 9f29b10098
commit 40eb74529e
3 changed files with 24 additions and 2 deletions

View File

@@ -1,9 +1,13 @@
package client
import (
"regexp"
"strings"
)
// List of keywords that are not allowed in read-only mode
var restrictedKeywords = regexp.MustCompile(`(?mi)\s?(CREATE|INSERT|DROP|DELETE|TRUNCATE|GRANT|OPEN|IMPORT|COPY|LOCK|SET)\s`)
// Get short version from the string
// Example: 10.2.3.1 -> 10.2
func getMajorMinorVersion(str string) string {
@@ -13,3 +17,8 @@ func getMajorMinorVersion(str string) string {
}
return strings.Join(chunks[0:2], ".")
}
// containsRestrictedKeywords returns true if given keyword is not allowed in read-only mode
func containsRestrictedKeywords(str string) bool {
return restrictedKeywords.MatchString(str)
}