From 33048abd1fe05f2e88b947adc646c92ec5fe9004 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:25:06 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[MEDIUM]=20?= =?UTF-8?q?Fix=20integer=20coercion=20DoS=20vulnerability=20in=20readline?= =?UTF-8?q?=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .Rbuildignore | 1 + .jules/sentinel.md | 5 +++++ R/aFIPC.R | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..e23099f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,4 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^.semgrepignore$ diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a4..17a5e4c 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-20 - Integer Coercion DoS Vulnerability in `readline()` Parsing +**Vulnerability:** Weak regex `grepl("^[0-9]+$", n)` was used to validate integer inputs from interactive `readline()` prompts before passing them to `as.integer()`. +**Learning:** Large numbers provided by users can pass the `^[0-9]+$` regex but fail to coerce properly via `as.integer()`, resulting in `NA`. This causes unhandled exceptions when evaluating the `if` conditions, leading to Denial of Service (DoS) in automated or interactive contexts. +**Prevention:** Always use strictly bounded exact-match regex (e.g., `^[12]$`) for constrained numeric choices to prevent `NA` coercion crashes. diff --git a/R/aFIPC.R b/R/aFIPC.R index 6254651..918e19b 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)) } }