Skip to content

Commit

Permalink
Merge pull request #510 from Shopify/ac-mysql-regex
Browse files Browse the repository at this point in the history
Fix regex in Mysql2 adapter
  • Loading branch information
adrianna-chang-shopify authored Oct 27, 2023
2 parents ad1515c + 475ce4b commit fd68b11
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/semian/mysql2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ module Mysql2
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 3306

QUERY_WHITELIST = Regexp.union(
%r{\A(?:/\*.*?\*/)?\s*ROLLBACK}i,
%r{\A(?:/\*.*?\*/)?\s*COMMIT}i,
%r{\A(?:/\*.*?\*/)?\s*RELEASE\s+SAVEPOINT}i,
)
QUERY_ALLOWLIST = %r{\A(?:/\*.*?\*/)?\s*(ROLLBACK|COMMIT|RELEASE\s+SAVEPOINT)}i

class << self
# The naked methods are exposed as `raw_query` and `raw_connect` for instrumentation purpose
Expand Down Expand Up @@ -114,7 +110,7 @@ def resource_exceptions
end

def query_whitelisted?(sql, *)
QUERY_WHITELIST =~ sql
QUERY_ALLOWLIST =~ sql
rescue ArgumentError
# The above regexp match can fail if the input SQL string contains binary
# data that is not recognized as a valid encoding, in which case we just
Expand Down

0 comments on commit fd68b11

Please sign in to comment.