1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Size limit constants for input validation
/// Maximum length for a JWT token string (64KB)
pub const MAX_TOKEN_LENGTH: usize = 64 * 1024;
/// Maximum length for issuer URLs (2048 characters)
pub const MAX_ISSUER_URL_LENGTH: usize = 2048;
/// Maximum length for JWKS URIs (2048 characters)
pub const MAX_JWKS_URI_LENGTH: usize = 2048;
/// Maximum size for OIDC discovery response (64KB)
pub const MAX_DISCOVERY_RESPONSE_SIZE: usize = 64 * 1024;
/// Maximum size for JWKS response (512KB)
pub const MAX_JWKS_RESPONSE_SIZE: usize = 512 * 1024;
/// Maximum size for decoded JWT header JSON (8KB)
/// Headers are typically small (< 1KB), but we allow reasonable margin
pub const MAX_DECODED_HEADER_SIZE: usize = 8 * 1024;
/// Maximum size for decoded JWT payload JSON (64KB)
/// Payloads can contain custom claims, but must be bounded to prevent DoS
pub const MAX_DECODED_PAYLOAD_SIZE: usize = 64 * 1024;
/// Maximum size for decoded signature bytes (1KB)
/// RSA signatures are typically 256-512 bytes
/// ECDSA signatures vary by curve: P-256 (~64 bytes), P-384 (~96 bytes), P-521 (~132 bytes)
pub const MAX_DECODED_SIGNATURE_SIZE: usize = 1024;
/// Maximum size for Base64URL-encoded signature string (1.5KB)
/// Base64URL encoding adds ~33% overhead, so 1KB decoded ≈ 1.3KB encoded
pub const MAX_SIGNATURE_B64_SIZE: usize = 1536;
/// Maximum size for RSA modulus (n) in bytes (4096 bytes)
/// For JWT/JWKS, practical RSA keys are 2048-4096 bits (256-512 bytes modulus)
pub const MAX_RSA_MODULUS_SIZE: usize = 4096;
/// Maximum size for Base64URL-encoded RSA modulus (n) field (12KB)
/// 8192-byte modulus (65536 bits) encodes to ~10.9KB Base64URL
pub const MAX_JWK_N_SIZE: usize = 12 * 1024;
/// Maximum size for Base64URL-encoded RSA exponent (e) field (64 bytes)
/// Standard exponent 65537 (0x010001) encodes to 4 bytes, but we allow margin
pub const MAX_JWK_E_SIZE: usize = 64;
/// Maximum size for JWK key ID (kid) field (256 bytes)
/// Key IDs are typically short identifiers, but must be bounded
pub const MAX_JWK_KID_SIZE: usize = 256;
/// Maximum size for JWK algorithm (alg) field (16 bytes)
/// Algorithm names are short (e.g., "RS256", "RS384", "RS512")
pub const MAX_JWK_ALG_SIZE: usize = 16;
/// Maximum size for JWK curve (crv) field (16 bytes)
/// Curve names are short (e.g., "P-256", "P-384", "P-521")
pub const MAX_JWK_CRV_SIZE: usize = 16;
/// Maximum size for Base64URL-encoded ECDSA x-coordinate field (128 bytes)
/// P-521 has 66-byte coordinates, encoding to ~88 bytes Base64URL
pub const MAX_JWK_X_SIZE: usize = 128;
/// Maximum size for Base64URL-encoded ECDSA y-coordinate field (128 bytes)
/// P-521 has 66-byte coordinates, encoding to ~88 bytes Base64URL
pub const MAX_JWK_Y_SIZE: usize = 128;
/// Minimum valid Unix timestamp (1970-01-01 00:00:00 UTC)
pub const MIN_TIMESTAMP: i64 = 0;
/// Maximum valid Unix timestamp (2100-01-01 00:00:00 UTC)
/// 4102444800 seconds since Unix epoch
pub const MAX_TIMESTAMP: i64 = 4_102_444_800;
/// Maximum length for algorithm (alg) field in JWT header (16 bytes)
/// Algorithm names are short (e.g., "RS256", "RS384", "RS512")
pub const MAX_ALG_LENGTH: usize = 16;
/// Maximum length for key ID (kid) field in JWT header (256 bytes)
/// Key IDs are typically short identifiers, but must be bounded
pub const MAX_KID_LENGTH: usize = 256;
/// Maximum clock skew tolerance (5 seconds)
pub const MAX_CLOCK_SKEW_SECONDS: u64 = 5;
/// Maximum token age (1 day = 86,400 seconds)
pub const MAX_MAX_AGE_SECONDS: u64 = 60 * 60 * 24;
/// Maximum length for cache keys (3KB)
pub const MAX_CACHE_KEY_LENGTH: usize = 3 * 1024;