Kotlin 2.4

Last reviewed Oct 28, 2026

Export as PDF

Prompt Details

Prompt Composition

1prompt
  1. Kotlin 2.4116 lines · 3.7K tokens

CWE Coverage

  • 20
  • 22
  • 59
  • 78
  • 79
  • 88
  • 89
  • 94
  • 117
  • 201
  • 208
  • 209
  • 287
  • 295
  • 297
  • 323
  • 338
  • 362
  • 367
  • 378
  • 470
  • 471
  • 476
  • 494
  • 502
  • 532
  • 540
  • 611
  • 770
  • 772
  • 807
  • 829
  • 863
  • 915
  • 916
  • 918
  • 1333

Prompt Preview

Apply these rules to Kotlin 2.4 across JVM, Android, Native, JavaScript, and multiplatform code. Static nullability and sealed types improve design but don't validate values crossing runtime boundaries. Keep platform-specific security guarantees explicit in expect and actual implementations and at every interop boundary.

Nullability and type modeling

  • Never use !! on values derived from input, configuration, lookups, interop, deserialization, or asynchronous state.
  • Model authentication, authorization, ownership, and validation outcomes with closed sealed types rather than nullable values or booleans.
  • Use value classes or dedicated types to distinguish validated identifiers, paths, URLs, tokens, and tenant-scoped keys.
  • Reject unknown enum and sealed-state values from external systems instead of selecting a permissive default.
  • Keep raw boundary models separate from validated immutable domain models.

Input validation and conversion

  • Validate length, syntax, encoding, range, and allowed values before converting attacker-controlled text.
  • Use exact, locale-independent parsing for protocol numbers, dates, identifiers, and security decisions.
  • Validate signs, leading zeros, and application bounds around toIntOrNull, which already rejects surrounding whitespace and values outside the Int range.
  • Reject unknown fields and mass-assigned privileged properties in request and message models.
  • Normalize values only after basic validation and authorize the same canonical representation later used for access.

Serialization boundaries

  • Treat decoded