From 2052d54d38c71ff43f426215355b1994baacfe3b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 29 Sep 2026 20:23:01 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20Fix=20Integ?= =?UTF-8?q?er=20Overflow=20DoS=20in=20`readline()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `R/aFIPC.R` 내 3곳의 `readline()` 입력 검증 코드를 `grepl`에서 엄격한 `%in%` 문자열 매칭으로 변경하여 Integer Overflow DoS 취약점을 방지했습니다. 이와 관련된 보안 학습 내용을 `.jules/sentinel.md`에 기록했습니다. --- .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..1915b087 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-05-18 - [Integer Overflow DoS in `readline()` Input Validation] +**Vulnerability:** Broad numeric regex validation (`grepl("^[0-9]+$", n)`) allowed arbitrary length numerical strings from user input to be parsed. When coerced via `as.integer(n)`, integer overflows resulted in `NA` values and warning messages, which could crash logic checks (DoS). +**Learning:** `readline()` input representing predefined options should be strictly checked against the expected literal string options (e.g., `n %in% c("1", "2")`) rather than allowing open-ended regex number matching prior to coercion. +**Prevention:** Always validate categorical or strict-menu interactive inputs using exact string matching (`%in%`) before type coercion. 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)) } }