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" + ) +})