diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..06638172 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. +## 2026-09-14 - readline() 입력값의 Integer Overflow 취약점 수정 +**Vulnerability:** `readline()`에서 숫자 입력 여부를 `grepl("^[0-9]+$", n)`로만 검증할 경우, 매우 큰 숫자를 입력했을 때 `as.integer()`에서 integer overflow coercion이 발생하여 `NA`를 반환하며 어플리케이션 크래시를 유발할 수 있습니다. +**Learning:** R에서 정규식을 이용해 숫자를 검증하고 바로 변환하는 것은 오버플로우나 타입 에러에 취약합니다. 제한된 옵션을 입력받을 경우 엄격한 값 매칭을 사용해야 합니다. +**Prevention:** `n %in% c("1", "2")`와 같이 사전에 정의된 안전한 옵션 값과 직접 매칭하는 방식을 사용하여 입력값을 검증해야 합니다. diff --git a/R/aFIPC.R b/R/aFIPC.R index 62546519..118aca09 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 (n %in% c("1", "2")) { 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 (n %in% c("1", "2")) { 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 (n %in% c("1", "2")) { return(as.integer(n)) } } diff --git a/tests/testthat/test-sentinel-validation.R b/tests/testthat/test-sentinel-validation.R index 900f0ee3..25a7a226 100644 --- a/tests/testthat/test-sentinel-validation.R +++ b/tests/testthat/test-sentinel-validation.R @@ -35,3 +35,16 @@ test_that("autoFIPC validates boolean flags for newformBILOGprior, oldformBILOGp "Security Error: confirmCommonItems must be a single non-NA logical value or NULL" ) }) + +test_that("aFIPC handles non-interactive prompt fallbacks and validates input safely to avoid integer overflow", { + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = data.frame(A=2), + newformCommonItemNames = c('A'), + oldformCommonItemNames = c('A'), + confirmCommonItems = FALSE + ), + "Please write down pairs correctly" + ) +})