From 99a5c274b4ac1ac842a6194b6747048f87da05b0 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:26:15 +0000 Subject: [PATCH 1/4] Fix integer coercion vulnerability in readline input validation --- .jules/sentinel.md | 5 +++++ R/aFIPC.R | 6 +++--- tests/testthat/test-sentinel-validation.R | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a4..d1753bf 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-08-08 - Fix missing input validation leading to NAs +**Vulnerability:** Weak regex `grepl("^[0-9]+$", n)` allows large numbers that coerce to `NA` via `as.integer()`, potentially causing unhandled exceptions in conditionals. +**Learning:** Always use tightly bounded exact-match regex like `grepl("^[12]$", n)` when validating user inputs for integer choices to avoid coercion crashes and DoS vulnerabilities. +**Prevention:** Strictly bound input validation regexes for choices. 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)) } } diff --git a/tests/testthat/test-sentinel-validation.R b/tests/testthat/test-sentinel-validation.R index 900f0ee..7e5d163 100644 --- a/tests/testthat/test-sentinel-validation.R +++ b/tests/testthat/test-sentinel-validation.R @@ -35,3 +35,24 @@ 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 validates invalid readline inputs safely", { + # We test the confirmCommonItems prompt + # If we feed "9999999999" 3 times, it should throw "Too many invalid common item confirmation attempts" + my_readline <- function(prompt) { + "9999999999" + } + + mockery::stub(aFIPC::autoFIPC, 'interactive', TRUE) + mockery::stub(aFIPC::autoFIPC, 'readline', my_readline) + + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = data.frame(A=2), + newformCommonItemNames = c('A'), + oldformCommonItemNames = c('A') + ), + "Too many invalid common item confirmation attempts" + ) +}) From 456770032c4011fd49d806750d2aab0a3b913ff1 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:40:16 +0000 Subject: [PATCH 2/4] Fix integer coercion vulnerability in readline input validation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f31d3e1..c90753c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Description: Automates fixed item parameter linking for test linking under the item response theory paradigm using mirt package estimates. License: GPL-3 | file LICENSE Imports: mirt, methods -Suggests: testthat (>= 3.0.0) +Suggests: testthat (>= 3.0.0), mockery Encoding: UTF-8 Config/testthat/edition: 3 Config/roxygen2/version: 8.0.0 From df97902f365349845c76a6e5a36978aabf554129 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:52:04 +0000 Subject: [PATCH 3/4] Fix integer coercion vulnerability in readline input validation --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..0821274 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +.semgrepignore +test_dummy.R +test_validation.R From 3a1c657eb49c8932b9be85cc512e4a2d34612ff2 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 17:02:17 +0000 Subject: [PATCH 4/4] Fix integer coercion vulnerability in readline input validation