Class: Hitch::DeviceAuthorizationRateLimit

Inherits:
Object
  • Object
show all
Defined in:
lib/hitch/device_authorization_rate_limit.rb

Overview

The device flow's two fixed-window quotas, counted through the host application's cache store. Neither is politeness: minting is an unauthenticated database write, and the verification quota is a term in the user code's brute-force math (RFC 8628 §5.1) — the fail-closed policy both apply lives in Hitch::RateLimitStore.

Constant Summary collapse

SETTING =
"config.device_authorization_rate_store"

Class Method Summary collapse

Class Method Details

.check_mint!(remote_ip:) ⇒ Object

Per IP: anyone may ask for a code, so the mint quota is keyed the way registration's is.



15
16
17
18
# File 'lib/hitch/device_authorization_rate_limit.rb', line 15

def check_mint!(remote_ip:)
  check!("hitch:device:ip:", RateLimitStore.normalize_ip(remote_ip),
    Hitch.configuration.device_authorization_limit)
end

.check_verification!(principal:) ⇒ Object

Per signed-in principal, checked only after authentication: anonymous traffic cannot drain a person's guessing budget.



22
23
24
25
26
27
28
29
30
31
# File 'lib/hitch/device_authorization_rate_limit.rb', line 22

def check_verification!(principal:)
  actor = RateLimitStore.actor_for(principal)
  # A principal that cannot be identified cannot be counted, and
  # counting is what makes short codes safe — refuse, don't admit
  # unmetered.
  raise RateLimitStore::Unavailable, "principal has no id to rate limit" if actor.nil?

  check!("hitch:device:code:", actor,
    Hitch.configuration.device_code_verification_limit)
end