From 2f71232aea979bf33d505e024763b941fe2035ea Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 20 Jul 2026 19:31:07 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EA=B0=95?= =?UTF-8?q?=ED=99=94=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EC=A0=95=EC=88=98=20?= =?UTF-8?q?=EC=98=A4=EB=B2=84=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `aFIPC.R`에서 사용자의 `readline()` 입력을 검증할 때 기존의 개수 제한이 없는 숫자 형태 정규표현식(`^[0-9]+$`)을 허용된 옵션(`^[12]$`)만 정확히 일치하도록 수정. - 대규모 숫자 문자열 입력 시 `as.integer()`에서 `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 a8207a4..cdacd63 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-07-20 - Prevent Integer Overflow Coercion Vulnerability in Interactive Prompts +**Vulnerability:** Unbounded digit classes (`^[0-9]+$`) in interactive input validation allow excessively large numeric strings that evaluate to `NA` when coerced with `as.integer()`, which could lead to downstream crashes. +**Learning:** `readline()` input validation should strictly match the exact expected options (e.g., `^[12]$`) rather than generic digit patterns. +**Prevention:** Always use precise regex patterns limiting the length and allowed characters when validating inputs intended for integer conversion in R. 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)) } } From 66665fd98991228229de393c6bf3ebc74f0d3194 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 21 Jul 2026 08:39:33 +0900 Subject: [PATCH 2/4] test(security): cover bounded prompt choices --- R/aFIPC.R | 13 ++++++++++--- tests/testthat/test-prompt-validation.R | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-prompt-validation.R diff --git a/R/aFIPC.R b/R/aFIPC.R index 918e19b..c04ec0c 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -1,3 +1,10 @@ +.is_binary_prompt_choice <- function(value) { + is.character(value) && + length(value) == 1L && + !is.na(value) && + grepl("^[12]$", value) +} + #' automated fixed item parameter linking #' #' @import mirt @@ -141,7 +148,7 @@ autoFIPC <- } for (attempt in seq_len(3)) { n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ") - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } @@ -171,7 +178,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : " ) - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } @@ -390,7 +397,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : " ) - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } diff --git a/tests/testthat/test-prompt-validation.R b/tests/testthat/test-prompt-validation.R new file mode 100644 index 0000000..98b00ac --- /dev/null +++ b/tests/testthat/test-prompt-validation.R @@ -0,0 +1,22 @@ +test_that("binary prompt choices accept only the documented scalar inputs", { + expect_true(aFIPC:::.is_binary_prompt_choice("1")) + expect_true(aFIPC:::.is_binary_prompt_choice("2")) + + invalid <- list( + "0", + "3", + "01", + "1 ", + " 2", + "999999999999999999999999999999999999999999", + "not-a-number", + NA_character_, + character(), + c("1", "2"), + 1L + ) + + for (value in invalid) { + expect_false(aFIPC:::.is_binary_prompt_choice(value)) + } +}) From 15f573e5547ef87758c21ef214f6a87f4b181db1 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 20 Jul 2026 23:42:02 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EA=B0=95?= =?UTF-8?q?=ED=99=94=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EC=A0=95=EC=88=98=20?= =?UTF-8?q?=EC=98=A4=EB=B2=84=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `aFIPC.R`에서 사용자의 `readline()` 입력을 검증할 때 기존의 개수 제한이 없는 숫자 형태 정규표현식(`^[0-9]+$`)을 허용된 옵션(`^[12]$`)만 정확히 일치하도록 수정. - 대규모 숫자 문자열 입력 시 `as.integer()`에서 `NA`로 강제 변환되며 발생할 수 있는 잠재적 프로세스 충돌(정수 오버플로우로 인한 강제 변환 취약점)을 예방. - `.jules/sentinel.md` 파일에 관련 보안 학습 내용을 기록함. --- R/aFIPC.R | 13 +++---------- tests/testthat/test-prompt-validation.R | 22 ---------------------- 2 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 tests/testthat/test-prompt-validation.R diff --git a/R/aFIPC.R b/R/aFIPC.R index c04ec0c..918e19b 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -1,10 +1,3 @@ -.is_binary_prompt_choice <- function(value) { - is.character(value) && - length(value) == 1L && - !is.na(value) && - grepl("^[12]$", value) -} - #' automated fixed item parameter linking #' #' @import mirt @@ -148,7 +141,7 @@ autoFIPC <- } for (attempt in seq_len(3)) { n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ") - if (.is_binary_prompt_choice(n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -178,7 +171,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : " ) - if (.is_binary_prompt_choice(n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } } @@ -397,7 +390,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : " ) - if (.is_binary_prompt_choice(n)) { + if (grepl("^[12]$", n)) { return(as.integer(n)) } } diff --git a/tests/testthat/test-prompt-validation.R b/tests/testthat/test-prompt-validation.R deleted file mode 100644 index 98b00ac..0000000 --- a/tests/testthat/test-prompt-validation.R +++ /dev/null @@ -1,22 +0,0 @@ -test_that("binary prompt choices accept only the documented scalar inputs", { - expect_true(aFIPC:::.is_binary_prompt_choice("1")) - expect_true(aFIPC:::.is_binary_prompt_choice("2")) - - invalid <- list( - "0", - "3", - "01", - "1 ", - " 2", - "999999999999999999999999999999999999999999", - "not-a-number", - NA_character_, - character(), - c("1", "2"), - 1L - ) - - for (value in invalid) { - expect_false(aFIPC:::.is_binary_prompt_choice(value)) - } -}) From e37766c27476549e3801875c48e9db814d0c15f0 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 21 Jul 2026 08:57:42 +0900 Subject: [PATCH 4/4] test(security): restore bounded prompt coverage --- R/aFIPC.R | 13 ++++++++++--- tests/testthat/test-prompt-validation.R | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-prompt-validation.R diff --git a/R/aFIPC.R b/R/aFIPC.R index 918e19b..c04ec0c 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -1,3 +1,10 @@ +.is_binary_prompt_choice <- function(value) { + is.character(value) && + length(value) == 1L && + !is.na(value) && + grepl("^[12]$", value) +} + #' automated fixed item parameter linking #' #' @import mirt @@ -141,7 +148,7 @@ autoFIPC <- } for (attempt in seq_len(3)) { n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ") - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } @@ -171,7 +178,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : " ) - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } @@ -390,7 +397,7 @@ autoFIPC <- readline( prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : " ) - if (grepl("^[12]$", n)) { + if (.is_binary_prompt_choice(n)) { return(as.integer(n)) } } diff --git a/tests/testthat/test-prompt-validation.R b/tests/testthat/test-prompt-validation.R new file mode 100644 index 0000000..98b00ac --- /dev/null +++ b/tests/testthat/test-prompt-validation.R @@ -0,0 +1,22 @@ +test_that("binary prompt choices accept only the documented scalar inputs", { + expect_true(aFIPC:::.is_binary_prompt_choice("1")) + expect_true(aFIPC:::.is_binary_prompt_choice("2")) + + invalid <- list( + "0", + "3", + "01", + "1 ", + " 2", + "999999999999999999999999999999999999999999", + "not-a-number", + NA_character_, + character(), + c("1", "2"), + 1L + ) + + for (value in invalid) { + expect_false(aFIPC:::.is_binary_prompt_choice(value)) + } +})