Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / plugins / mcollective / validator / shellsafe_validator.rb
diff --git a/plugins/mcollective/validator/shellsafe_validator.rb b/plugins/mcollective/validator/shellsafe_validator.rb
new file mode 100644 (file)
index 0000000..d03e420
--- /dev/null
@@ -0,0 +1,13 @@
+module MCollective
+  module Validator
+    class ShellsafeValidator
+      def self.validate(validator)
+        raise ValidatorError, "value should be a String" unless validator.is_a?(String)
+
+        ['`', '$', ';', '|', '&&', '>', '<'].each do |chr|
+          raise ValidatorError, "value should not have #{chr} in it" if validator.match(Regexp.escape(chr))
+        end
+      end
+    end
+  end
+end