Method: Contrast::Agent::Protect::Rule::InputClassification::Encoding#cs__decode64

Defined in:
lib/contrast/agent/protect/rule/input_classification/encoding.rb

#cs__decode64(value, input_type) ⇒ String

This method will decode the value using Base64.decode64, only if value was encoded. If value is not encoded, it will return the original value.

Parameters:

  • value (String)

    input to decode.

  • input_type (Symbol)

    input type.

Returns:

  • (String)

    decoded or original value.

Raises:

  • (StandardError)


96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/contrast/agent/protect/rule/input_classification/encoding.rb', line 96

def cs__decode64 value, input_type
  return value unless cs__base64?(value, input_type)

  new_value = try_base64_decode(value)
  new_value, success = normalize_encoding(new_value)
  return new_value if success

  value
rescue StandardError => e
  logger.error('Error while decoding base64', error: e, message: e.message, backtrace: e.backtrace)
  value
end