From 55f9934cdeab7f42a2e6d7e08ada62699324df27 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 20 Aug 2026 19:11:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20readline=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EB=B3=B4?= =?UTF-8?q?=EC=95=88=20=ED=8C=A8=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `readline()` 대화형 프롬프트의 숫자 입력값 검증 시 예상되는 정확한 값(`^[12]$`)만 허용하도록 변경 - 기존 `^[0-9]+$` 사용 시 매우 큰 숫자 입력 시 발생하는 integer overflow(coercion to NA)로 인한 취약점 방지 - .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..a93c9259 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-20 - readline 입력값 검증 강화 +**Vulnerability:** `readline()`으로 사용자 입력을 받을 때 정규식 `^[0-9]+$`를 사용하면 매우 큰 숫자가 입력될 경우 `as.integer()`에서 `NA`로 변환되어 후속 로직에서 예외가 발생할 수 있습니다. +**Learning:** 대화형 프롬프트의 숫자 입력값 검증 시에는 예상되는 정확한 값(예: `^[12]$`)만 허용해야 합니다. +**Prevention:** `readline()` 반환값을 검증할 때 허용 가능한 값만 정확히 일치하도록 제한된 정규식을 사용하십시오. 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)) } }