diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..28b2d85 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^\.semgrepignore$ +^test_dummy\.R$ +^test_validation\.R$ diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a4..6b60ea2 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-07-30 - Fix weak regex validation in readline prompts +**Vulnerability:** Interactive `readline` prompts in `R/aFIPC.R` previously validated integer inputs using the weak regex `^[0-9]+$`. This allows arbitrarily large numbers which, when cast via `as.integer()`, cause integer overflow and coerce to `NA`, leading to unhandled condition lengths and process crashes. +**Learning:** Broad regex limits in interactive R prompts are insecure and can easily cause DoS via unexpected data coercion. +**Prevention:** Always use strictly bounded exact-match regex like `^[12]$` when validating integer inputs expected to match small, specific sets of choices. diff --git a/R/aFIPC.R b/R/aFIPC.R index 6254651..e8abf3c 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -141,7 +141,10 @@ autoFIPC <- } for (attempt in seq_len(3)) { n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ") - if (grepl("^[0-9]+$", n)) { + # 🛡️ Sentinel Security Context: + # Strictly bound input to exactly '1' or '2' to prevent integer overflow + # where large numbers coerce to NA and cause unhandled condition crashes. + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -171,7 +174,10 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : " ) - if (grepl("^[0-9]+$", n)) { + # 🛡️ Sentinel Security Context: + # Strictly bound input to exactly '1' or '2' to prevent integer overflow + # where large numbers coerce to NA and cause unhandled condition crashes. + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -390,7 +396,10 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : " ) - if (grepl("^[0-9]+$", n)) { + # 🛡️ Sentinel Security Context: + # Strictly bound input to exactly '1' or '2' to prevent integer overflow + # where large numbers coerce to NA and cause unhandled condition crashes. + if (grepl("^[12]$", n)) { return(as.integer(n)) } }