From 74038d3baefa3d7ba442ca599697526445f7a69b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 3 Sep 2026 16:11:35 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=20=EC=A0=95=EC=88=98=20=EA=B0=95=EC=A0=9C=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=20=EC=B7=A8=EC=95=BD=EC=A0=90=20=EC=88=98=EC=A0=95=20(?= =?UTF-8?q?=EB=B3=B4=EC=95=88=20=ED=8C=A8=EC=B9=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Weak regex validation in `readline()` inputs allowed arbitrary large numbers to be entered, which would coerce to `NA` via `as.integer()`. This can lead to unexpected conditions and DoS via unhandled exceptions. This commit patches the vulnerable prompts by strictly binding the regex validation to exactly `1` or `2`. --- .jules/sentinel.md | 5 +++++ R/aFIPC.R | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..229ded36 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-12 - Fix weak regex validation for integer coercion +**Vulnerability:** Weak regex validation (`^[0-9]+$`) for `readline()` inputs allows extremely large numbers (e.g. `9999999999999999999999`) to be parsed. When coerced via `as.integer()`, these large strings turn into `NA` rather than numbers, breaking downstream `if` conditions and causing unhandled exceptions/DoS vulnerabilities. +**Learning:** R's `as.integer()` fails silently with `NA` (along with a warning) when it encounters numbers larger than a 32-bit integer limits, making broad regex digit validation insufficient for inputs meant to be coerced to integers. +**Prevention:** Use strictly bounded exact-match regex (e.g., `^[12]$`) to validate inputs intended for discrete integer coercion prior to calling `as.integer()`. 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)) } }