Class: Hooks::Plugins::Auth::TimestampValidator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/plugins/auth/timestamp_validator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Validates and parses timestamps for webhook authentication

This class provides secure timestamp validation supporting both ISO 8601 UTC format and Unix timestamp format. It includes strict validation to prevent various injection attacks.

Examples:

Basic usage

validator = TimestampValidator.new
validator.valid?("1609459200", 300)  # => true/false
validator.parse("2021-01-01T00:00:00Z")  # => 1609459200

Instance Method Summary collapse

Instance Method Details

#parse(timestamp_value) ⇒ Integer?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Security: Strict validation prevents various injection attacks

Parse timestamp value supporting both ISO 8601 UTC and Unix formats

Parameters:

  • timestamp_value (String)

    The timestamp string to parse

Returns:

  • (Integer, nil)

    Epoch seconds if parsing succeeds, nil otherwise



41
42
43
44
45
# File 'lib/hooks/plugins/auth/timestamp_validator.rb', line 41

def parse(timestamp_value)
  return nil if invalid_characters?(timestamp_value)

  parse_iso8601_timestamp(timestamp_value) || parse_unix_timestamp(timestamp_value)
end

#valid?(timestamp_value, tolerance = 300) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validate timestamp against current time with tolerance

Parameters:

  • timestamp_value (String)

    The timestamp string to validate

  • tolerance (Integer) (defaults to: 300)

    Maximum age in seconds (default: 300)

Returns:

  • (Boolean)

    true if timestamp is valid and within tolerance



26
27
28
29
30
31
32
33
34
# File 'lib/hooks/plugins/auth/timestamp_validator.rb', line 26

def valid?(timestamp_value, tolerance = 300)
  return false if timestamp_value.nil? || timestamp_value.strip.empty?

  parsed_timestamp = parse(timestamp_value.strip)
  return false unless parsed_timestamp.is_a?(Integer)

  now = Time.now.utc.to_i
  (now - parsed_timestamp).abs <= tolerance
end