From 20b210372e82e63b83e4f2961fca90c414d4160b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 29 Aug 2026 16:46:21 +0000 Subject: [PATCH 1/3] Fix integer coercion DoS vulnerability via interactive readline --- .jules/sentinel.md | 4 ++++ R/aFIPC.R | 6 +++--- tests/testthat/test-autoFIPC.R | 10 ++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..c142542a 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-07-28 - Fix integer coercion DoS vulnerability via interactive readline +**Vulnerability:** Interactive `readline()` prompts parsing integers via `as.integer()` were loosely validated with `^[0-9]+$`. Large inputs coerced to `NA`, breaking `if` conditionals and causing crashes (Denial of Service). +**Learning:** Weak regex for integers is dangerous since R's 32-bit limits can easily cause silent `NA` generation upon coercion. +**Prevention:** Strictly bound validations for menu prompts (e.g., `^[12]$` instead of `^[0-9]+$`). 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/tests/testthat/test-autoFIPC.R b/tests/testthat/test-autoFIPC.R index 13cecd92..0a99b4cd 100644 --- a/tests/testthat/test-autoFIPC.R +++ b/tests/testthat/test-autoFIPC.R @@ -89,3 +89,13 @@ test_that("autoFIPC validates input types securely", { "Security Error: tryEM must be a single non-NA logical value" ) }) + +test_that("autoFIPC securely restricts input via regex for prompts", { + expect_true(grepl("^[12]$", "1")) + expect_true(grepl("^[12]$", "2")) + expect_false(grepl("^[12]$", "3")) + expect_false(grepl("^[12]$", "12")) + expect_false(grepl("^[12]$", "0")) + expect_false(grepl("^[12]$", "abc")) + expect_false(grepl("^[12]$", "")) +}) From b8e074139e94f3ff1d7a9b8505bb9726272af9e2 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 29 Aug 2026 16:54:42 +0000 Subject: [PATCH 2/3] Fix integer coercion DoS vulnerability via interactive readline From 3c7950bd5b4159644e166775aeb0aabaeb8018eb Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 29 Aug 2026 17:00:37 +0000 Subject: [PATCH 3/3] Fix integer coercion DoS vulnerability via interactive readline