Merge pull request #71 from runningman/security

Fixed regex of database user.
This commit is contained in:
Dan Bode 2012-05-06 23:56:01 -07:00
commit 05f7807fc0

View file

@ -7,7 +7,9 @@ Puppet::Type.newtype(:database_user) do
newparam(:name, :namevar=>true) do
desc "The name of the user. This uses the 'username@hostname' or username@hostname."
validate do |value|
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /\w+@[\w%]+/
# https://dev.mysql.com/doc/refman/5.1/en/account-names.html
# Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /[\w-]*@[\w%\.]+/
username = value.split('@')[0]
if username.size > 16
raise ArgumentError, "MySQL usernames are limited to a maximum of 16 characters"