From 6d48de6832c20c878de3463e3992fd275c91e9d8 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 20 Sep 2026 16:05:45 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=2032=EB=B9=84=ED=8A=B8=20=EC=A0=95=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=20=EC=9A=B0=ED=9A=8C=EB=A5=BC=20=EB=B0=A9=EC=A7=80?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20readline=20=EC=A0=95?= =?UTF-8?q?=EA=B7=9C=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/sentinel.md | 4 ++++ R/aFIPC.R | 6 +++--- test_dummy.R | 2 -- tests/testthat/test-sentinel-validation.R | 7 +++++++ 4 files changed, 14 insertions(+), 5 deletions(-) delete mode 100644 test_dummy.R diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..fdfe4c40 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -2,3 +2,7 @@ **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-20 - Fix readline regex for unbounded integer limit coercion vulnerability +**Vulnerability:** Weak regex `^[0-9]+$` on interactive `readline()` user inputs allows passing strings larger than the 32-bit integer limit, causing `as.integer()` to silently coerce to `NA` breaking downstream type expectations. +**Learning:** In R, input validation for exact match choices (e.g. 1 or 2) shouldn't allow unbounded digits if it's meant to coerce to a limited integer set. +**Prevention:** Use strictly bounded exact-match regex like `^[12]$` instead of `^[0-9]+$` when validating limited choices to prevent unintended coercion errors. 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)) } } diff --git a/test_dummy.R b/test_dummy.R deleted file mode 100644 index e6f7019b..00000000 --- a/test_dummy.R +++ /dev/null @@ -1,2 +0,0 @@ -source("R/aFIPC.R") -source("R/surveyFA.R") diff --git a/tests/testthat/test-sentinel-validation.R b/tests/testthat/test-sentinel-validation.R index 900f0ee3..2e629355 100644 --- a/tests/testthat/test-sentinel-validation.R +++ b/tests/testthat/test-sentinel-validation.R @@ -35,3 +35,10 @@ test_that("autoFIPC validates boolean flags for newformBILOGprior, oldformBILOGp "Security Error: confirmCommonItems must be a single non-NA logical value or NULL" ) }) + +test_that("autoFIPC bounds check for readline input works safely", { + expect_true(grepl("^[12]$", "1")) + expect_true(grepl("^[12]$", "2")) + expect_false(grepl("^[12]$", "3")) + expect_false(grepl("^[12]$", "2147483648")) +})