Best practices: sanitize user input by default, handle unset, and environment variables
The complete source of sanitized_practices.ek9, compiled by the EK9 compiler. Shown on sanitized.html.
#!ek9 defines module site.sanitized.practices defines function //GOOD: default to sanitized for user input processUserData() -> input as sanitized String <- rtn as String: String(input) //Only omit sanitized for trusted internal data processInternalData() -> trustedInput as String <- rtn as String: trustedInput doCreateUser() -> username as String <- created as Boolean: username? logValidationError() -> message as String Stderr().println(message) createUser() -> username as sanitized String <- result as Boolean? if username? //Safe to process result: doCreateUser(username) else //Threat detected - apply the normal business validation message: //defence in depth without leaking what was detected result: false logValidationError("Invalid username format") configurationPath() <- rtn as String: String() sanitizer <- InputSanitizer(Stderr()) envVars <- EnvVars() //Path traversal patterns are legitimate in environment variables configPath <- envVars.get("CONFIG_PATH") if configPath? rtn: sanitizer.sanitizeWithoutPathChecks(configPath)