diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..80c10cbc 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -2,3 +2,8 @@ **Vulnerability:** Unvalidated inputs passed to `if()` statements can cause process crashes (`condition has length > 1`) or unexpected coercion vulnerabilities. **Learning:** In R, optional boolean parameters that default to `NULL` should be validated using explicit runtime type validation (e.g., `if (!is.null(flag) && (!is.logical(flag) || length(flag) != 1 || is.na(flag)))`). **Prevention:** Always implement explicit runtime type validation for optional boolean parameters. + +## 2024-09-15 - Strict bounds for regex coercions +**Vulnerability:** Loose regex (`^[0-9]+$`) used for validation before coercion allows unexpected inputs (e.g., numbers that exceed machine integer limits like `9999999999999999999`) causing coercion to `NA` when passed to `as.integer()` which leads to missing values where strict integer matches (like 1 or 2) are required. +**Learning:** In interactive CLI menu handlers, weak regular expressions like `^[0-9]+$` pose a security concern because inputs beyond the 32-bit limit silently coerce to `NA` leading to unexpected behaviors downline. +**Prevention:** Always use exact-match regular expressions with tight bounds (e.g., `^[12]$`) when parsing inputs meant to conform to a specific list of single-digit integer choices to prevent silent `NA` coercion vulnerabilities. diff --git a/R/aFIPC.R b/R/aFIPC.R index 62546519..918e19b1 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -141,7 +141,7 @@ autoFIPC <- } for (attempt in seq_len(3)) { n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ") - if (grepl("^[0-9]+$", n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -171,7 +171,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : " ) - if (grepl("^[0-9]+$", n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -390,7 +390,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : " ) - if (grepl("^[0-9]+$", n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } }