class

Session::Configuration

Inherits Reference < Object

Constants

DEFAULT_SECRET = "1sxc1aNxGHTTZKlK5cpCgufJAqGM4G13"

The secret older releases signed with when none was configured. It is public, so it is never used by default any more and is refused where require_secure_secret holds.

MIN_SECRET_BYTES = 32

AES-256 takes a 32-byte key, and the secret is that key unless use_kdf derives one. The HMAC signature always uses the secret itself, so the minimum holds with use_kdf too.

PRODUCTION_ENVIRONMENTS = ["production", "staging"] of ::String

Environments that must not run on the published default secret.

Constructors

from_preset(preset : Symbol) : Configuration

Load configuration from a preset (returns a new Configuration instance) Available presets: :development, :production, :high_security, :testing, :clustered

Source

Class methods

process_secret

The random fallback, one per process so every configuration agrees on it; warns once.

Source
production_environment?
Source

Instance methods

allow_insecure_cookies

Where a secure secret is required (production, staging), insecure cookies are refused too, unless this opts out explicitly.

Source
allow_insecure_cookies=(allow_insecure_cookies : Bool)

Where a secure secret is required (production, staging), insecure cookies are refused too, unless this opts out explicitly.

Source
apply_preset(preset : Symbol) : self

Apply a preset's settings to this configuration instance Available presets: :development, :production, :high_security, :testing, :clustered

Source
bind_to_ip

Session binding: bind sessions to client fingerprint for security

Source
bind_to_ip=(bind_to_ip : Bool)

Session binding: bind sessions to client fingerprint for security

Source
bind_to_user_agent
Source
bind_to_user_agent=(bind_to_user_agent : Bool)
Source
circuit_breaker_config
Source
circuit_breaker_config=(circuit_breaker_config : CircuitBreakerConfig)
Source
circuit_breaker_enabled

Circuit breaker configuration for Redis connections

Source
circuit_breaker_enabled=(circuit_breaker_enabled : Bool)

Circuit breaker configuration for Redis connections

Source
cluster

Cluster configuration for multi-node deployments with Redis Pub/Sub

Source
cluster=(cluster : ClusterConfig)

Cluster configuration for multi-node deployments with Redis Pub/Sub

Source
compress_data

Data compression: when enabled, session data is compressed before storage

Source
compress_data=(compress_data : Bool)

Data compression: when enabled, session data is compressed before storage

Source
compression_threshold

Minimum size in bytes before compression is applied (smaller data may grow with compression)

Source
compression_threshold=(compression_threshold : Int32)

Minimum size in bytes before compression is applied (smaller data may grow with compression)

Source
digest_algorithm

Digest algorithm for HMAC signatures (:sha256 recommended, :sha1 for legacy)

Source
digest_algorithm=(digest_algorithm : Symbol)

Digest algorithm for HMAC signatures (:sha256 recommended, :sha1 for legacy)

Source
digest_fallback

Enable auto-fallback to SHA1 for migrating old sessions (logs deprecation warning)

Source
digest_fallback=(digest_fallback : Bool)

Enable auto-fallback to SHA1 for migrating old sessions (logs deprecation warning)

Source
enable_retry

Error handling configuration

Source
enable_retry=(enable_retry : Bool)

Error handling configuration

Source
encrypt_redis_data

Redis encryption: when enabled, session data stored in Redis is encrypted

Source
encrypt_redis_data=(encrypt_redis_data : Bool)

Redis encryption: when enabled, session data stored in Redis is encrypted

Source
encryptor

The encryptor for the current settings. It is reused while they stay the same, so PBKDF2 (use_kdf) runs once per secret, salt and iteration count, not on every encrypt and decrypt.

Source
fail_fast_on_corruption
Source
fail_fast_on_corruption=(fail_fast_on_corruption : Bool)
Source
kdf_iterations
Source
kdf_iterations=(kdf_iterations : Int32)
Source
kdf_salt
Source
kdf_salt=(kdf_salt : String)
Source
log_errors
Source
log_errors=(log_errors : Bool)
Source
metrics_backend

Metrics backend for observability (default: NullBackend discards all metrics)

Source
metrics_backend=(metrics_backend : Metrics::Backend)

Metrics backend for observability (default: NullBackend discards all metrics)

Source
on_client
Source
on_client=(on_client : Proc(String, Session::Base, Nil))
Source
on_deleted
Source
on_deleted=(on_deleted : Proc(String, Session::Base, Nil))
Source
on_loaded
Source
on_loaded=(on_loaded : Proc(String, Session::Base, Nil))
Source
on_regenerated
Source
on_regenerated=(on_regenerated : Proc(String, String, Session::Base, Nil))
Source
on_started
Source
on_started=(on_started : Proc(String, Session::Base, Nil))
Source
require_secure_secret
Source
require_secure_secret=(require_secure_secret : Bool | Nil)

Whether a missing or published secret is an error rather than a warning. Unless set, it holds in production and staging, read from CRYSTAL_ENV (case-insensitive) each time it is checked.

Source
retry_config

Retry configuration for resilient operations

Source
retry_config=(retry_config : RetryConfig)

Retry configuration for resilient operations

Source
secret

The key sessions are encrypted and signed with: the one configured, else SESSION_SECRET. Without either, InsecureSecretException where require_secure_secret holds, and otherwise a random key for this process only (sessions do not survive a restart or reach another instance). Not memoised: the random fallback is refused again as soon as require_secure_secret holds.

Source
secret=(secret : String | Nil)
Source
session
Source
session_key
Source
session_key=(session_key : String)
Source
sliding_expiration

Sliding expiration: when enabled, session timeout resets on each access

Source
sliding_expiration=(sliding_expiration : Bool)

Sliding expiration: when enabled, session timeout resets on each access

Source
timeout
Source
timeout=(timeout : Time::Span)
Source
trust_proxy_headers

Whether X-Forwarded-For and X-Real-IP name the client for IP binding. Any client can send them, so they are believed only when a trusted proxy in front of the app sets them.

Source
trust_proxy_headers=(trust_proxy_headers : Bool)

Whether X-Forwarded-For and X-Real-IP name the client for IP binding. Any client can send them, so they are believed only when a trusted proxy in front of the app sets them.

Source
use_kdf

Key Derivation Function (KDF) settings When enabled, derives cipher key from secret using PBKDF2-SHA256

Source
use_kdf=(use_kdf : Bool)

Key Derivation Function (KDF) settings When enabled, derives cipher key from secret using PBKDF2-SHA256

Source
using_default_secret?

Check if the current secret is the insecure default

Source
validate_secret!

Validate secret security - warns or raises based on configuration

Source
validate_secret_for!(store : Store) : Nil

Raises InsecureSecretException when store encrypts with the secret (Store#encrypts_with_secret?: a CookieStore, or a Redis store with encrypt_redis_data) and the secret is missing, published or too short.

Source