Class: Rubino::Security::PrefixDeriver::Rule

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubino/security/prefix_deriver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



21
22
23
# File 'lib/rubino/security/prefix_deriver.rb', line 21

def kind
  @kind
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



21
22
23
# File 'lib/rubino/security/prefix_deriver.rb', line 21

def value
  @value
end

Instance Method Details

#covers?(command) ⇒ Boolean

Does this remembered rule cover ‘command`? Matching mirrors the storage shape: a pattern covers any sibling of its class, a prefix covers any command that start_with? it (like CommandAllowlist), an exact command covers only itself.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/rubino/security/prefix_deriver.rb', line 26

def covers?(command)
  cmd = command.to_s
  case kind
  when :pattern then DangerousPatterns.detect(cmd)[1] == value
  when :prefix  then cmd.strip.start_with?(value.to_s.strip)
  else               cmd.strip == value.to_s.strip
  end
end