From 3d09490d87906424381b401bf9f3c00383e0f491 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Wed, 26 Aug 2026 19:46:14 +0000 Subject: [PATCH] =?UTF-8?q?=EB=8C=80=ED=99=94=ED=98=95=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=A0=95=EC=88=98=20=EC=98=A4=EB=B2=84=ED=94=8C?= =?UTF-8?q?=EB=A1=9C=EC=9A=B0=20=EA=B0=95=EC=A0=9C=20=EB=B3=80=ED=99=98=20?= =?UTF-8?q?=EC=B7=A8=EC=95=BD=EC=A0=90=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `R/aFIPC.R` 내의 대화형 `readline()` 숫자 입력에서 정수 오버플로우로 인해 후속 오류가 발생할 수 있는 취약점을 해결했습니다. 기존 무제한 숫자 매칭(`^[0-9]+$`)을 특정 예상 값 매칭(`^[12]$`)으로 변경하였습니다. 수정 사항 검증을 위해 `mockery`를 사용한 테스트를 추가하고 `.jules/sentinel.md`에 내용을 기록했습니다. --- .Rbuildignore | 3 ++ .jules/sentinel.md | 5 ++ DESCRIPTION | 2 +- R/aFIPC.R | 6 +-- tests/testthat/test-sentinel-validation.R | 61 +++++++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 8989c62f..9f149758 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -24,3 +24,6 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^test_dummy\.R$ +^test_validation\.R$ +^\.semgrepignore$ diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..769fb933 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-26 - 정수 오버플로우 강제 변환 취약점 수정 +**Vulnerability:** 대화형 `readline()` 입력에서 숫자 옵션을 검증할 때 제한 없는 숫자 클래스(예: `^[0-9]+$`)를 사용하면, 너무 큰 숫자가 정규표현식 검사를 통과한 후 `as.integer()`에서 `NA`로 평가되어 후속 프로세스 충돌을 유발할 수 있습니다. +**Learning:** R 스크립트에서 대화형 `readline()` 숫자 입력을 검증할 때, 제한 없는 숫자 클래스보다 정확히 예상되는 값(예: `^[12]$`)과 엄격하게 일치시켜야 합니다. +**Prevention:** 정수 오버플로우 강제 변환 취약점을 방지하기 위해 대화형 세션에서 예상되는 숫자 입력 옵션에 대해 항상 정밀한 정규표현식 매칭을 사용해야 합니다. diff --git a/DESCRIPTION b/DESCRIPTION index f31d3e1a..c90753c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Description: Automates fixed item parameter linking for test linking under the item response theory paradigm using mirt package estimates. License: GPL-3 | file LICENSE Imports: mirt, methods -Suggests: testthat (>= 3.0.0) +Suggests: testthat (>= 3.0.0), mockery Encoding: UTF-8 Config/testthat/edition: 3 Config/roxygen2/version: 8.0.0 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-sentinel-validation.R b/tests/testthat/test-sentinel-validation.R index 900f0ee3..bb794566 100644 --- a/tests/testthat/test-sentinel-validation.R +++ b/tests/testthat/test-sentinel-validation.R @@ -35,3 +35,64 @@ test_that("autoFIPC validates boolean flags for newformBILOGprior, oldformBILOGp "Security Error: confirmCommonItems must be a single non-NA logical value or NULL" ) }) + +test_that("autoFIPC integer overflow coercion vulnerability in readline inputs is handled safely", { + # We test the interactive prompt paths by mocking readline to simulate bad inputs. + + # For confirmCommonItems prompt + mock_readline_confirm <- mockery::mock("3", "9999999999", "invalid", cycle = TRUE) + mockery::stub(aFIPC::autoFIPC, 'readline', mock_readline_confirm) + mockery::stub(aFIPC::autoFIPC, 'interactive', function() TRUE) + + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = data.frame(A=2), + newformCommonItemNames = c('A'), + oldformCommonItemNames = c('A') + ), + "Too many invalid common item confirmation attempts" + ) +}) + +test_that("autoFIPC input validation for required arguments", { + expect_error( + aFIPC::autoFIPC( + newformXData = 1, # Invalid type + oldformYData = data.frame(A=2), + newformCommonItemNames = c('A'), + oldformCommonItemNames = c('A') + ), + "Security Error: newformXData must be a data.frame, matrix, or a valid fitted mirt model" + ) + + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = 2, # Invalid type + newformCommonItemNames = c('A'), + oldformCommonItemNames = c('A') + ), + "Security Error: oldformYData must be a data.frame, matrix, or a valid fitted mirt model" + ) + + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = data.frame(A=2), + newformCommonItemNames = 1, # Invalid type + oldformCommonItemNames = c('A') + ), + "Security Error: newformCommonItemNames must be a character vector" + ) + + expect_error( + aFIPC::autoFIPC( + newformXData = data.frame(A=1), + oldformYData = data.frame(A=2), + newformCommonItemNames = c('A'), + oldformCommonItemNames = 2 # Invalid type + ), + "Security Error: oldformCommonItemNames must be a character vector" + ) +})